# Choose FFmpec decoder

**URL:** <https://forum.opencv.org/t/choose-ffmpec-decoder/8358>\
**Category:** C++\
**Tags:** ffmpeg, videoio\
**Created:** [April 10, 2022, 10:38pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358 "2022-04-10T22:38:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheEnigmist](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@TheEnigmist](https://forum.opencv.org/u/TheEnigmist)\
**Post date:** [April 10, 2022, 10:38pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/1 "2022-04-10T22:38:33Z")

</div>

Is there a way to choose what codec use when creating VideoCapture(…, cv::CAP\_FFMPEG)?  
I want to use libvpx-vp9 and be sure my video load correctly.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [April 11, 2022, 12:19pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/2 "2022-04-11T12:19:52Z")

</div>

so you have a video file. the video file has a specific container format and video encoding.

ffmpeg will decide what codec to use for decoding that video.

usually, there is exactly one codec that can decode the video.

why do you want to control this?

---

<div class="post-metadata">

**Author:** ![TheEnigmist](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@TheEnigmist](https://forum.opencv.org/u/TheEnigmist)\
**Post date:** [April 11, 2022, 9:29pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/3 "2022-04-11T21:29:24Z")

</div>

So there is some problem either with opencv or ffmpeg.  
I created a .webm video with alpha channel, but it load without alpha channel.  
OpenCV gives always 3 channel instead of 4 (bgr+a).  
But I’m reading online OpenCV doesn’t manage alpha channel at all

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [April 11, 2022, 9:50pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/4 "2022-04-11T21:50:37Z")

</div>

try using `CAP_PROP_CONVERT_RGB`

[https://docs.opencv.org/3.4/d4/d15/group\_\_videoio\_\_flags\_\_base.html#ggaeb8dd9c89c10a5c63c139bf7c4f5704dad0bb457c76e2b01024ecb3a85e75af29](https://docs.opencv.org/3.4/d4/d15/group __videoio__ flags__base.html#ggaeb8dd9c89c10a5c63c139bf7c4f5704dad0bb457c76e2b01024ecb3a85e75af29)

OpenCV doesn’t _understand_ the _special_ meaning of alpha channels (in calculations) but it can read and write them… at least as images. I haven’t personally done any specific color space stuff with VideoCapture/VideoWriter.

---

<div class="post-metadata">

**Author:** ![TheEnigmist](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@TheEnigmist](https://forum.opencv.org/u/TheEnigmist)\
**Post date:** [April 11, 2022, 9:55pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/5 "2022-04-11T21:55:11Z")

</div>

Already tried it without any success.

```auto
capture.set(cv::CAP_PROP_CONVERT_RGB, false);

```

Indeed I don’t have any problem loading a .png file with transparency, thought it was so easy for video too. How do other tools show properly my test video? (Obs, some HTML5 webapp, etc)

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [April 12, 2022, 9:08am UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/6 "2022-04-12T09:08:32Z")

</div>

> [@TheEnigmist](#):
>
> So there is some problem either with opencv or ffmpeg.

As stated in your other post

> [@Open Video file (.gif/.mov/.webm) with alpha channel](https://forum.opencv.org/t/open-video-file-gif-mov-webm-with-alpha-channel/8347):
>
> I’m trying to open a video file (.gif / .webm) with alpha channel on it, but always it gives me 3 channels and it displays with a solid background in Qt6. If I open a normal image .png with alpha channel it works correctly. What I’ve done so far is: VideoCapture capture; capture.open(filename, cv::CAP\_FFMPEG); capture.set(cv::CAP\_PROP\_CONVERT\_RGB, false); //to force loading alpha channel frameRate = capture.get(cv::CAP\_PROP\_FPS); capture.get(cv::CAP\_PROP\_CONVERT\_RGB); // gives 0 //in a thread …

the OpenCV FFMpeg backend does not support an alpha channel

> <https://github.com/opencv/opencv/blob/9aa647068b2eba4a34462927b1878353dfd3df69/modules/videoio/src/cap_ffmpeg_impl.hpp#L1598>

Additonaly `CAP_PROP_CONVERT_RGB` doesn’t have any effect in FFMpeg and if it did I assume it would be to convert from BGR to RGB but I may be wrong.

Out of interest why do you need an alpha channel?

---

<div class="post-metadata">

**Author:** ![TheEnigmist](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@TheEnigmist](https://forum.opencv.org/u/TheEnigmist)\
**Post date:** [April 12, 2022, 2:31pm UTC](https://forum.opencv.org/t/choose-ffmpec-decoder/8358/7 "2022-04-12T14:31:35Z")

</div>

Since I want to display some video with transparency on my project as an overlay (they are YUVA format). Since this videos are made with an alpha channel on it (YUVA format) I want to display them without doing any preprocess like masking pixel etc.  
But I can’t. So basically I’ve 3 solutions:

1. Create a chroma key feature with opencv and doing so I need to resync video+audio;
2. Build custom opencv with forcing AV\_FMT with alpha channel in videoio;
3. Use FFmpeg directly on my project and get rid of opencv.
