Audio sinks provide ways to retrieve decoded audio samples, audio buffers, and encoded packets from audio tracks.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Vanilagy/mediabunny/llms.txt
Use this file to discover all available pages before exploring further.
AudioSampleSink
Sink for retrieving decoded audio samples from an audio track.Constructor
The audio track to read samples from
Methods
getSample
Retrieves the audio sample corresponding to the given timestamp.The timestamp used for retrieval, in seconds. Returns the last audio sample (in presentation order) with a start timestamp less than or equal to the given timestamp. Returns null if the timestamp is before the track’s first timestamp.
AudioSample | null
The audio sample at the specified timestamp, or null if not found
samples
Creates an async iterator that yields audio samples in presentation order.The timestamp in seconds at which to start yielding samples (inclusive)
The timestamp in seconds at which to stop yielding samples (exclusive)
AsyncGenerator<AudioSample>
An async iterator that yields audio samples. This method will intelligently pre-decode a few samples ahead to enable fast iteration.
samplesAtTimestamps
Creates an async iterator that yields an audio sample for each timestamp in the argument.An iterable or async iterable of timestamps in seconds. This method uses an optimized decoding pipeline if these timestamps are monotonically sorted, decoding each packet at most once.
AsyncGenerator<AudioSample | null>
An async iterator that yields audio samples. May yield null if no sample is available for a given timestamp.
AudioBufferSink
A sink that retrieves decoded audio samples from an audio track and converts them toAudioBuffer instances. This is often more useful than directly retrieving audio samples, as audio buffers can be directly used with the Web Audio API.
Constructor
The audio track to read buffers from
Methods
getBuffer
Retrieves the audio buffer corresponding to the given timestamp.The timestamp used for retrieval, in seconds. Returns the last audio buffer (in presentation order) with a start timestamp less than or equal to the given timestamp. Returns null if the timestamp is before the track’s first timestamp.
WrappedAudioBuffer | null
The audio buffer at the specified timestamp, or null if not found
buffers
Creates an async iterator that yields audio buffers in presentation order.The timestamp in seconds at which to start yielding buffers (inclusive)
The timestamp in seconds at which to stop yielding buffers (exclusive)
AsyncGenerator<WrappedAudioBuffer>
An async iterator that yields audio buffers. This method will intelligently pre-decode a few buffers ahead to enable fast iteration.
buffersAtTimestamps
Creates an async iterator that yields an audio buffer for each timestamp in the argument.An iterable or async iterable of timestamps in seconds. This method uses an optimized decoding pipeline if these timestamps are monotonically sorted, decoding each packet at most once.
AsyncGenerator<WrappedAudioBuffer | null>
An async iterator that yields audio buffers. May yield null if no buffer is available for a given timestamp.
WrappedAudioBuffer
An AudioBuffer with additional timing information.An AudioBuffer instance
The timestamp of the corresponding audio sample, in seconds
The duration of the corresponding audio sample, in seconds
EncodedPacketSink
Sink for retrieving encoded packets from an input track.This sink works with both audio and video tracks and provides access to raw encoded packet data.
Constructor
The input track to read encoded packets from
Methods
getFirstPacket
Retrieves the track’s first packet (in decode order), or null if it has no packets.Additional options for controlling packet retrieval
EncodedPacket | null
The first packet in the track. The first packet is very likely to be a key packet.
getPacket
Retrieves the packet corresponding to the given timestamp.The timestamp used for retrieval, in seconds. Returns the last packet (in presentation order) with a start timestamp less than or equal to the given timestamp. Use
getPacket(Infinity) to retrieve the track’s last packet.Additional options for controlling packet retrieval
EncodedPacket | null
The packet at the specified timestamp, or null if the timestamp is before the first packet in the track
getNextPacket
Retrieves the packet following the given packet (in decode order).The current packet
Additional options for controlling packet retrieval
EncodedPacket | null
The next packet, or null if the given packet is the last packet
getKeyPacket
Retrieves the key packet corresponding to the given timestamp.The timestamp used for retrieval, in seconds. Returns the last key packet (in presentation order) with a start timestamp less than or equal to the given timestamp. A key packet is a packet that doesn’t require previous packets to be decoded. Use
getKeyPacket(Infinity) to retrieve the track’s last key packet.Additional options for controlling packet retrieval. To ensure that the returned packet is guaranteed to be a real key frame, enable
options.verifyKeyPackets.EncodedPacket | null
The key packet at the specified timestamp, or null if the timestamp is before the first key packet in the track
getNextKeyPacket
Retrieves the key packet following the given packet (in decode order).The current packet
Additional options for controlling packet retrieval. To ensure that the returned packet is guaranteed to be a real key frame, enable
options.verifyKeyPackets.EncodedPacket | null
The next key packet, or null if the given packet is the last key packet
packets
Creates an async iterator that yields the packets in this track in decode order.The packet from which iteration should begin. This packet will also be yielded.
The packet at which iteration should end. This packet will not be yielded.
Additional options for controlling packet retrieval
AsyncGenerator<EncodedPacket>
An async iterator that yields encoded packets. This method will intelligently preload packets based on the speed of the consumer.
PacketRetrievalOptions
Additional options for controlling packet retrieval.When set to
true, only packet metadata (like timestamp) will be retrieved - the actual packet data will not be loaded.When set to true, key packets will be verified upon retrieval by looking into the packet’s bitstream. If not enabled, the packet types will be determined solely by what’s stored in the containing file and may be incorrect, potentially leading to decoder errors. Since determining a packet’s actual type requires looking into its data, this option cannot be enabled together with
metadataOnly.