EncodedPacket
Represents an encoded chunk of media. Mainly used as an expressive wrapper around WebCodecs API's EncodedVideoChunk and EncodedAudioChunk, but can also be used standalone.
Used by
AudioEncodingConfig.onEncodedPacketCustomAudioDecoder.decode()CustomAudioEncoder.onPacketCustomVideoDecoder.decode()CustomVideoEncoder.onPacketEncodedAudioPacketSource.add()EncodedPacketSink.getFirstPacket()EncodedPacketSink.getKeyPacket()EncodedPacketSink.getNextKeyPacket()EncodedPacketSink.getNextPacket()EncodedPacketSink.getPacket()EncodedPacketSink.packets()EncodedVideoPacketSource.add()InputAudioTrack.determinePacketType()InputTrack.determinePacketType()InputVideoTrack.determinePacketType()VideoEncodingConfig.onEncodedPacket
Constructor
constructor(
data: Uint8Array,
type: PacketType,
timestamp: number,
duration: number,
sequenceNumber: number = -1,
byteLength?: number,
sideData?: EncodedPacketSideData,
): EncodedPacket;Creates a new EncodedPacket from raw bytes and timing information.
See PacketType and EncodedPacketSideData.
Static methods
fromEncodedChunk()
static fromEncodedChunk(
chunk: EncodedVideoChunk | EncodedAudioChunk,
sideData?: EncodedPacketSideData,
): EncodedPacket;Creates an EncodedPacket from an EncodedVideoChunk or EncodedAudioChunk. This method is useful for converting chunks from the WebCodecs API to EncodedPacket instances.
Properties
byteLength
readonly byteLength: 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.
data
readonly data: Uint8Array;The encoded data of this packet.
duration
readonly duration: number;The duration of this packet in seconds.
isMetadataOnly
get isMetadataOnly(): boolean;If this packet is a metadata-only packet. Metadata-only packets don't contain their packet data.
microsecondDuration
get microsecondDuration(): number;The duration of this packet in microseconds.
microsecondTimestamp
get microsecondTimestamp(): number;The timestamp of this packet in microseconds.
sequenceNumber
readonly sequenceNumber: number;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. Otherwise, sequence numbers are arbitrary and are not guaranteed to have any meaning besides their relative ordering. Negative sequence numbers mean the sequence number is undefined.
sideData
readonly sideData: EncodedPacketSideData;Additional data carried with this packet.
timestamp
readonly timestamp: number;The presentation timestamp of this packet in seconds. May be negative. Samples with negative end timestamps should not be presented.
type
readonly type: PacketType;The type of this packet.
See PacketType.
Methods
toEncodedVideoChunk()
toEncodedVideoChunk(): EncodedVideoChunk;Converts this packet to an EncodedVideoChunk for use with the WebCodecs API.
alphaToEncodedVideoChunk()
alphaToEncodedVideoChunk(
type: PacketType = this.type,
): EncodedVideoChunk;Converts this packet to an EncodedVideoChunk for use with the WebCodecs API, using the alpha side data instead of the color data. Throws if no alpha side data is defined.
See PacketType.
toEncodedAudioChunk()
toEncodedAudioChunk(): EncodedAudioChunk;Converts this packet to an EncodedAudioChunk for use with the WebCodecs API.
clone()
clone(
options?: {
/** The timestamp of the cloned packet in seconds. */
timestamp?: number;
/** The duration of the cloned packet in seconds. */
duration?: number;
},
): EncodedPacket;Clones this packet while optionally updating timing information.