Skip to content
Type

AudioEncodingConfig

Configuration object that controls audio encoding. Can be used to set codec, quality, and more.

ts
type AudioEncodingConfig = {
	codec: AudioCodec;
	quality?: Quality;
	bitrate?: number | Quality;
	transform?: AudioTransformOptions;
	onEncodedPacket?: (packet: EncodedPacket, meta: EncodedAudioChunkMetadata | undefined) => unknown;
	onEncoderConfig?: (config: AudioEncoderConfig) => unknown;
	onEncodedSample?: (sample: AudioSample) => unknown;
} & AudioEncodingAdditionalOptions;

See AudioCodec, Quality, AudioTransformOptions, EncodedPacket, AudioSample, and AudioEncodingAdditionalOptions.

Used by

Properties

codec

ts
codec: AudioCodec;

The audio codec that should be used for encoding the audio samples.

See AudioCodec.

quality

ts
quality?: Quality;

The desired quality of the encoded audio. Required for compressed audio codecs, unused for PCM codecs.

See Quality.

bitrate

ts
bitrate?: number | Quality;

The target bitrate for the encoded audio, in bits per second. Alternatively, a Quality can be provided.

See Quality.

transform

ts
transform?: AudioTransformOptions;

Optional transformations to apply to the audio samples before they are passed to the encoder.

See AudioTransformOptions.

bitrateMode

ts
bitrateMode?: 'constant' | 'variable';

Configures the bitrate mode. A bitrate mode set directly on a Quality takes precedence over this field.

fullCodecString

ts
fullCodecString?: string;

The full codec string as specified in the Mediabunny Codec Registry. This string must match the codec specified in codec. When not set, a fitting codec string will be constructed automatically by the library.

Events

onEncodedPacket

ts
onEncodedPacket?: (packet: EncodedPacket, meta: EncodedAudioChunkMetadata | undefined) => unknown;

Called for each successfully encoded packet. Both the packet and the encoding metadata are passed.

See EncodedPacket.

onEncoderConfig

ts
onEncoderConfig?: (config: AudioEncoderConfig) => unknown;

Called when the internal encoder config, as used by the WebCodecs API, is created.

onEncodedSample

ts
onEncodedSample?: (sample: AudioSample) => unknown;

Called right before a sample is passed to the encoder.

See AudioSample.

Released under the Mozilla Public License 2.0.