The EncodedVideoChunk class represents a single chunk of encoded video data. Each chunk is either a keyframe (can be decoded independently) or a delta frame (requires previous frames to decode).
import { EncodedVideoChunk } from 'node-webcodecs';// Create from encoded H.264 dataconst chunk = new EncodedVideoChunk({ type: 'key', // 'key' for keyframe, 'delta' for P/B frames timestamp: 0, // Presentation time in microseconds duration: 33333, // Frame duration in microseconds (30fps = ~33333μs) data: encodedH264Data // Uint8Array or ArrayBuffer});// Access propertiesconsole.log(chunk.type); // 'key'console.log(chunk.timestamp); // 0console.log(chunk.byteLength); // Size of encoded data// Copy data to another bufferconst buffer = new Uint8Array(chunk.byteLength);chunk.copyTo(buffer);
The frame type. Use 'key' for keyframes (I-frames) that can be decoded independently,
or 'delta' for frames that depend on previous frames (P/B-frames).
An ArrayBuffer or TypedArray to copy the data into. Must have at least byteLength bytes available.
Throws:TypeError if the destination buffer is smaller than byteLength.
Example: Copying chunk data
Copy
const chunk = new EncodedVideoChunk({ type: 'key', timestamp: 0, data: someEncodedData});// Allocate buffer with exact size neededconst buffer = new Uint8Array(chunk.byteLength);chunk.copyTo(buffer);// Now buffer contains a copy of the encoded dataconsole.log(`Copied ${buffer.length} bytes`);