Skip to main content
The Output class orchestrates the creation of a new media file, allowing you to add tracks and configure output settings.

Constructor

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

Properties

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

Methods

addVideoTrack()

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

addAudioTrack()

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

addSubtitleTrack()

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

setMetadataTags()

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.
MetadataTags
required
Metadata tags to write to the output file.

start()

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()

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()

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()

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