Skip to content
Type

ConversionAudioOptions

Audio-specific options.

ts
type ConversionAudioOptions = {
	discard?: boolean;
	numberOfChannels?: number;
	sampleRate?: number;
	sampleFormat?: 'u8' | 's16' | 's32' | 'f32';
	codec?: AudioCodec;
	bitrate?: number | Quality;
	forceTranscode?: boolean;
	process?: (sample: AudioSample) => MaybePromise<
		AudioSample | AudioSample[] | null
	>;
	processedNumberOfChannels?: number;
	processedSampleRate?: number;
	group?: OutputTrackGroup | OutputTrackGroup[];
};

See AudioCodec, Quality, AudioSample, MaybePromise, and OutputTrackGroup.

Used by

Properties

discard

ts
discard?: boolean;

If true, all audio tracks will be discarded and will not be present in the output.

numberOfChannels

ts
numberOfChannels?: number;

The desired channel count of the output audio.

sampleRate

ts
sampleRate?: number;

The desired sample rate of the output audio, in hertz.

sampleFormat

ts
sampleFormat?: 'u8' | 's16' | 's32' | 'f32';

The desired sample format (and therefore bit depth) of the audio samples before they are passed to the encoder. Can be used to control bit depth with certain output codecs such as FLAC.

Setting this field forces audio transcoding.

codec

ts
codec?: AudioCodec;

The desired output audio codec.

See AudioCodec.

bitrate

ts
bitrate?: number | Quality;

The desired bitrate of the output audio.

See Quality.

forceTranscode

ts
forceTranscode?: boolean;

When true, audio will always be re-encoded instead of directly copying over the encoded samples.

process

ts
process?: ((sample: AudioSample) => MaybePromise<AudioSample | AudioSample[] | null>);

Allows for custom user-defined processing of audio samples, e.g. for applying audio effects, transformations, or timestamp modifications. Will be called for each input audio sample after remixing and resampling.

Must return an AudioSample, an array of them, or null for dropping the sample.

This function can also be used to manually perform remixing or resampling. When doing so, you should signal the post-process parameters using the processedNumberOfChannels and processedSampleRate fields, which enables the encoder to better know what to expect. If these fields aren't set, Mediabunny will assume you won't perform remixing or resampling.

See AudioSample and MaybePromise.

processedNumberOfChannels

ts
processedNumberOfChannels?: number;

An optional hint specifying the channel count of audio samples returned by the process function, for better encoder configuration.

processedSampleRate

ts
processedSampleRate?: number;

An optional hint specifying the sample rate of audio samples returned by the process function, for better encoder configuration.

group

ts
group?: OutputTrackGroup | OutputTrackGroup[];

Defines the group(s) the output track is a part of. For more, see BaseTrackMetadata.group.

If left blank, tracks will internally be assigned to groups such that the output track pairability graph exactly matches the input track pairability graph.

See OutputTrackGroup.

Released under the Mozilla Public License 2.0.