w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
978 stars 136 forks source link

How to convert VideoFrame to image format and save it ? #538

Closed yangfangfang1204 closed 2 years ago

yangfangfang1204 commented 2 years ago

decode the video raw data by webcodecs ,and i got the videoframe , use drawimage api to display the videoframe . There is a need that save the image . it also could render the videoframe in canvas ,and use HTMLCanvasElement.toBlob or toDataURL to save the image ,but it is high performance overhead. so there is solution to save the image by VideoFrame ?

yangfangfang1204 commented 2 years ago

when use HTMLCanvasElement.toBlob or toDataURL to save the image , the image will be fuzzy .After a while the screen returned to normal, so I guess it was performance consuming.

sandersdan commented 2 years ago

<canvas> is the only way to have the browser encode an image currently, as WebCodecs does not have an ImageEncoder. It's possible that that might happen some day, but it's also possible to copy the VideoFrame using copyTo(), then encode it using any JS or WASM image encoder.