Does opencv support alpha channel for videos?

Hi, I have a .webm video with an alpha channel which presence is confirmed by ffprobe:

Input #0, matroska,webm, from 'front_HD.webm':
    encoder         : libwebm-
    creation_time   : 2022-08-31T09:32:51.000000Z
  Duration: 00:00:05.96, start: -0.007000, bitrate: 8095 kb/s
    Stream #0:0(eng): Video: vp8, yuv420p(progressive), 720x1280, SAR 1:1 DAR 9:16, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
      alpha_mode      : 1
    Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)

When loading the video with VideoCapture however, I get frames of shape 720x1080x3 i.e. the alpha channel is missing.

According to Add support for reading 4-channel BGRA frames from video by anmoluppal · Pull Request #13395 · opencv/opencv · GitHub CAP_PROP_CONVERT_RGB=False should allow for RGBA frames but even with this the alpha chennel is missing when iterating over the frames.

Is it possible to read a video (in this case a .webm) preserving the alpha channel?


i’m afraid, that only works for webcams, not for video files using ffmpeg backend (no such thing in the src code)

(if i may ask, why do you want a friggin alpha channel here ? does not make much sense for computer-vision)

if you really need that feature, try the (rejected) patch from that pr, or, srsly, ditch opencv and use libffmpeg directly in your program

I was try to find a fast and hackish solution for a small POC and then fell into the rabbit hole of opencv and alpha channels.

Thanks for the inputs, appreciated.