Skip to content
Class

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

Constructor

ts
constructor(
	data: Uint8Array,
	type: PacketType,
	timestamp: number,
	duration: number,
	sequenceNumber: number = -1,
	byteLength?: number,
): EncodedPacket;

Creates a new EncodedPacket from raw bytes and timing information.

See PacketType.

Static methods

fromEncodedChunk()

ts
static fromEncodedChunk(
	chunk: EncodedVideoChunk | EncodedAudioChunk,
): EncodedPacket;

Creates an EncodedPacket from an EncodedVideoChunk or EncodedAudioChunk. This method is useful for converting chunks from the WebCodecs API to EncodedPackets.

Properties

byteLength

ts
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

ts
readonly data: Uint8Array;

The encoded data of this packet.

duration

ts
readonly duration: number;

The duration of this packet in seconds.

isMetadataOnly

ts
get isMetadataOnly(): boolean;

If this packet is a metadata-only packet. Metadata-only packets don't contain their packet data.

microsecondDuration

ts
get microsecondDuration(): number;

The duration of this packet in microseconds.

microsecondTimestamp

ts
get microsecondTimestamp(): number;

The timestamp of this packet in microseconds.

sequenceNumber

ts
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.

timestamp

ts
readonly timestamp: number;

The presentation timestamp of this packet in seconds. May be negative. Samples with negative end timestamps should not be presented.

type

ts
readonly type: PacketType;

The type of this packet.

See PacketType.

Methods

toEncodedVideoChunk()

ts
toEncodedVideoChunk(): EncodedVideoChunk;

Converts this packet to an EncodedVideoChunk for use with the WebCodecs API.

toEncodedAudioChunk()

ts
toEncodedAudioChunk(): EncodedAudioChunk;

Converts this packet to an EncodedAudioChunk for use with the WebCodecs API.

clone()

ts
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.

Released under the Mozilla Public License 2.0.