> ## 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.

# Output formats

> Classes and configuration for writing media files in various formats

## OutputFormat

Base class representing an output media file format.

```typescript theme={null}
abstract class OutputFormat
```

### Properties

<ResponseField name="fileExtension" type="string">
  The file extension used by this output format, beginning with a dot.
</ResponseField>

<ResponseField name="mimeType" type="string">
  The base MIME type of the output format.
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Whether this output format supports video rotation metadata.
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Whether this output format's tracks store timestamped media data. When `true`, the timestamps of added packets will be respected, allowing things like gaps in media data or non-zero start times. When `false`, the format's media data implicitly starts at zero and follows an implicit sequential timing from there, using the intrinsic durations of the media data.
</ResponseField>

### Methods

<ResponseField name="getSupportedCodecs" type="() => MediaCodec[]">
  Returns a list of media codecs that this output format can contain.
</ResponseField>

<ResponseField name="getSupportedTrackCounts" type="() => TrackCountLimits">
  Returns the number of tracks that this output format supports.
</ResponseField>

<ResponseField name="getSupportedVideoCodecs" type="() => VideoCodec[]">
  Returns a list of video codecs that this output format can contain.
</ResponseField>

<ResponseField name="getSupportedAudioCodecs" type="() => AudioCodec[]">
  Returns a list of audio codecs that this output format can contain.
</ResponseField>

<ResponseField name="getSupportedSubtitleCodecs" type="() => SubtitleCodec[]">
  Returns a list of subtitle codecs that this output format can contain.
</ResponseField>

***

## Types

### InclusiveIntegerRange

Specifies an inclusive range of integers.

```typescript theme={null}
type InclusiveIntegerRange = {
  min: number;
  max: number;
}
```

<ParamField name="min" type="number">
  The integer cannot be less than this.
</ParamField>

<ParamField name="max" type="number">
  The integer cannot be greater than this.
</ParamField>

***

### TrackCountLimits

Specifies the number of tracks (for each track type and in total) that an output format supports.

```typescript theme={null}
type TrackCountLimits = {
  video: InclusiveIntegerRange;
  audio: InclusiveIntegerRange;
  subtitle: InclusiveIntegerRange;
  total: InclusiveIntegerRange;
}
```

<ParamField name="video" type="InclusiveIntegerRange">
  The allowed range of video tracks.
</ParamField>

<ParamField name="audio" type="InclusiveIntegerRange">
  The allowed range of audio tracks.
</ParamField>

<ParamField name="subtitle" type="InclusiveIntegerRange">
  The allowed range of subtitle tracks.
</ParamField>

<ParamField name="total" type="InclusiveIntegerRange">
  Specifies the overall allowed range of track counts for the output format.
</ParamField>

***

## MP4 and MOV formats

### Mp4OutputFormat

MPEG-4 Part 14 (MP4) file format. Supports most codecs.

```typescript theme={null}
class Mp4OutputFormat extends IsobmffOutputFormat
```

#### Constructor

```typescript theme={null}
new Mp4OutputFormat(options?: IsobmffOutputFormatOptions)
```

<ParamField name="options" type="IsobmffOutputFormatOptions">
  Configuration options for the MP4 output format.
</ParamField>

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.mp4'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'video/mp4'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `true`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `true`
</ResponseField>

***

### MovOutputFormat

QuickTime File Format (QTFF), often called MOV. Supports all video and audio codecs, but not subtitle codecs.

```typescript theme={null}
class MovOutputFormat extends IsobmffOutputFormat
```

#### Constructor

```typescript theme={null}
new MovOutputFormat(options?: IsobmffOutputFormatOptions)
```

<ParamField name="options" type="IsobmffOutputFormatOptions">
  Configuration options for the MOV output format.
</ParamField>

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.mov'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'video/quicktime'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `true`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `true`
</ResponseField>

***

### IsobmffOutputFormatOptions

ISOBMFF-specific output options.

