w3c / webcodecs

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

How to cache decoded VideoFrames By CopyTo , is there demo? #500

Closed yangfangfang1204 closed 1 year ago

yangfangfang1204 commented 2 years ago

How to cache decoded VideoFrames By CopyTo , is there demo?

sandersdan commented 2 years ago

This is relatively straightforward (make a buffer, copy, create a new VideoFrame with matching metadata), but it's not a very efficient method for caching. It is the best option if you need your copies to be stored in system RAM, though.

If GPU RAM is not scarce (and your frames are hardware), I would recommend createImageBitmap() since it can in most cases avoid doing readback. It will do conversion to RGB, but in most cases that is more efficient than readback.

The best method would be the proposed VideoFrame.copy() API, see #436. I'm going to hold of producing a demo until I'm sure of what is happening with that API.

onthegit commented 2 years ago

This is is exactly the same question I have: how to make copyTo() work. Copying the attributes of frame and passing them in options as in https://github.com/w3c/webcodecs/issues/501#issuecomment-1162284163 throws error...

yangfangfang1204 commented 2 years ago

is there a demo that how to use VideoFrame.copy() , And What is the return value of the VideoFrame.copy() ? Is it a shared texture index or shared texture data?

sandersdan commented 2 years ago

There is no demo of copy() because copy() is not yet specified. It would return a new VideoFrame.

dalecurtis commented 1 year ago

Could use a sample, but copyTo now has MDN documentation, let us know if that's insufficient.