-
Notifications
You must be signed in to change notification settings - Fork 144
Decoding WebM files with alpha #377
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
Comments
WebCodecs supports alpha frames, but I don't think any codecs that support alpha are available in any implementation. Taking VP9 as an example, the alpha is conventionally encoded as a separate stream, and the decoder takes the alpha stream as side data on each packet. WebCodecs doesn't have side data on Chrome's current implementation of |
Hi @sandersdan, can Chrome encode VP9/VP8 video with alpha now? |
No, not yet. There is currently no timeline for this feature in WebCodecs. |
HEVC with Alpha decoding on macOS has recently been implemented in the latest Chrome Canary 108. It supports WebCodec API well, meanwhile can preserve its alpha layer. A simple demo here FYI. |
@sandersdan any pointers on how to encode the alpha channel as a separate stream and combine in JS? I have the need to alpha video + webcodecs that will work correctly on Win+Mac in Chrome. |
To combine in JS you'll need the opaque pixel data and alpha data in CPU memory. You can then merge them into a I420A frame or RGB convert into RGBA/BGRA. There's no way to zip hardware decoded opaque data with hardware/software decoded alpha data with the current API, so you'll need to use |
Thanks for responding so quickly @dalecurtis . So it looks pretty easy to extract out the alpha channel with ffmpeg using the alphaextract filter. And also easy to decode both the regular file + alpha file - modifying the webcodec decode sample (https://github.com/w3c/webcodecs/tree/main/samples/video-decode-display). However a couple things:
which gives me Thank again for your help |
More recent versions of Chrome should have less cases where the format is null. When it's null you need to go through ImageBitmap or canvas to read back the pixel data. If the data you readback is in RGBx or BGRx format you just need to replace each alpha byte with the corresponding one from your alpha stream. If your draw primitives can source the alpha plane from elsewhere you don't even need to zip into RGBA. |
@dalecurtis sorry to bother you again, but I am back on this task and having an issue with the data coming back from copyTo. It appears to be YUV420p by its size, and its y values seem correct. For a 640x360 frame, layout returned shows
So my images are coming out with b/w looking correct, but the color incorrect. Is there something I am missing here? |
Given that you only have two returned layouts, it seems like it's NV12 instead of I420? |
omg, yes. Can't believe I did not notice that. Thank you again. |
The issue is closed, but I thought @dalecurtis might want to see the webcodecs-powered alpha video feature which finally was enabled for general use in Scenery this week: |
@rcunning Could you explain how did you make h265 alpha channel video? I tried with FFMPEG + libx265 but it failed. |
I did not use h265! I created an .mp4 with two h264 video tracks:
Then at decode+render time I combined each paired VideoFrame rendered textures to get a single RGBA texture for display. |
Thanks for your reply @rcunning ! So basically you have two |
Yep. |
Do webcodec decoding operation support alpha channels in webm files?
I'm using https://github.com/Yahweasel/mkvdemuxjs demuxer for getting chunks and webcodes VideoDecoder for getting VideoFrames. But when I draw frame on canvas, alpha layer from input webm file is missing.
I'm not sure if it's problem of demuxer or of webcodecs..
I noticed that encoder does support alpha: 'keep' option, I looked for something similar for decoder but with no luck
The text was updated successfully, but these errors were encountered: