Skip to main content

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 Output class orchestrates the creation of a new media file, allowing you to add tracks and configure output settings.

Constructor

new Output(options: OutputOptions)
Creates a new instance of Output which can then be used to create a new media file according to the specified OutputOptions.
options
OutputOptions
required
Configuration for the output file

Properties

format
OutputFormat
The format of the output file.
target
Target
The target to which the file will be written.
state
'pending' | 'started' | 'canceled' | 'finalizing' | 'finalized'
The current state of the output.

Methods

addVideoTrack()

addVideoTrack(source: VideoSource, metadata?: VideoTrackMetadata): void
Adds a video track to the output with the given source. Can only be called before the output is started.
source
VideoSource
required
The video source for this track.
metadata
VideoTrackMetadata
Track metadata including language, name, rotation, and frame rate

addAudioTrack()

addAudioTrack(source: AudioSource, metadata?: AudioTrackMetadata): void
Adds an audio track to the output with the given source. Can only be called before the output is started.
source
AudioSource
required
The audio source for this track.
metadata
AudioTrackMetadata
Track metadata including language, name, and disposition

addSubtitleTrack()

addSubtitleTrack(source: SubtitleSource, metadata?: SubtitleTrackMetadata): void
Adds a subtitle track to the output with the given source. Can only be called before the output is started.
source
SubtitleSource
required
The subtitle source for this track.
metadata
SubtitleTrackMetadata
Track metadata including language, name, and disposition.

setMetadataTags()

setMetadataTags(tags: MetadataTags): void
Sets descriptive metadata tags about the media file, such as title, author, date, or cover art. When called multiple times, only the metadata from the last call will be used. Can only be called before the output is started.
tags
MetadataTags
required
Metadata tags to write to the output file.

start()

async start(): Promise<void>
Starts the creation of the output file. This method should be called after all tracks have been added. Only after the output has started can media samples be added to the tracks. Returns a promise that resolves when the output has successfully started and is ready to receive media samples.

getMimeType()

async getMimeType(): Promise<string>
Resolves with the full MIME type of the output file, including track codecs. The returned promise will resolve only once the precise codec strings of all tracks are known.

finalize()

async finalize(): Promise<void>
Finalizes the output file. This method must be called after all media samples across all tracks have been added. Once the Promise returned by this method completes, the output file is ready.

cancel()

async cancel(): Promise<void>
Cancels the creation of the output file, releasing internal resources like encoders and preventing further samples from being added. Returns a promise that resolves once all internal resources have been released.

Example

import { Output, StreamTarget, Mp4OutputFormat } from '@mediabunny/browser';

const target = new StreamTarget();
const output = new Output({
  format: Mp4OutputFormat,
  target
});

// Add tracks
output.addVideoTrack(videoSource, {
  languageCode: 'eng',
  name: 'Main Video',
  frameRate: 30
});

output.addAudioTrack(audioSource, {
  languageCode: 'eng',
  name: 'Stereo Audio'
});

// Set metadata
output.setMetadataTags({
  title: 'My Video',
  author: 'John Doe'
});

// Start and process
await output.start();

// Add samples to sources...

await output.finalize();

Build docs developers (and LLMs) love