I would like to display a video in my Qt QML 5.12 application but a video with an alpha channel, which means that there will be other displayed QML components behind the video.
For example, the video could display an animated logo in front of QML buttons, texts, ...
I tried to do it but Qt replaces the transparent areas in the video by black areas, and so the elements behind the video are not visible.
I use a .mov video file with the following codec information:
Codec: Apple ProRes 4444 XQ (ap4x)
Decoded format: Planar YUV 4:4:4 Y:U:V:A 10bits
Color primaries: ITU-R BT.709
Color transfer function: ITU-R BT.709
Color space: ITU-R BT.709 Range
So, is it possible to use QML Video component (or other) to display a video with an alpha channel, with transparent areas.
Thanks.
Firstly, if the transparent region is static (i.e. unchanging nor rotating) you could consider using
OpacityMask. If it's more complex, such as a video with a specific chroma-key color you want transparent, consider usingShaderEffect.In the following code, we treat "green" as the chroma-key by searching and replacing all "green" pixels with "transparent" with a tolerance of 10%. To make it convenient, I've refactored it as a
ColorChangercomponent with propertiesfrom: "green"andto: "transparent".Whilst the
VideoOutputsource is currently aMediaPlayeryou can easily substitute it forCameraand it'll behave like a Zoom meeting with background video effects:References: