Skip to content
Type

ConversionAudioOptions

Audio-specific options.

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

See AudioCodec, Quality, AudioSample, and MaybePromise.

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.

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.

Released under the Mozilla Public License 2.0.