Skip to main content

EncodedPacket

Represents an encoded chunk of media. Used as an expressive wrapper around WebCodecs API’s EncodedVideoChunk and EncodedAudioChunk, but can also be used standalone.

Constructor

Uint8Array
required
The encoded data of this packet. For any given codec, this data must adhere to the format specified in the Mediabunny Codec Registry.
PacketType
required
The type of this packet: 'key' or 'delta'.
number
required
The presentation timestamp of this packet in seconds. May be negative. Samples with negative end timestamps should not be presented.
number
required
The duration of this packet in seconds.
number
default:"-1"
The sequence number indicates the decode order of the packets. Packet A must be decoded before packet B if A has a lower sequence number than B. If two packets have the same sequence number, they are the same packet. Negative sequence numbers mean the sequence number is undefined.
number
The actual byte length of the data in this packet. This field is useful for metadata-only packets where the data field contains no bytes.
EncodedPacketSideData
Additional data carried with this packet.

Properties

Uint8Array
The encoded data of this packet.
PacketType
The type of this packet: 'key' or 'delta'.
number
The presentation timestamp in seconds.
number
The duration in seconds.
number
The sequence number for decode order.
number
The actual byte length of the data.
EncodedPacketSideData
Additional data carried with this packet.

Methods

toEncodedVideoChunk()

Converts this packet to an EncodedVideoChunk.

toEncodedAudioChunk()

Converts this packet to an EncodedAudioChunk.

toEncodedChunk()

Converts this packet to either an EncodedVideoChunk or EncodedAudioChunk.

PacketType

The type of a packet. Key packets can be decoded without previous packets, while delta packets depend on previous packets.
string
Key (keyframe) packets can be decoded independently without previous packets.
string
Delta packets depend on previous packets for decoding.

EncodedPacketSideData

Holds additional data accompanying an EncodedPacket.
Uint8Array
An encoded alpha frame, encoded with the same codec as the packet. Typically used for transparent videos, where the alpha information is stored separately from the color information.
number
The actual byte length of the alpha data. This field is useful for metadata-only packets where the alpha field contains no bytes.

Example

See also