Skip to main content

EncodedAudioChunk

The EncodedAudioChunk class represents a single chunk of encoded audio data. Unlike video, most audio codecs produce chunks that are all keyframes (independently decodable), though some codecs may use delta encoding.

Quick Example


Constructor

Creates a new EncodedAudioChunk from initialization data.
init
EncodedAudioChunkInit
required
Configuration object for the encoded chunk.
The type must be exactly 'key' or 'delta'. Any other value will throw a TypeError.

Properties

All properties are readonly after construction.
type
'key' | 'delta'
required
The chunk type. For audio, this is almost always 'key' since most audio codecs don’t use inter-frame prediction.
timestamp
number
required
Presentation timestamp in microseconds. Determines when this audio should be played relative to the start of the stream.
duration
number | null
required
Duration of this audio chunk in microseconds, or null if not specified during construction.
byteLength
number
required
Size of the encoded data in bytes. Use this to allocate a buffer for copyTo().

Methods

copyTo()

Copies the encoded audio data to a destination buffer.
destination
BufferSource
required
An ArrayBuffer or TypedArray to copy the data into. Must have at least byteLength bytes available.
Throws: TypeError if the destination buffer is smaller than byteLength.

Type Definitions

EncodedAudioChunkType

EncodedAudioChunkInit


Usage with AudioEncoder

EncodedAudioChunk objects are typically created by AudioEncoder and passed to your output callback:

Usage with AudioDecoder

Pass EncodedAudioChunk objects to AudioDecoder.decode():

Audio Codec Frame Sizes

Different audio codecs produce chunks of different durations:

See Also

EncodedVideoChunk

The video equivalent for encoded video data

AudioEncoder

Encodes AudioData into EncodedAudioChunks

AudioDecoder

Decodes EncodedAudioChunks into AudioData

AudioData

Raw audio sample data