EncodedAudioChunk
TheEncodedAudioChunk 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.
This class follows the W3C WebCodecs EncodedAudioChunk specification.
Quick Example
Constructor
Creates a newEncodedAudioChunk from initialization data.
Configuration object for the encoded chunk.
Properties
All properties are readonly after construction.The chunk type. For audio, this is almost always
'key' since most audio codecs
don’t use inter-frame prediction.Presentation timestamp in microseconds. Determines when this audio should be played
relative to the start of the stream.
Duration of this audio chunk in microseconds, or
null if not specified during construction.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.An
ArrayBuffer or TypedArray to copy the data into. Must have at least byteLength bytes available.TypeError if the destination buffer is smaller than byteLength.
Example: Copying chunk data
Example: Copying chunk data
Type Definitions
EncodedAudioChunkType
EncodedAudioChunkInit
Usage with AudioEncoder
EncodedAudioChunk objects are typically created by AudioEncoder and passed to your output callback:
Usage with AudioDecoder
PassEncodedAudioChunk 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