The decode() method of the ImageDecoder interface enqueues a control message to decode the frame of an image.
A promise that resolves with an object containing the following members:
image -
A VideoFrame containing the decoded image.
complete -
A boolean, if true indicates that image contains the final full-detail output.
If an error occurs, the promise will resolve with following exception:
-
InvalidStateError DOMException
-
Returned if any of the following conditions apply:
-
close is true, meaning close() has already been called. - The requested frame does not exist.
The following example decodes the second frame (at index 1) and prints the resulting VideoFrame to the console.
let result = await imageDecoder.decode({ frameIndex: 1 });
console.log(result.image);
The following example decodes the first frame repeatedly until its complete:
let complete = false;
while (!complete) {
let result = await imageDecode.decode({ completeFramesOnly: false });
complete = result.complete;
}