QVideoSink doesn't handle alpha channel
-
I've a WebM (VP9) video with alpha channel on it. I can open correctly the video on OBS and it shows as intended, but if I try to use it in
QVideoSink
usingvideoFrameChanged
to show video frame by frame it shows a black background instead of transparent. I'm using Qt 6.3.0 RCHere ffmpeg file info :
PixelFormat
of eachQVideoFrame
isFormat_BGRA8888
, when converted toQImage
becomesFormat_ARGB32_Premultiplied
, all of them has an alpha channel so why my video show transparency as a black pixel?EDIT: If I check alpha channel with
hasAlpha()
onframe.image()
is true,QPixmap::fromImage(frame.image)
returns false!connect(videoSink, &QVideoSink::videoFrameChanged, [=](const QVideoFrame& frame) { qDebug() << QPixmap::fromImage(frame.toImage()).hasAlpha(); //FALSE qDebug() << frame.toImage().hasAlphaChannel(); // TRUE videoLabel->setPixmap(QPixmap::fromImage(frame.toImage())); });
-
Hi,
On which do you see this result ?
-
Why not use OpenCV to read the video stream directly ?
-
@SGaist Well because that would be a future work, but maybe it is more simple to start directly with OpenCV than try to do the same first with native Qt code and then add OpenCV to it. I will build OpenCV and try to use it.
How can I set the output of OpenCV frames in myQLabel
? -
Convert the cv::Mat to a QImage.
-
@SGaist I figured out how to show an image with alpha correctly. But I still cannot show a video/gif with alpha. I'm able to load it without problem in Qt but not with opencv. The only problem with Qt is a video with alpha (webm) that it shown with a background instead of transparency.
While learning how use properly opencv, how can I show videos with alpha channel in Qt? -
From a cursorary look, I think the frame is rendered on a black background in the backend code. You would have to modify this code to achieve what you want.
-
Sure you can. You can clone the QtMultimedia sources.