Skip to main content

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.

Audio sinks provide ways to retrieve decoded audio samples, audio buffers, and encoded packets from audio tracks.

AudioSampleSink

Sink for retrieving decoded audio samples from an audio track.

Constructor

new AudioSampleSink(audioTrack: InputAudioTrack)
audioTrack
InputAudioTrack
required
The audio track to read samples from

Methods

getSample

Retrieves the audio sample corresponding to the given timestamp.
async getSample(timestamp: number): Promise<AudioSample | null>
timestamp
number
required
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.
samples(startTimestamp?: number, endTimestamp?: number): AsyncGenerator<AudioSample, void, unknown>
startTimestamp
number
default:0
The timestamp in seconds at which to start yielding samples (inclusive)
endTimestamp
number
default:null
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.
samplesAtTimestamps(timestamps: AnyIterable<number>): AsyncGenerator<AudioSample | null, void, unknown>
timestamps
AnyIterable<number>
required
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 to AudioBuffer instances. This is often more useful than directly retrieving audio samples, as audio buffers can be directly used with the Web Audio API.

Constructor

new AudioBufferSink(audioTrack: InputAudioTrack)
audioTrack
InputAudioTrack
required
The audio track to read buffers from

Methods

getBuffer

Retrieves the audio buffer corresponding to the given timestamp.
async getBuffer(timestamp: number): Promise<WrappedAudioBuffer | null>
timestamp
number
required
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.
buffers(startTimestamp?: number, endTimestamp?: number): AsyncGenerator<WrappedAudioBuffer, void, unknown>
startTimestamp
number
default:0
The timestamp in seconds at which to start yielding buffers (inclusive)
endTimestamp
number
default:null
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.
buffersAtTimestamps(timestamps: AnyIterable<number>): AsyncGenerator<WrappedAudioBuffer | null, void, unknown>
timestamps
AnyIterable<number>
required
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.
buffer
AudioBuffer
An AudioBuffer instance
timestamp
number
The timestamp of the corresponding audio sample, in seconds
duration
number
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

new EncodedPacketSink(track: InputTrack)
track
InputTrack
required
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.
async getFirstPacket(options?: PacketRetrievalOptions): Promise<EncodedPacket | null>
options
PacketRetrievalOptions
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.
async getPacket(timestamp: number, options?: PacketRetrievalOptions): Promise<EncodedPacket | null>
timestamp
number
required
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.
options
PacketRetrievalOptions
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).
async getNextPacket(packet: EncodedPacket, options?: PacketRetrievalOptions): Promise<EncodedPacket | null>
packet
EncodedPacket
required
The current packet
options
PacketRetrievalOptions
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.
async getKeyPacket(timestamp: number, options?: PacketRetrievalOptions): Promise<EncodedPacket | null>
timestamp
number
required
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.
options
PacketRetrievalOptions
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).
async getNextKeyPacket(packet: EncodedPacket, options?: PacketRetrievalOptions): Promise<EncodedPacket | null>
packet
EncodedPacket
required
The current packet
options
PacketRetrievalOptions
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.
packets(
  startPacket?: EncodedPacket,
  endPacket?: EncodedPacket,
  options?: PacketRetrievalOptions
): AsyncGenerator<EncodedPacket, void, unknown>
startPacket
EncodedPacket
The packet from which iteration should begin. This packet will also be yielded.
endPacket
EncodedPacket
The packet at which iteration should end. This packet will not be yielded.
options
PacketRetrievalOptions
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.
metadataOnly
boolean
default:false
When set to true, only packet metadata (like timestamp) will be retrieved - the actual packet data will not be loaded.
verifyKeyPackets
boolean
default:false
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.

Build docs developers (and LLMs) love