Documentation Index Fetch the complete documentation index at: https://mintlify.com/Vanilagy/mediabunny/llms.txt
Use this file to discover all available pages before exploring further.
The Input class represents an input media file and provides methods for reading tracks, metadata, and computing file properties.
Constructor
new Input ( options : InputOptions )
Creates a new input file from the specified options. No reading operations will be performed until methods are called on this instance.
Configuration for the input file Show InputOptions properties
A list of supported formats. If the source file is not of one of these formats, then it cannot be read.
The source from which data will be read.
Properties
Returns the source from which this input file reads its data. This is the same source that was passed to the constructor.
True if the input has been disposed.
Methods
async getFormat (): Promise < InputFormat >
Returns the format of the input file. You can compare this result directly to the InputFormat singletons or use instanceof checks for subset-aware logic (for example, format instanceof MatroskaInputFormat is true for both MKV and WebM).
computeDuration()
async computeDuration (): Promise < number >
Computes the duration of the input file, in seconds. More precisely, returns the largest end timestamp among all tracks.
getFirstTimestamp()
async getFirstTimestamp (): Promise < number >
Returns the timestamp at which the input file starts. More precisely, returns the smallest starting timestamp among all tracks.
getTracks()
async getTracks (): Promise < InputTrack [] >
Returns the list of all tracks of this input file.
getVideoTracks()
async getVideoTracks (): Promise < InputVideoTrack [] >
Returns the list of all video tracks of this input file.
getAudioTracks()
async getAudioTracks (): Promise < InputAudioTrack [] >
Returns the list of all audio tracks of this input file.
getPrimaryVideoTrack()
async getPrimaryVideoTrack (): Promise < InputVideoTrack | null >
Returns the primary video track of this input file, or null if there are no video tracks.
getPrimaryAudioTrack()
async getPrimaryAudioTrack (): Promise < InputAudioTrack | null >
Returns the primary audio track of this input file, or null if there are no audio tracks.
getMimeType()
async getMimeType (): Promise < string >
Returns the full MIME type of this input file, including track codecs.
async getMetadataTags (): Promise < MetadataTags >
Returns descriptive metadata tags about the media file, such as title, author, date, cover art, or other attached files.
dispose()
Disposes this input and frees connected resources. When an input is disposed, ongoing read operations will be canceled, all future read operations will fail, any open decoders will be closed, and all ongoing media sink operations will be canceled. Disallowed and canceled operations will throw an InputDisposedError.
You are expected not to use an input after disposing it. While some operations may still work, it is not specified and may change in any future update.
Errors
Thrown when an operation was prevented because the corresponding Input has been disposed.
class InputDisposedError extends Error
Example
import { Input , FileSource , Mp4InputFormat , WebMInputFormat } from '@mediabunny/browser' ;
const file = await fileInput . files [ 0 ];
const source = new FileSource ( file );
const input = new Input ({
formats: [ Mp4InputFormat , WebMInputFormat ],
source
});
const duration = await input . computeDuration ();
console . log ( `Duration: ${ duration } seconds` );
const videoTrack = await input . getPrimaryVideoTrack ();
if ( videoTrack ) {
console . log ( `Video: ${ videoTrack . codedWidth } x ${ videoTrack . codedHeight } ` );
}
const metadata = await input . getMetadataTags ();
console . log ( 'Title:' , metadata . title );
input . dispose ();