Skip to content
Class

Output

Main class orchestrating the creation of new media files.

Extends: EventEmitter

Used by

Type parameters

ts
Output<
	F extends OutputFormat = OutputFormat,
	T extends Target = Target,
>

See OutputFormat and Target.

Constructor

ts
constructor(
	options: OutputOptions<F, T>,
): Output;

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

Properties

defaultTrackGroup

ts
readonly defaultTrackGroup: OutputTrackGroup;

The OutputTrackGroup that all tracks are assigned to by default unless otherwise specified by BaseTrackMetadata.group.

format

ts
readonly format: F;

The format of the output file.

state

ts
state: 'pending' | 'started' | 'canceled' | 'finalizing' | 'finalized';

The current state of the output.

target

ts
get target(): T;

The target to which the root file will be written. Throws when using PathedTarget with an async callback; prefer the 'target' event for those cases.

Methods

addAudioTrack()

ts
addAudioTrack(
	source: AudioSource,
	metadata: AudioTrackMetadata = {},
): OutputAudioTrack;

Adds an audio track to the output with the given source. Can only be called before the output is started.

See AudioSource, AudioTrackMetadata, and OutputAudioTrack.

addSubtitleTrack()

ts
addSubtitleTrack(
	source: SubtitleSource,
	metadata: SubtitleTrackMetadata = {},
): OutputSubtitleTrack;

Adds a subtitle track to the output with the given source. Can only be called before the output is started.

See SubtitleSource, SubtitleTrackMetadata, and OutputSubtitleTrack.

addVideoTrack()

ts
addVideoTrack(
	source: VideoSource,
	metadata: VideoTrackMetadata = {},
): OutputVideoTrack;

Adds a video track to the output with the given source. Can only be called before the output is started.

See VideoSource, VideoTrackMetadata, and OutputVideoTrack.

cancel()

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

finalize()

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

getMimeType()

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

on()

ts
on(
	event: K,
	listener: (data: TEvents[K]) => unknown,
	options?: EventListenerOptions,
): () => void;

Registers a listener for the given event.

See EventListenerOptions.

setMetadataTags()

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

See MetadataTags.

start()

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

Released under the Mozilla Public License 2.0.