files/en-us/web/api/videodecoder/decode/index.md
{{APIRef("WebCodecs API")}}{{SecureContext_Header}}{{AvailableInWorkers("window_and_dedicated")}}
The decode() method of the {{domxref("VideoDecoder")}} interface enqueues a control message to decode a given chunk of video.
decode(chunk)
chunk
None ({{jsxref("undefined")}}).
InvalidStateError {{domxref("DOMException")}}
configured.DataError {{domxref("DOMException")}}
chunk is unable to be decoded due to relying on other frames for decoding.The following example demonstrates how to use the decode() method to decode {{domxref("EncodedVideoChunk")}} objects created from encoded video data.
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}}
{{Compat}}