### Start Output Creation - TypeScript Source: https://mediabunny.dev/api/Output Initiates the media file creation process. This method should be called after all tracks and metadata have been configured. Once started, media samples can be added to the tracks. Returns a Promise that resolves when the output is ready. ```typescript start(): Promise; ``` -------------------------------- ### Constructor for VideoSampleSink (TypeScript) Source: https://mediabunny.dev/api/VideoSampleSink Initializes a new VideoSampleSink instance for a given InputVideoTrack. This is the starting point for accessing video frames. ```typescript constructor( videoTrack: InputVideoTrack ): VideoSampleSink; ``` -------------------------------- ### Configure Fast Start Metadata Placement (TypeScript) Source: https://mediabunny.dev/api/IsobmffOutputFormatOptions Explains the 'fastStart' option for IsobmffOutputFormatOptions, controlling metadata placement for improved playback. Options include disabling it, using memory, reserving space, or creating fragmented files. ```typescript fastStart?: false | 'in-memory' | 'reserve' | 'fragmented'; ``` -------------------------------- ### Create AudioSamples from AudioBuffer Source: https://mediabunny.dev/api/AudioSample This static method allows the creation of AudioSample instances from an existing AudioBuffer. It takes the AudioBuffer and a starting timestamp in seconds as input. It typically generates one sample but may produce more for very large buffers. ```typescript static fromAudioBuffer( audioBuffer: AudioBuffer, timestamp: number ): AudioSample[]; ``` -------------------------------- ### Input Class Source: https://mediabunny.dev/api/Input Represents an input media file. This is the root object from which all media read operations start. It implements the `Disposable` interface. ```APIDOC ## Class: Input Represents an input media file. This is the root object from which all media read operations start. **Implements:** `Disposable` ### Type parameters ```ts Input ``` See `Source`. ### Constructor ```ts constructor(options: InputOptions): Input; ``` Creates a new input file from the specified options. No reading operations will be performed until methods are called on this instance. See `InputOptions`. ### Properties #### `disposed` ```ts get disposed(): boolean; ``` True if the input has been disposed. #### `source` ```ts get source(): S; ``` Returns the source from which this input file reads its data. This is the same source that was passed to the constructor. ### Methods #### `getFormat()` ```ts getFormat(): Promise; ``` 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()` ```ts computeDuration(): Promise; ``` Computes the duration of the input file, in seconds. More precisely, returns the largest end timestamp among all tracks. #### `getTracks()` ```ts getTracks(): Promise; ``` Returns the list of all tracks of this input file. See `InputTrack`. #### `getVideoTracks()` ```ts getVideoTracks(): Promise; ``` Returns the list of all video tracks of this input file. See `InputVideoTrack`. #### `getAudioTracks()` ```ts getAudioTracks(): Promise; ``` Returns the list of all audio tracks of this input file. See `InputAudioTrack`. #### `getPrimaryVideoTrack()` ```ts getPrimaryVideoTrack(): Promise; ``` Returns the primary video track of this input file, or null if there are no video tracks. See `InputVideoTrack`. #### `getPrimaryAudioTrack()` ```ts getPrimaryAudioTrack(): Promise; ``` Returns the primary audio track of this input file, or null if there are no audio tracks. See `InputAudioTrack`. #### `getMimeType()` ```ts getMimeType(): Promise; ``` Returns the full MIME type of this input file, including track codecs. #### `getMetadataTags()` ```ts getMetadataTags(): Promise; ``` Returns descriptive metadata tags about the media file, such as title, author, date, cover art, or other attached files. See `MetadataTags`. #### `dispose()` ```ts dispose(): void; ``` 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. #### `[Symbol.dispose]()` ```ts [Symbol.dispose](): void; ``` Calls `.dispose()` on the input, implementing the `Disposable` interface for use with JavaScript Explicit Resource Management features. ``` -------------------------------- ### Initialize Conversion Process (TypeScript) Source: https://mediabunny.dev/api/Conversion Initializes a new media conversion process using provided options. This method sets up the conversion but does not start it. The `ConversionOptions` parameter dictates the conversion parameters. It returns a `Promise` that resolves with a `Conversion` object. ```TypeScript static init( opions: ConversionOptions, ): Promise; ``` -------------------------------- ### Trim Options for ConversionOptions Source: https://mediabunny.dev/api/ConversionOptions The `trim` property enables trimming of the input media file. It accepts an object with optional `start` and `end` properties to define the desired segment. ```typescript trim?: { start?: number; end?: number; }; ``` -------------------------------- ### Get Codec Parameter String for Audio Track Source: https://mediabunny.dev/api/InputAudioTrack Asynchronously returns the full codec parameter string for this audio track. Returns null if the codec is unknown. ```typescript getCodecParameterString(): Promise; ``` -------------------------------- ### Get AudioSample Format Source: https://mediabunny.dev/api/AudioSample Returns the format of the audio sample. This property indicates the encoding or format of the audio data, such as PCM, AAC, etc. Refer to the sample formats documentation for details. ```typescript readonly format: AudioSampleFormat; ``` -------------------------------- ### Retrieve Audio Sample by Timestamp (TypeScript) Source: https://mediabunny.dev/api/AudioSampleSink Fetches a specific audio sample based on its presentation timestamp. It returns the last sample whose start time is less than or equal to the provided timestamp, or null if the timestamp is before the track's beginning. ```typescript getSample( timestamp: number ): Promise; ``` -------------------------------- ### Set Metadata Tags - TypeScript Source: https://mediabunny.dev/api/Output Assigns descriptive metadata tags (e.g., title, author, date, cover art) to the media file. If called multiple times, only the last set of tags will be applied. This method must be called before the output is started. ```typescript setMetadataTags( tags: MetadataTags, ): void; ``` -------------------------------- ### Get Encoded Packet by Timestamp - TypeScript Source: https://mediabunny.dev/api/EncodedPacketSink Retrieves an encoded packet based on a given timestamp in seconds. It returns the last packet whose start timestamp is less than or equal to the provided timestamp. Use `Infinity` to get the last packet. Returns null if the timestamp is before the first packet. Supports optional retrieval options. ```typescript getPacket( timestamp: number, options: PacketRetrievalOptions = {}, ): Promise; ``` -------------------------------- ### Get Key Encoded Packet by Timestamp - TypeScript Source: https://mediabunny.dev/api/EncodedPacketSink Retrieves the key packet corresponding to a given timestamp in seconds. It returns the last key packet whose start timestamp is less than or equal to the provided timestamp. Use `Infinity` to get the last key packet. Returns null if the timestamp is before the first key packet. Supports optional retrieval options and verification. ```typescript getKeyPacket( timestamp: number, options: PacketRetrievalOptions = {}, ): Promise; ``` -------------------------------- ### TypeScript: Input Class Definition and Methods Source: https://mediabunny.dev/api/Input Defines the Input class in TypeScript, used as the root object for reading media files. It includes methods for getting format, duration, tracks (audio, video, primary), MIME type, metadata, and managing disposal. ```typescript class Input implements Disposable { constructor(options: InputOptions); get disposed(): boolean; get source(): S; getFormat(): Promise; computeDuration(): Promise; getTracks(): Promise; getVideoTracks(): Promise; getAudioTracks(): Promise; getPrimaryVideoTrack(): Promise; getPrimaryAudioTrack(): Promise; getMimeType(): Promise; getMetadataTags(): Promise; dispose(): void; [Symbol.dispose](): void; } ``` -------------------------------- ### Get AudioBuffer by Timestamp Source: https://mediabunny.dev/api/AudioBufferSink Retrieves the AudioBuffer corresponding to a specific timestamp. It returns the last buffer whose start timestamp is less than or equal to the provided timestamp. Returns null if the timestamp is before the track's earliest timestamp. ```typescript getBuffer( timestamp: number ): Promise; ``` -------------------------------- ### BufferSource Constructor Source: https://mediabunny.dev/api/BufferSource Initializes a new BufferSource instance with a buffer containing the entire file in memory. ```APIDOC ## BufferSource Constructor ### Description Creates a new `BufferSource` backed by the specified `ArrayBuffer`, `SharedArrayBuffer`, or `ArrayBufferView`. ### Method `constructor` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **buffer** (AllowSharedBufferSource) - Required - The buffer containing the data. ### Request Example ```typescript const buffer = new Uint8Array([1, 2, 3, 4, 5]); const source = new BufferSource(buffer); ``` ### Response #### Success Response (200) N/A (Constructor does not return a value) #### Response Example N/A ``` -------------------------------- ### Get Specific Video Sample by Timestamp (TypeScript) Source: https://mediabunny.dev/api/VideoSampleSink Retrieves a single video sample (frame) based on a specific timestamp. It returns the last sample whose start timestamp is less than or equal to the provided timestamp. Returns null if the timestamp is before the track's first frame. ```typescript getSample( timestamp: number ): Promise; ``` -------------------------------- ### Instantiate MovOutputFormat in TypeScript Source: https://mediabunny.dev/api/MovOutputFormat Creates a new MovOutputFormat instance. This class extends IsobmffOutputFormat and is configured with IsobmffOutputFormatOptions. It represents the QuickTime File Format (MOV). ```typescript import { MovOutputFormat, IsobmffOutputFormatOptions } from "mediabunny-api"; const options: IsobmffOutputFormatOptions = {}; // Configure with appropriate options const movFormat = new MovOutputFormat(options); ``` -------------------------------- ### BlobSource Methods Source: https://mediabunny.dev/api/BlobSource Documentation for methods available on the BlobSource class to get file sizes. ```APIDOC ## BlobSource Methods ### `getSizeOrNull()` #### Description Resolves with the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size. Returns null if the source is unsized. #### Method `getSizeOrNull` #### Return Type `Promise` ### `getSize()` #### Description Resolves with the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size. Throws an error if the source is unsized. #### Method `getSize` #### Return Type `Promise` #### Throws An error if the source is unsized. ``` -------------------------------- ### VideoSampleSink.samples() Source: https://mediabunny.dev/api/VideoSampleSink Creates an async iterator that yields the video samples (frames) of this track in presentation order. ```APIDOC ## VideoSampleSink.samples() ### Description Creates an async iterator that yields the video samples (frames) of this track in presentation order. This method intelligently pre-decodes frames ahead for fast iteration. ### Method GET ### Endpoint `/websites/mediabunny_dev_api/VideoSampleSink/samples` (Conceptual endpoint for documentation purposes) ### Parameters #### Path Parameters None #### Query Parameters * **startTimestamp** (number) - Optional - The timestamp in seconds at which to start yielding samples (inclusive). Defaults to 0. * **endTimestamp** (number) - Optional - The timestamp in seconds at which to stop yielding samples (exclusive). Defaults to Infinity. #### Request Body None ### Request Example ```bash GET /websites/mediabunny_dev_api/VideoSampleSink/samples?startTimestamp=1.0&endTimestamp=5.0 ``` ### Response #### Success Response (200) * **AsyncGenerator<VideoSample, void, unknown>** - An async generator yielding VideoSample objects. #### Response Example ```json // Example of yielded data: { "data": "...video frame data...", "timestamp": 1.033, "duration": 0.033 } ``` ``` -------------------------------- ### Get Track Type Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the type of this track (e.g., audio, video). This property is part of the InputAudioTrack class. ```typescript get type(): TrackType; ``` -------------------------------- ### BlobSource Constructor Source: https://mediabunny.dev/api/BlobSource Initializes a new BlobSource instance with a provided Blob and optional configuration. ```APIDOC ## BlobSource Constructor ### Description Creates a new `BlobSource` backed by the specified `Blob`. See `BlobSourceOptions`. ### Method `constructor` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **blob** (Blob) - Required - The Blob to back the source. - **options** (BlobSourceOptions) - Optional - Configuration options for the BlobSource. ``` -------------------------------- ### Get Video Samples at Specific Timestamps (TypeScript) Source: https://mediabunny.dev/api/VideoSampleSink Provides an asynchronous iterator to retrieve video samples for an iterable of timestamps. This method is optimized for monotonically sorted timestamps, decoding each packet at most once. It may return null if no sample is found for a given timestamp. ```typescript samplesAtTimestamps( timestamps: AnyIterable ): AsyncGenerator; ``` -------------------------------- ### Create AudioSampleSink Instance (TypeScript) Source: https://mediabunny.dev/api/AudioSampleSink Initializes a new AudioSampleSink for a given InputAudioTrack. This is the primary way to begin retrieving audio data. ```typescript constructor( audioTrack: InputAudioTrack ): AudioSampleSink; ``` -------------------------------- ### Get Encodable Subtitle Codecs Source: https://mediabunny.dev/api/getEncodableSubtitleCodecs Retrieves a list of all subtitle codecs that can be encoded by the browser. This is useful for determining client-side subtitle compatibility. ```APIDOC ## GET /websites/mediabunny_dev_api/getEncodableSubtitleCodecs ### Description Returns the list of all subtitle codecs that can be encoded by the browser. ### Method GET ### Endpoint /websites/mediabunny_dev_api/getEncodableSubtitleCodecs ### Parameters #### Query Parameters - **checkedCodecs** (SubtitleCodec[]) - Optional - An array of subtitle codecs to check. Defaults to all available SUBTITLE_CODECS. ### Response #### Success Response (200) - **webvtt** (string[]) - A list of subtitle codec identifiers that are encodable. #### Response Example { "webvtt": ["vtt"] } ``` -------------------------------- ### Get Sample Rate for Audio Track Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the audio sample rate of this track in Hertz. This property is part of the InputAudioTrack class. ```typescript get sampleRate(): number; ``` -------------------------------- ### TypeScript: Hardware Acceleration Hint Source: https://mediabunny.dev/api/VideoEncodingAdditionalOptions Provides a hint for the hardware acceleration method used by the codec. It's recommended to use the default 'no-preference' for optimal compatibility. ```typescript hardwareAcceleration?: 'no-preference' | 'prefer-hardware' | 'prefer-software'; ``` -------------------------------- ### Get Number of Channels for Audio Track Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the number of audio channels present in this track. This property is part of the InputAudioTrack class. ```typescript get numberOfChannels(): number; ``` -------------------------------- ### Constructor: MediaStreamAudioTrackSource Source: https://mediabunny.dev/api/MediaStreamAudioTrackSource Initializes a MediaStreamAudioTrackSource by taking a MediaStreamAudioTrack and an AudioEncodingConfig. This allows real-time audio capture and encoding from the provided track. ```typescript constructor( track: MediaStreamAudioTrack, encodingConfig: AudioEncodingConfig, ): MediaStreamAudioTrackSource; ``` -------------------------------- ### Mp3OutputFormat Constructor Source: https://mediabunny.dev/api/Mp3OutputFormat Initializes a new Mp3OutputFormat object. It can be configured with optional Mp3OutputFormatOptions. Refer to Mp3OutputFormatOptions for more details on configuration. ```typescript constructor( opions: Mp3OutputFormatOptions = {}, ): Mp3OutputFormat; ``` -------------------------------- ### Get User-Defined Name for Audio Track Source: https://mediabunny.dev/api/InputAudioTrack Retrieves a user-defined name for this audio track, if one exists. This property is part of the InputAudioTrack class. ```typescript get name(): string | null; ``` -------------------------------- ### Output Constructor - TypeScript Source: https://mediabunny.dev/api/Output Initializes a new instance of the Output class. The constructor takes an OutputOptions object, which specifies the format and target for the media file, and prepares the Output instance for subsequent operations. ```typescript constructor( options: OutputOptions, ): Output; ``` -------------------------------- ### AdtsOutputFormat Constructor Source: https://mediabunny.dev/api/AdtsOutputFormat Creates a new AdtsOutputFormat instance with optional configuration options. ```APIDOC ## AdtsOutputFormat Constructor ### Description Creates a new `AdtsOutputFormat` configured with the specified `options`. See `AdtsOutputFormatOptions`. ### Method `constructor` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (AdtsOutputFormatOptions) - Optional - Configuration options for the AdtsOutputFormat. ### Request Example ```json { "options": {} } ``` ### Response #### Success Response (200) - **AdtsOutputFormat** - An instance of the AdtsOutputFormat class. #### Response Example ```json { "instance": "AdtsOutputFormat" } ``` ``` -------------------------------- ### Get Audio Track ID Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the unique identifier for this audio track within the input file. This property is part of the InputAudioTrack class. ```typescript get id(): number; ``` -------------------------------- ### WebMOutputFormat Constructor Source: https://mediabunny.dev/api/WebMOutputFormat Initializes a new WebMOutputFormat instance. It accepts optional MkvOutputFormatOptions for configuration. This class is designed for writing WebM files, a format based on Matroska, with specific support for transparent video. ```typescript constructor( op ions?: MkvOutputFormatOptions, ): WebMOutputFormat; ``` -------------------------------- ### Get Audio Track Disposition Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the disposition of the audio track, providing information about its intended usage. This property is part of the InputAudioTrack class. ```typescript get disposition(): TrackDisposition; ``` -------------------------------- ### Get Audio Track Codec Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the audio codec of the track. Returns null if the codec is unknown. This property is part of the InputAudioTrack class. ```typescript get codec(): AudioCodec | null; ``` -------------------------------- ### Create FilePathTarget Instance Source: https://mediabunny.dev/api/FilePathTarget Initializes a new FilePathTarget to write data to a specified file. This is intended for server-side environments like Node.js, Bun, or Deno. The constructor takes the file path and optional configuration options. ```typescript constructor( filePath: string, options: FilePathTargetOptions = {}, ): FilePathTarget; ``` -------------------------------- ### Get AudioSample Duration in Microseconds Source: https://mediabunny.dev/api/AudioSample Provides the duration of the audio sample in microseconds. This getter is useful for high-precision timing and calculations involving microseconds. ```typescript get microsecondDuration(): number; ``` -------------------------------- ### TypeScript Type Definition for Hardware Acceleration Hint Source: https://mediabunny.dev/api/ConversionVideoOptions Provides a hint for configuring the hardware acceleration method used during video transcoding. Options range from no preference to preferring hardware or software acceleration. It is generally recommended to leave this setting on 'no-preference'. ```typescript hardwareAcceleration?: 'no-preference' | 'prefer-hardware' | 'prefer-software'; ``` -------------------------------- ### Create AudioSample from AudioData or Raw Bytes Source: https://mediabunny.dev/api/AudioSample Initializes a new AudioSample. It can be created either from an existing AudioData object or from raw byte data specified in AudioSampleInit. This constructor is essential for creating audio samples programmatically. ```typescript constructor( init: AudioData | AudioSampleInit ): AudioSample; ``` -------------------------------- ### AudioSampleCopyToOptions.frameOffset Property Source: https://mediabunny.dev/api/AudioSampleCopyToOptions Sets an offset within the source plane data to specify the starting frame for the copy operation. The default value is 0. ```typescript frameOffset?: number; ``` -------------------------------- ### Get AudioSample Duration Source: https://mediabunny.dev/api/AudioSample Retrieves the duration of the audio sample in seconds. This read-only property is crucial for understanding the length of the audio data represented by the sample. ```typescript readonly duration: number; ``` -------------------------------- ### VideoSampleSource Constructor Source: https://mediabunny.dev/api/VideoSampleSource Creates a new VideoSampleSource that encodes raw video samples according to the provided encoding configuration. ```APIDOC ## VideoSampleSource Constructor ### Description Creates a new `VideoSampleSource` whose samples are encoded according to the specified `VideoEncodingConfig`. ### Method `constructor` ### Endpoint N/A (Class Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **encodingConfig** (`VideoEncodingConfig`) - Required - Configuration object for video encoding. ### Request Example ```json { "encodingConfig": { "codec": "vp9", "width": 1280, "height": 720, "frameRate": 30 } } ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### AudioSampleCopyToOptions.frameCount Property Source: https://mediabunny.dev/api/AudioSampleCopyToOptions Defines the total number of frames to copy. If this property is omitted, the copy operation will include all frames in the specified plane starting from the frameOffset. ```typescript frameCount?: number; ``` -------------------------------- ### Source Class API Source: https://mediabunny.dev/api/Source Documentation for the abstract Source class, its subclasses, events, and methods. ```APIDOC ## Abstract Class Source ### Description The source base class, representing a resource from which bytes can be read. ### Subclasses - `BlobSource` - `BufferSource` - `FilePathSource` - `StreamSource` - `ReadableStreamSource` - `UrlSource` ### Used by - `Input` - `InputOptions` ## Events ### `onread` #### Description Called each time data is retrieved from the source. Will be called with the retrieved range (end exclusive). #### Type `(start: number, end: number) => unknown) | null` ## Methods ### `getSizeOrNull()` #### Description Resolves with the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size. Returns null if the source is unsized. #### Returns `Promise` ### `getSize()` #### Description Resolves with the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size. Throws an error if the source is unsized. #### Returns `Promise` ``` -------------------------------- ### Get MovOutputFormat MIME Type in TypeScript Source: https://mediabunny.dev/api/MovOutputFormat Retrieves the base MIME type for the MovOutputFormat. This property returns a string representing the MIME type. ```typescript import { MovOutputFormat } from "mediabunny-api"; const movFormat = new MovOutputFormat(); // Assuming a default instance or initialized elsewhere const mimeType = movFormat.mimeType; console.log(mimeType); // Expected output: "video/quicktime" ``` -------------------------------- ### Initialize AudioBufferSource with Encoding Configuration Source: https://mediabunny.dev/api/AudioBufferSource Constructs a new AudioBufferSource. The AudioBuffer instances added to this source will be encoded according to the provided AudioEncodingConfig. This is essential for ensuring compatibility with the audio output system. ```typescript constructor( encodingConfig: AudioEncodingConfig ): AudioBufferSource; ``` -------------------------------- ### Get Number of Audio Channels Source: https://mediabunny.dev/api/AudioSample Returns the number of audio channels present in the sample. This property is essential for understanding the stereo or multi-channel nature of the audio data. ```typescript readonly numberOfChannels: number; ``` -------------------------------- ### Initialize QuickTimeInputFormat Singleton (JavaScript) Source: https://mediabunny.dev/api/QTFF This snippet initializes the QTFF constant as a new instance of QuickTimeInputFormat. It is used to represent the QuickTime File Format input format. No specific dependencies are mentioned other than the QuickTimeInputFormat class itself. ```javascript const QTFF = new QuickTimeInputFormat(); ``` -------------------------------- ### Get AudioSample Timestamp in Microseconds Source: https://mediabunny.dev/api/AudioSample Returns the presentation timestamp of the audio sample in microseconds. This getter is valuable for accurate synchronization and playback control at microsecond resolution. ```typescript get microsecondTimestamp(): number; ``` -------------------------------- ### VideoSampleColorSpace Constructor Source: https://mediabunny.dev/api/VideoSampleColorSpace Initializes a new VideoSampleColorSpace object. It optionally accepts a VideoColorSpaceInit object to configure the color space properties. ```typescript constructor( init?: VideoColorSpaceInit, ): VideoSampleColorSpace; ``` -------------------------------- ### VideoSample Class Documentation Source: https://mediabunny.dev/api/VideoSample Documentation for the VideoSample class, including its constructors, properties, and methods. ```APIDOC ## VideoSample Class Represents a raw, unencoded video sample (frame). It acts as a wrapper around WebCodecs API's `VideoFrame` and can also be used standalone. **Implements:** `Disposable` ### Constructors 1. **`constructor(data: VideoFrame, init?: VideoSampleInit): VideoSample`** Creates a new `VideoSample` from a `VideoFrame`. This is a near zero-cost wrapper. Metadata can be refined using `init`. 2. **`constructor(data: CanvasImageSource, init: SetRequired): VideoSample`** Creates a new `VideoSample` from a `CanvasImageSource`. Wraps the `VideoFrame` constructor if available, otherwise copies image data to an internal canvas. 3. **`constructor(data: AllowSharedBufferSource, init: SetRequired): VideoSample`** Creates a new `VideoSample` from raw pixel data. Requires additional metadata in `init`. ### Properties * **`codedHeight`** (readonly number): The height of the frame in pixels. * **`codedWidth`** (readonly number): The width of the frame in pixels. * **`colorSpace`** (readonly VideoSampleColorSpace): The color space of the frame. * **`displayHeight`** (get number): The height of the frame in pixels after rotation. * **`displayWidth`** (get number): The width of the frame in pixels after rotation. * **`duration`** (readonly number): The duration of the frame in seconds. * **`format`** (readonly VideoSamplePixelFormat | null): The internal pixel format. `null` if using an arbitrary format. * **`hasAlpha`** (get boolean | null): Indicates if the pixel format supports transparency. * **`microsecondDuration`** (get number): The duration of the frame in microseconds. * **`microsecondTimestamp`** (get number): The presentation timestamp of the frame in microseconds. * **`rotation`** (readonly Rotation): The rotation of the frame in degrees, clockwise. * **`timestamp`** (readonly number): The presentation timestamp of the frame in seconds. Can be negative. ### Methods * **`clone(): VideoSample`** Clones this video sample. * **`close(): void`** Closes this video sample, releasing held resources. Should be called when the sample is no longer needed. * **`allocationSize(options: VideoFrameCopyToOptions = {}): number`** Returns the number of bytes required for the pixel data. Throws if `format` is `null` without explicit format in options. * **`copyTo(destination: AllowSharedBufferSource, options: VideoFrameCopyToOptions = {}): Promise`** Copies the pixel data to an ArrayBuffer or ArrayBufferView. Throws if `format` is `null` without explicit format in options. Returns the byte layout of the copied data planes. * **`toVideoFrame(): VideoFrame`** Converts this video sample to a `VideoFrame` for use with the WebCodecs API. The returned `VideoFrame` must be closed separately. ``` -------------------------------- ### Initialize Custom Audio Decoder (TypeScript) Source: https://mediabunny.dev/api/CustomAudioDecoder This method is called after the decoder is created and is intended for any custom initialization logic. It returns a `MaybePromise` which can be used for asynchronous setup. ```typescript init(): MaybePromise; ``` -------------------------------- ### AttachedImage MimeType Property (TypeScript) Source: https://mediabunny.dev/api/AttachedImage Specifies the MIME type of the attached image according to RFC 6838 standards. Examples include 'image/jpeg' and 'image/png'. ```typescript mimeType: string; ``` -------------------------------- ### add() Method Source: https://mediabunny.dev/api/CanvasSource Captures the current canvas state as a video sample (frame), encodes it and adds it to the output. ```APIDOC ## add() Method ### Description Captures the current canvas state as a video sample (frame), encodes it and adds it to the output. ### Method ```typescript add( timestamp: number, duration: number = 0, encodeOptions?: VideoEncoderEncodeOptions ): Promise; ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **timestamp** (number) - Required - The timestamp of the sample, in seconds. - **duration** (number) - Optional - The duration of the sample, in seconds. - **encodeOptions** (VideoEncoderEncodeOptions) - Optional - Options for encoding the video frame. ### Request Example ```json { "timestamp": 1.23, "duration": 0.1, "encodeOptions": { "keyFrame": false } } ``` ### Response #### Success Response (200) A Promise that resolves once the output is ready to receive more samples. You should await this Promise to respect writer and encoder backpressure. #### Response Example ```json {} ``` ### Error Handling None ``` -------------------------------- ### InputVideoTrack Methods - Mediabunny API Source: https://mediabunny.dev/api/InputVideoTrack Offers methods to interact with and retrieve detailed information about a video track. This includes asynchronously fetching color space, checking for high dynamic range, determining transparency, getting decoder configurations, obtaining the codec parameter string, verifying decode capabilities, determining packet types, and checking if the track is specifically a video track. It also includes methods to check if it's an audio track, get the first timestamp, and compute the duration of the track. ```typescript getColorSpace(): Promise; hasHighDynamicRange(): Promise; canBeTransparent(): Promise; getDecoderConfig(): Promise; getCodecParameterString(): Promise; canDecode(): Promise; determinePacketType( packet: EncodedPacket, ): Promise; isVideoTrack(): boolean; isAudioTrack(): boolean; getFirstTimestamp(): Promise; computeDuration(): Promise; ``` -------------------------------- ### VideoSampleSink.samplesAtTimestamps() Source: https://mediabunny.dev/api/VideoSampleSink Creates an async iterator that yields a video sample (frame) for each timestamp in the argument. ```APIDOC ## VideoSampleSink.samplesAtTimestamps() ### Description Creates an async iterator that yields a video sample (frame) for each timestamp in the argument. This method uses an optimized decoding pipeline for monotonically sorted timestamps, decoding each packet at most once. The iterator may yield null if no frame is available for a given timestamp. ### Method POST ### Endpoint `/websites/mediabunny_dev_api/VideoSampleSink/samplesAtTimestamps` (Conceptual endpoint for documentation purposes) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **timestamps** (AnyIterable<number>) - Required - An iterable or async iterable of timestamps in seconds. ### Request Example ```json { "timestamps": [1.0, 1.5, 2.0, 2.5] } ``` ### Response #### Success Response (200) * **AsyncGenerator<VideoSample | null, void, unknown>** - An async generator yielding VideoSample objects or null. #### Response Example ```json // Example of yielded data for each timestamp: { "data": "...video frame data...", "timestamp": 1.5, "duration": 0.033 } // or null if no sample found for a timestamp null ``` ``` -------------------------------- ### Add Video Track - TypeScript Source: https://mediabunny.dev/api/Output Adds a video track to the output. This method requires a VideoSource and optional VideoTrackMetadata. It can only be invoked before the output process has started. ```typescript addVideoTrack( source: VideoSource, metadata: VideoTrackMetadata = {}, ): void; ``` -------------------------------- ### VideoSampleSink Constructor Source: https://mediabunny.dev/api/VideoSampleSink Creates a new VideoSampleSink for the given InputVideoTrack. ```APIDOC ## VideoSampleSink Constructor ### Description Creates a new `VideoSampleSink` for the given `InputVideoTrack`. ### Method CONSTRUCTOR ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **videoTrack** (InputVideoTrack) - Required - The input video track to create the sink for. ### Request Example ```typescript // No direct request body for constructor ``` ### Response #### Success Response (200) * **VideoSampleSink** - An instance of the VideoSampleSink. #### Response Example ```typescript // No direct response body for constructor ``` ``` -------------------------------- ### Instantiate FlacOutputFormat Source: https://mediabunny.dev/api/FlacOutputFormat Creates a new FlacOutputFormat instance configured with optional settings. This is the primary way to begin working with the FLAC output format. ```typescript constructor( options: FlacOutputFormatOptions = {}, ): FlacOutputFormat; ``` -------------------------------- ### AdtsOutputFormat Constructor Source: https://mediabunny.dev/api/AdtsOutputFormat Initializes a new AdtsOutputFormat instance with optional configuration. It extends the base OutputFormat class and can be customized using AdtsOutputFormatOptions. ```typescript constructor( options: AdtsOutputFormatOptions = {}, ): AdtsOutputFormat; ``` -------------------------------- ### Get Supported Subtitle Codecs for FlacOutputFormat Source: https://mediabunny.dev/api/FlacOutputFormat Returns a list of subtitle codecs that can be included with the FLAC output format. This indicates potential for embedding subtitle tracks. ```typescript getSupportedSubtitleCodecs(): "webvtt"[]; ``` -------------------------------- ### Add Subtitle Track - TypeScript Source: https://mediabunny.dev/api/Output Enables the addition of subtitle tracks to the output, requiring a SubtitleSource and optional SubtitleTrackMetadata. This operation is restricted to the period before the output is started. ```typescript addSubtitleTrack( source: SubtitleSource, metadata: SubtitleTrackMetadata = {}, ): void; ``` -------------------------------- ### OggOutputFormat Constructor Source: https://mediabunny.dev/api/OggOutputFormat Initializes a new OggOutputFormat instance with optional configurations. The constructor takes an OggOutputFormatOptions object to customize its behavior. Refer to the OggOutputFormatOptions documentation for available settings. ```typescript constructor( opions: OggOutputFormatOptions = {}, ): OggOutputFormat; ``` -------------------------------- ### Get Encodable Codecs Source: https://mediabunny.dev/api/getEncodableCodecs Retrieves a list of all media codecs that the browser is capable of encoding. This is useful for dynamically configuring media playback or recording based on browser capabilities. ```APIDOC ## GET /websites/mediabunny_dev_api/getEncodableCodecs ### Description Returns the list of all media codecs that can be encoded by the browser. Refer to the `MediaCodec` documentation for details on individual codec properties. ### Method GET ### Endpoint /websites/mediabunny_dev_api/getEncodableCodecs ### Parameters None ### Request Example ```json { "example": "" } ``` ### Response #### Success Response (200) - **MediaCodec[]** (array) - An array of objects, where each object represents an encodable media codec. #### Response Example ```json { "example": [ { "codec": "vp9", "mimeType": "video/webm", "codecs": [ "vp9" ] }, { "codec": "avc", "mimeType": "video/mp4", "codecs": [ "avc1.42E01E", "avc1.4D401E", "avc1.64001E" ] } ] } ``` ``` -------------------------------- ### Initialize OGG Input Format Singleton (JavaScript) Source: https://mediabunny.dev/api/OGG This snippet initializes the OGG input format singleton using the OggInputFormat class. It's a constant, meaning it's assigned once and cannot be reassigned. No specific dependencies are mentioned, but it likely relies on the OggInputFormat class being defined elsewhere. ```javascript const OGG = new OggInputFormat(); ``` -------------------------------- ### Get MovOutputFormat File Extension in TypeScript Source: https://mediabunny.dev/api/MovOutputFormat Retrieves the file extension for the MovOutputFormat. This property returns a string representing the file extension, including the leading dot. ```typescript import { MovOutputFormat } from "mediabunny-api"; const movFormat = new MovOutputFormat(); // Assuming a default instance or initialized elsewhere const extension = movFormat.fileExtension; console.log(extension); // Expected output: ".mov" ``` -------------------------------- ### InputAudioTrack Methods Source: https://mediabunny.dev/api/InputAudioTrack This section details the methods available for an InputAudioTrack object. ```APIDOC ## InputAudioTrack Methods ### `getDecoderConfig()` - **Returns**: `Promise` - **Description**: Returns the decoder configuration for decoding the track's packets using an `AudioDecoder`. Returns null if the track's codec is unknown. ### `getCodecParameterString()` - **Returns**: `Promise` - **Description**: Returns the full codec parameter string for this track. ### `canDecode()` - **Returns**: `Promise` - **Description**: Checks if this track's packets can be decoded by the browser. ### `determinePacketType(packet: EncodedPacket)` - **Parameters**: - `packet` (EncodedPacket) - The encoded packet to determine the type of. - **Returns**: `Promise` - **Description**: For a given packet of this track, this method determines the actual type of this packet (key/delta) by looking into its bitstream. Returns null if the type couldn't be determined. See `EncodedPacket` and `PacketType`. ### `isVideoTrack()` - **Returns**: `boolean` - **Description**: Returns true if and only if this track is a video track. ### `isAudioTrack()` - **Returns**: `boolean` - **Description**: Returns true if and only if this track is an audio track. ### `getFirstTimestamp()` - **Returns**: `Promise` - **Description**: Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples with a negative timestamp should not be presented. ### `computeDuration()` - **Returns**: `Promise` - **Description**: Returns the end timestamp of the last packet of this track, in seconds. ### `computePacketStats(targetPacketCount: number = Infinity)` - **Parameters**: - `targetPacketCount` (number, Optional) - This optional parameter sets a target for how many packets this method must have looked at before it can return early; this means, you can use it to aggregate only a subset (prefix) of all packets. This is very useful for getting a great estimate of video frame rate without having to scan through the entire file. - **Returns**: `Promise` - **Description**: Computes aggregate packet statistics for this track, such as average packet rate or bitrate. See `PacketStats`. ``` -------------------------------- ### Initialize MP3 Input Format Singleton (TypeScript) Source: https://mediabunny.dev/api/MP3 This snippet initializes a singleton instance for the MP3 input format. It assumes the existence of an Mp3InputFormat class, which is used to create the singleton object. ```typescript const MP3 = new Mp3InputFormat(); ``` -------------------------------- ### Get Language Code for Audio Track Source: https://mediabunny.dev/api/InputAudioTrack Retrieves the ISO 639-2/T language code for this audio track. If the language is unknown, it returns 'und'. This property is part of the InputAudioTrack class. ```typescript get languageCode(): string; ``` -------------------------------- ### Get Audio Sample Rate Source: https://mediabunny.dev/api/AudioSample Returns the sample rate of the audio in Hertz. This property defines how many samples are taken per second and is fundamental for audio playback and processing. ```typescript readonly sampleRate: number; ``` -------------------------------- ### Iterate Through Video Samples with Time Range (TypeScript) Source: https://mediabunny.dev/api/VideoSampleSink Creates an asynchronous generator to yield video samples within a specified time range (startTimestamp to endTimestamp). It pre-decodes frames ahead to ensure fast iteration. ```typescript samples( startTimestamp: number = 0, endTimestamp: number = Infinity ): AsyncGenerator; ``` -------------------------------- ### Mp3OutputFormat Methods for Supported Formats Source: https://mediabunny.dev/api/Mp3OutputFormat These methods return lists of supported track counts, media codecs, video codecs, audio codecs, and subtitle codecs for the MP3 output format. They help in understanding the compatibility of different media streams. ```typescript getSupportedTrackCounts(): TrackCountLimits; getSupportedCodecs(): MediaCodec[]; getSupportedVideoCodecs(): "avc" | "hevc" | "vp9" | "av1" | "vp8"[]; getSupportedAudioCodecs(): "aac" | "opus" | "mp3" | "vorbis" | "flac" | "pcm-s16" | "pcm-s16be" | "pcm-s24" | "pcm-s24be" | "pcm-s32" | "pcm-s32be" | "pcm-f32" | "pcm-f32be" | "pcm-f64" | "pcm-f64be" | "pcm-u8" | "pcm-s8" | "ulaw" | "alaw"[]; getSupportedSubtitleCodecs(): "webvtt"[]; ``` -------------------------------- ### AdtsOutputFormat Supported Video Codecs Source: https://mediabunny.dev/api/AdtsOutputFormat Gets a list of supported video codecs for the ADTS output format. This includes codecs like 'avc', 'hevc', 'vp9', 'av1', and 'vp8'. ```typescript getSupportedVideoCodecs(): "avc" | "hevc" | "vp9" | "av1" | "vp8"[]; ``` -------------------------------- ### NullTarget Class Documentation Source: https://mediabunny.dev/api/NullTarget Details the NullTarget class, its purpose, inheritance, and events, particularly the 'onwrite' event. ```APIDOC ## NullTarget ### Description This target just discards all incoming data. It is useful for when you need an `Output` but extract data from it differently, for example through format-specific callbacks (`onMoof`, `onMdat`, ...) or encoder events. **Extends:** `Target` ### Events #### onwrite ##### Description Called each time data is written to the target. Will be called with the byte range into which data was written. Use this callback to track the size of the output file as it grows. But be warned, this function is chatty and gets called _extremely_ often. ##### Signature ```typescript onwrite: ((start: number, end: number) => unknown) | null; ``` ``` -------------------------------- ### BlobSource onread Event in TypeScript Source: https://mediabunny.dev/api/BlobSource Defines the 'onread' event handler for BlobSource. This event is triggered whenever data is read from the source, providing the start and end indices of the retrieved data. ```TypeScript onread: ((start: number, end: number) => unknown) | null; ``` -------------------------------- ### AttachedFile Constructor (TypeScript) Source: https://mediabunny.dev/api/AttachedFile Creates a new AttachedFile instance. It takes the raw file data as a Uint8Array, and optionally accepts MIME type, name, and description. ```typescript constructor( data: Uint8Array, mimeType?: string, name?: string, description?: string, ): AttachedFile; ``` -------------------------------- ### Get Supported Subtitle Codecs for Ogg Source: https://mediabunny.dev/api/OggOutputFormat Returns an array containing the supported subtitle codecs for the Ogg output format. Currently, only 'webvtt' is listed as a supported subtitle codec. ```typescript getSupportedSubtitleCodecs(): "webvtt באי"; ``` -------------------------------- ### Get AudioSample Timestamp Source: https://mediabunny.dev/api/AudioSample Retrieves the presentation timestamp of the audio sample in seconds. This read-only property may be negative and is used for timing playback; samples with negative end timestamps should not be presented. ```typescript readonly timestamp: number; ``` -------------------------------- ### VideoSampleSource.add() Source: https://mediabunny.dev/api/VideoSampleSource Encodes a video sample and adds it to the output, respecting backpressure. ```APIDOC ## VideoSampleSource.add() ### Description Encodes a video sample (frame) and then adds it to the output. This method returns a Promise that resolves when the output is ready for more samples, ensuring proper backpressure handling. ### Method `add` ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **videoSample** (`VideoSample`) - Required - The video sample (frame) to add. - **encodeOptions** (`VideoEncoderEncodeOptions`) - Optional - Options for encoding the video sample. ### Request Example ```json { "videoSample": { "timestamp": 1678886400000, "data": "base64EncodedFrameData" }, "encodeOptions": { "keyFrame": true } } ``` ### Response #### Success Response (200) - **Promise** - Resolves when the output is ready to receive more samples. #### Response Example (This is a Promise-based operation, no direct JSON response) ``` ``` -------------------------------- ### AudioSampleInit Interface Definition (TypeScript) Source: https://mediabunny.dev/api/AudioSampleInit Defines the structure for initializing an AudioSample. It requires audio data, format, number of channels, sample rate, and a timestamp. The `data` property accepts any `AllowSharedBufferSource`. ```typescript type AudioSampleInit = { data: AllowSharedBufferSource; format: AudioSampleFormat; numberOfChannels: number; sampleRate: number; timestamp: number; }; ``` -------------------------------- ### Get Number of Frames per Channel Source: https://mediabunny.dev/api/AudioSample Returns the number of audio frames per channel in the sample. This indicates the total length of the audio data in frames, which is critical for sample processing. ```typescript readonly numberOfFrames: number; ``` -------------------------------- ### MkvOutputFormat Constructor Source: https://mediabunny.dev/api/MkvOutputFormat Initializes a new MkvOutputFormat instance with optional configuration. The constructor takes an MkvOutputFormatOptions object to specify settings for the Matroska output. See MkvOutputFormatOptions for available configuration parameters. ```typescript constructor( opions: MkvOutputFormatOptions = {}, ): MkvOutputFormat; ``` -------------------------------- ### CanvasSink Constructor Source: https://mediabunny.dev/api/CanvasSink Creates a new CanvasSink for a given InputVideoTrack. Options can be provided to customize its behavior. ```APIDOC ## CanvasSink Constructor ### Description Creates a new `CanvasSink` for the given `InputVideoTrack`. See `CanvasSinkOptions`. ### Method constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **videoTrack** (InputVideoTrack) - Required - The input video track to render. - **options** (CanvasSinkOptions) - Optional - Configuration options for the CanvasSink. ### Request Example ```typescript const canvasSink = new CanvasSink(videoTrack, { /* options */ }); ``` ### Response #### Success Response (200) - **CanvasSink** (object) - A new instance of CanvasSink. #### Response Example ```json { "message": "CanvasSink created successfully" } ``` ``` -------------------------------- ### Get Decoder Configuration for Audio Track Source: https://mediabunny.dev/api/InputAudioTrack Asynchronously retrieves the decoder configuration required for decoding the track's packets using an AudioDecoder. Returns null if the track's codec is unknown. ```typescript getDecoderConfig(): Promise; ```