-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for conversion between pixel formats #92
Comments
The urgency of this API is reduced. Previously we expected this would be primary means to read back pixel data from GPU backed frames into the CPU space. Since then we've managed to add support (in chromium, not yet in the spec) for exposing pixel data from GPU backed video frames coming off of the users camera in the NV12 pixel format. A conversion API is still interesting to pursue, but there are no urgent use cases that we are aware of (feel free to share some). |
#208, for reference, but this would still be good to have. |
triage note: marking extension, as this would be a new API. |
this means, of course, that any application that handles only a limited set of formats will be broken every time a new format is encountered. Seems a rough deal for app developers. |
There is a fallback path; you can createImageBitmap(videoFrame), then read back that ImageBitmap (presumably as RGBA). This isn't great if the frame was mappable in the first place, but for GPU-backed frames it actually has acceptable performance. |
So this means that we have a fallback (effectively "read as RGBA"). Apps can choose between using a fast path if they support the current format and a slow path if they don't. For a lot of cases, this will be sufficient. |
Options for potential chromium impl in https://bugs.chromium.org/p/chromium/issues/detail?id=1139119 |
Is there anything that would enforce that conversion? Currently the HTML specs for
I guess the term "visible pixel data" is open to interpretation, but there doesn't seem to be anything there asking for a conversion of the pixel format. |
We've had a few requests for this in different forms, so going to mark as p1 to at least add support for converting to RGBA/BGRA which is already required for canvas interactions. |
API Change Proposal
Example
|
@padenot hasn't been a fan of exceptions for feature signaling in the past. So we could also have a simple |
Thanks @Djuffin for proposing the API. Can't wait to use the copyTo with specific format, it will definitely boost the performance when handling VideoFrame in different format. Do we have any schedule on finalizing this API? And in practice, how long would it take to implement it in Chrome/Edge? |
A method that returns a promise cannot throw, or this would be a new pattern. Also, I am not a big fan of optional/open ended support as it might trigger compat issues. |
Agree that it should reject rather than throw. It is possible for a Promise-returning API to throw, but also terrible style w/o precedent in DOM AFAIK. |
Rejecting with |
At TPAC Media WG agreed on this way forward. Two new members in VideoFrameCopyToOptions dictionary
With Exampleconst options = {
format: 'RGBA',
colorSpace: 'display-p3'
};
const bufSize = frame.allocationSize(options);
const buffer = new Uint8ClampedArray(size);
await frame.copyTo(buffer, options);
const image_data = new ImageData(buffer, frame.codedWidth, frame.codedHeight,
{ colorSpace: 'display-p3' }); |
At TPAC we were aligned on overall direction, but there were some concerns about potentially confusing naming of the pixel formats and color spaces, that we should review; https://www.w3.org/2023/09/11-mediawg-minutes.html#t05 |
Nigel expressed concern about pixel format named RGB. |
I agree, but also wonder if we should also include the bpp in the pixel format names, as is commonly done in native APIs (example). This would help clarify the actual memory layout as well as further distinguish from the color space. |
I agree that the pixel format enum values could benefit from bit depth in the name. |
Currently the spec lists one format: I420. We'll want more, including some format to indicate "opaque", which will be used for GPU backed frames to avoid having to always copy to CPU memory.
Particularly for "opaque", we want an API to convert to another format where the planes can be read (performing the copy to CPU along the way). This API could also be used to convert between various non-opaque formats. Something like...
let frame = await gpu_frame.convertTo(I420);
The text was updated successfully, but these errors were encountered: