'How correctly show video with transparency in Qt with OpenCV + FFMpeg

I'm trying to show a video with transparency in a Qt6 application using OpenCV + FFMPEG. Actually those are tool versions:

  • Win 11
  • Qt 6.3.0
  • OpenCV 4.5.5 (built with CMake)
  • FFMPEG 2022-04-03-git-1291568c98-full_build-www.gyan.dev

I've used a base .mov video with transparency as test (link provided below). First of all I've converted .mov video to .webm video (VP9) and I see in output text that alpha channel remains

ffmpeg -i '.\Retro Bars.mov' -c:v libvpx-vp9 -crf 30 -b:v 0 output.webm

Input #0, mov,mp4,m4a,3gp,3g2,mj2,
    ...
    Stream #0:0[0x1](eng): Video: qtrle (rle  / 0x20656C72), argb(progressive),
    ...

Output #0, webm, 
   ...
   Stream #0:0(eng): Video: vp9, yuva420p(tv, progressive),
   ...

But when I show info of output file with ffmpeg it loses alpha channel:

ffmpeg -i .\output.webm

Input #0, matroska,webm,
    ...
    Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, progressive),
    ...

If I open output.webm with OBS it is shown correctly without a background, as shown in picture: obs_load

If I try to open it with OpenCV + FFMPEG it shows a black background under bars, as shown in picture: Qt_out

This is how I load video in Qt:

cv::VideoCapture capture;
capture.open(filename, cv::CAP_FFMPEG);
capture.set(cv::CAP_PROP_CONVERT_RGB, false); // try forcing load alpha channel
... //in a thread
while (capture.read(frame)) {
    qDebug() << "c" << frame.channels() << "t" <<  frame.type() << "d" <<  frame.depth(); // output: c 3 t 16 d 0
    cv::cvtColor(frame, frame, cv::COLOR_BGR2RGBA); //useless since no alpha channel is detected
    img = QImage(frame.data, frame.cols, frame.rows, QImage::Format_RGBA8888);
    emit processedImage(img); // to show image in a QLabel with QPixmap::fromImage(img)
}

I think the problem is when I load the video with OpenCV, it doens't detect alpha channel, since I can load correctly in other player (obs, html5, etc.)

What I'm wrong with all process to show this video in Qt with transparency?

EDIT: Added dropbox link with test video + ffmpeg outputs: sample items



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source