```typescript theme={null}
type IsobmffOutputFormatOptions = {
  fastStart?: false | 'in-memory' | 'reserve' | 'fragmented';
  minimumFragmentDuration?: number;
  metadataFormat?: 'auto' | 'mdir' | 'mdta' | 'udta';
  onFtyp?: (data: Uint8Array, position: number) => unknown;
  onMoov?: (data: Uint8Array, position: number) => unknown;
  onMdat?: (data: Uint8Array, position: number) => unknown;
  onMoof?: (data: Uint8Array, position: number, timestamp: number) => unknown;
}
```

<ParamField name="fastStart" type="false | 'in-memory' | 'reserve' | 'fragmented'">
  Controls the placement of metadata in the file. Placing metadata at the start of the file is known as "Fast Start", which results in better playback at the cost of more required processing or memory.

  * `false`: Disable Fast Start, placing the metadata at the end of the file. Fastest and uses the least memory.
  * `'in-memory'`: Produce a file with Fast Start by keeping all media chunks in memory until the file is finalized. This produces a high-quality and compact output at the cost of a more expensive finalization step and higher memory requirements. Data will be written monotonically (in order) when this option is set.
  * `'reserve'`: Reserve space at the start of the file into which the metadata will be written later. This produces a file with Fast Start but requires knowledge about the expected length of the file beforehand. When using this option, you must set the `maximumPacketCount` field in the track metadata for all tracks.
  * `'fragmented'`: Place metadata at the start of the file by creating a fragmented file (fMP4). In a fragmented file, chunks of media and their metadata are written to the file in "fragments", eliminating the need to put all metadata in one place. Data will be written monotonically (in order) when this option is set.

  When this field is not defined, either `false` or `'in-memory'` will be used, automatically determined based on the type of output target used.
</ParamField>

<ParamField name="minimumFragmentDuration" type="number">
  When using `fastStart: 'fragmented'`, this field controls the minimum duration of each fragment, in seconds. New fragments will only be created when the current fragment is longer than this value. Defaults to 1 second.
</ParamField>

<ParamField name="metadataFormat" type="'auto' | 'mdir' | 'mdta' | 'udta'">
  The metadata format to use for writing metadata tags.

  * `'auto'` (default): Behaves like `'mdir'` for MP4 and like `'udta'` for QuickTime, matching FFmpeg's default behavior.
  * `'mdir'`: Write tags into `moov/udta/meta` using the 'mdir' handler format.
  * `'mdta'`: Write tags into `moov/udta/meta` using the 'mdta' handler format, equivalent to FFmpeg's `use_metadata_tags` flag. This allows for custom keys of arbitrary length.
  * `'udta'`: Write tags directly into `moov/udta`.
</ParamField>

<ParamField name="onFtyp" type="(data: Uint8Array, position: number) => unknown">
  Will be called once the ftyp (File Type) box of the output file has been written.
</ParamField>

<ParamField name="onMoov" type="(data: Uint8Array, position: number) => unknown">
  Will be called once the moov (Movie) box of the output file has been written.
</ParamField>

<ParamField name="onMdat" type="(data: Uint8Array, position: number) => unknown">
  Will be called for each finalized mdat (Media Data) box of the output file. Usage of this callback is not recommended when not using `fastStart: 'fragmented'`, as there will be one monolithic mdat box which might require large amounts of memory.
</ParamField>

<ParamField name="onMoof" type="(data: Uint8Array, position: number, timestamp: number) => unknown">
  Will be called for each finalized moof (Movie Fragment) box of the output file.
</ParamField>

***

## Matroska and WebM formats

### MkvOutputFormat

Matroska file format.

Supports writing transparent video. For a video track to be marked as transparent, the first packet added must contain alpha side data.

```typescript theme={null}
class MkvOutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new MkvOutputFormat(options?: MkvOutputFormatOptions)
```

<ParamField name="options" type="MkvOutputFormatOptions">
  Configuration options for the MKV output format.
