Skip to content
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

YCoCg matrix support #678

Open
fabiosky opened this issue Jun 5, 2023 · 2 comments
Open

YCoCg matrix support #678

fabiosky opened this issue Jun 5, 2023 · 2 comments
Labels

Comments

@fabiosky
Copy link

fabiosky commented Jun 5, 2023

Currently the VideoColorSpace: matrix property supports the following values:

  • "rgb"
    Matrix coefficients used by sRGB.
  • "bt709"
    Matrix coefficients used by BT.709.
  • "bt470bg"
    Matrix coefficients used by BT.601 PAL.
  • "smpte170m"
    Matrix coefficients used by BT.601 NTSC.

It is known that:

  • At least H.264/MPEG-4 AVC and HEVC are fully supporting such color space
  • It has good coding gain (at least comparable to ycbcr/bt.601 with full range)
  • Conversion from/to rgb color space should be faster than with ycbcr/bt.601 since it results in additions/shifts for integer arithmetic, or just multiplies by 0.25 and 0.5 for float ones)

Are there any plans to support such color space?

Thanks,
Fabio

@sandersdan
Copy link
Contributor

Color matrices are being added on-demand, based on usage where data is available.

In H.273, this matrix is called YCgCo and has ID 8. I do not currently have usage data to share, but it is my understanding that YCgCo content is rare in practice. FFmpeg describes it as "used by Dirac / VC-2 and H.264 FRext".

I expect that browsers already support this color matrix, so adding it to WebCodecs is probably trivial.

@fabiosky
Copy link
Author

fabiosky commented Jun 6, 2023

Thanks for the explanation.

Currently it is already possible to achieve more or less the wanted feature by either using a software implementation of webcodecs (tested just on Chrome), or using VideoFrame.copyTo and at that point one can have full control on the yuv planes and thus also the conversion to rgb.

However, both solutions are typically slower than rather using the hardware implementation as in the first case decoding would be slower and with copyTo it is likely that copy from gpu to cpu would be slower as well.

Most efficient path would be use the hardware implementation and process the generated frame within WebGL/WebGPU. Not checked on WebGPU actually, but at least with WebGL produced colors looks incorrect; that suggested me about the lack of internal YCoCg to RGB conversion when binding an external texture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants