VideoDecoder: decode() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Note: This feature is available inDedicated Web Workers.
Thedecode() method of theVideoDecoder interface enqueues a control message to decode a given chunk of video.
In this article
Syntax
js
decode(chunk)Parameters
chunkAn
EncodedVideoChunkobject representing a chunk of encoded video.
Return value
None (undefined).
Exceptions
InvalidStateErrorDOMExceptionThrown if the
stateis notconfigured.DataErrorDOMExceptionThrown if the
chunkis unable to be decoded due to relying on other frames for decoding.
Examples
The following example demonstrates how to use thedecode() method to decodeEncodedVideoChunk objects created from encoded video data.
js
const responses = await downloadVideoChunksFromServer(timestamp);for (const response of responses) { const chunk = new EncodedVideoChunk({ timestamp: response.timestamp, type: response.key ? "key" : "delta", data: new Uint8Array(response.body), }); decoder.decode(chunk);}Specifications
| Specification |
|---|
| WebCodecs> # dom-videodecoder-decode> |