</ParamField>

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.mkv'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'video/x-matroska'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false` (while it technically supports it with ProjectionPoseRoll, many players appear to ignore this value)
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `true`
</ResponseField>

***

### WebMOutputFormat

WebM file format, based on Matroska.

Supports writing transparent video. For a video track to be marked as transparent, the first packet added must contain alpha side data.

```typescript theme={null}
class WebMOutputFormat extends MkvOutputFormat
```

#### Constructor

```typescript theme={null}
new WebMOutputFormat(options?: WebMOutputFormatOptions)
```

<ParamField name="options" type="WebMOutputFormatOptions">
  Configuration options for the WebM output format.
</ParamField>

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.webm'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'video/webm'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `true`
</ResponseField>

***

### MkvOutputFormatOptions

Matroska-specific output options.

```typescript theme={null}
type MkvOutputFormatOptions = {
  appendOnly?: boolean;
  minimumClusterDuration?: number;
  onEbmlHeader?: (data: Uint8Array, position: number) => void;
  onSegmentHeader?: (data: Uint8Array, position: number) => unknown;
  onCluster?: (data: Uint8Array, position: number, timestamp: number) => unknown;
}
```

<ParamField name="appendOnly" type="boolean">
  Configures the output to only append new data at the end, useful for live-streaming the file as it's being created. When enabled, some features such as storing duration and seeking will be disabled or impacted, so don't use this option when you want to write out a clean file for later use.
</ParamField>

<ParamField name="minimumClusterDuration" type="number">
  This field controls the minimum duration of each Matroska cluster, in seconds. New clusters will only be created when the current cluster is longer than this value. Defaults to 1 second.
</ParamField>

<ParamField name="onEbmlHeader" type="(data: Uint8Array, position: number) => void">
  Will be called once the EBML header of the output file has been written.
</ParamField>

<ParamField name="onSegmentHeader" type="(data: Uint8Array, position: number) => unknown">
  Will be called once the header part of the Matroska Segment element has been written. The header data includes the Segment element and everything inside it, up to (but excluding) the first Matroska Cluster.
</ParamField>

<ParamField name="onCluster" type="(data: Uint8Array, position: number, timestamp: number) => unknown">
  Will be called for each finalized Matroska Cluster of the output file.
</ParamField>

***

### WebMOutputFormatOptions

WebM-specific output options.

```typescript theme={null}
type WebMOutputFormatOptions = MkvOutputFormatOptions
```

***

## Audio formats

### Mp3OutputFormat

MP3 file format.

```typescript theme={null}
class Mp3OutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new Mp3OutputFormat(options?: Mp3OutputFormatOptions)
```

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.mp3'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'audio/mpeg'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `false`
</ResponseField>

***

### Mp3OutputFormatOptions

MP3-specific output options.

```typescript theme={null}
type Mp3OutputFormatOptions = {
  xingHeader?: boolean;
  onXingFrame?: (data: Uint8Array, position: number) => unknown;
}
```

<ParamField name="xingHeader" type="boolean">
  Controls whether the Xing header, which contains additional metadata as well as an index, is written to the start of the MP3 file. When disabled, the writing process becomes append-only. Defaults to `true`.
</ParamField>

<ParamField name="onXingFrame" type="(data: Uint8Array, position: number) => unknown">
  Will be called once the Xing metadata frame is finalized.
</ParamField>

***

### WavOutputFormat

WAVE file format, based on RIFF.

```typescript theme={null}
class WavOutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new WavOutputFormat(options?: WavOutputFormatOptions)
```

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.wav'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'audio/wav'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `false`
</ResponseField>

***

### WavOutputFormatOptions

WAVE-specific output options.

```typescript theme={null}
type WavOutputFormatOptions = {
  large?: boolean;
  metadataFormat?: 'info' | 'id3';
  onHeader?: (data: Uint8Array, position: number) => unknown;
}
```

<ParamField name="large" type="boolean">
  When enabled, an RF64 file will be written, allowing for file sizes to exceed 4 GiB, which is otherwise not possible for regular WAVE files.
</ParamField>

<ParamField name="metadataFormat" type="'info' | 'id3'">
  The metadata format to use for writing metadata tags.

  * `'info'` (default): Writes metadata into a RIFF INFO LIST chunk, the default way to contain metadata tags within WAVE. Only allows for a limited subset of tags to be written.
  * `'id3'`: Writes metadata into an ID3 chunk. Non-default, but used by many taggers in practice. Allows for a much larger and richer set of tags to be written.
</ParamField>

<ParamField name="onHeader" type="(data: Uint8Array, position: number) => unknown">
  Will be called once the file header is written. The header consists of the RIFF header, the format chunk, metadata chunks, and the start of the data chunk (with a placeholder size of 0).
</ParamField>

***

### OggOutputFormat

Ogg file format.

```typescript theme={null}
class OggOutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new OggOutputFormat(options?: OggOutputFormatOptions)
```

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.ogg'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'application/ogg'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `false`
</ResponseField>

***

### OggOutputFormatOptions

Ogg-specific output options.

```typescript theme={null}
type OggOutputFormatOptions = {
  maximumPageDuration?: number;
  onPage?: (data: Uint8Array, position: number, source: MediaSource) => unknown;
}
```

<ParamField name="maximumPageDuration" type="number">
  The maximum duration of each Ogg page, in seconds. This is useful for streaming contexts where more frequent page output is desired. By default, pages are only flushed when they exceed a certain size.
</ParamField>

<ParamField name="onPage" type="(data: Uint8Array, position: number, source: MediaSource) => unknown">
  Will be called for each Ogg page that is written.
</ParamField>

***

### AdtsOutputFormat

ADTS file format.

```typescript theme={null}
class AdtsOutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new AdtsOutputFormat(options?: AdtsOutputFormatOptions)
```

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.aac'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'audio/aac'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `false`
</ResponseField>

***

### AdtsOutputFormatOptions

ADTS-specific output options.

```typescript theme={null}
type AdtsOutputFormatOptions = {
  onFrame?: (data: Uint8Array, position: number) => unknown;
}
```

<ParamField name="onFrame" type="(data: Uint8Array, position: number) => unknown">
  Will be called for each ADTS frame that is written.
</ParamField>

***

### FlacOutputFormat

FLAC file format.

```typescript theme={null}
class FlacOutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new FlacOutputFormat(options?: FlacOutputFormatOptions)
```

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.flac'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'audio/flac'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `false`
</ResponseField>

***

### FlacOutputFormatOptions

FLAC-specific output options.

```typescript theme={null}
type FlacOutputFormatOptions = {
  onFrame?: (data: Uint8Array, position: number) => unknown;
}
```

<ParamField name="onFrame" type="(data: Uint8Array, position: number) => unknown">
  Will be called for each FLAC frame that is written.
</ParamField>

***

## Transport Stream formats

### MpegTsOutputFormat

MPEG Transport Stream file format.

```typescript theme={null}
class MpegTsOutputFormat extends OutputFormat
```

#### Constructor

```typescript theme={null}
new MpegTsOutputFormat(options?: MpegTsOutputFormatOptions)
```

#### Properties

<ResponseField name="fileExtension" type="string">
  Returns `'.ts'`
</ResponseField>

<ResponseField name="mimeType" type="string">
  Returns `'video/MP2T'`
</ResponseField>

<ResponseField name="supportsVideoRotationMetadata" type="boolean">
  Returns `false`
</ResponseField>

<ResponseField name="supportsTimestampedMediaData" type="boolean">
  Returns `true`
</ResponseField>

***

### MpegTsOutputFormatOptions

MPEG-TS-specific output options.

```typescript theme={null}
type MpegTsOutputFormatOptions = {
  onPacket?: (data: Uint8Array, position: number) => unknown;
}
```

<ParamField name="onPacket" type="(data: Uint8Array, position: number) => unknown">
  Will be called for each 188-byte Transport Stream packet that is written.
</ParamField>
