# Opencv hardware acceleration not working

**URL:** <https://forum.opencv.org/t/opencv-hardware-acceleration-not-working/8223>\
**Category:** Uncategorized\
**Tags:** ffmpeg, cuda, videoio\
**Created:** [April 1, 2022, 3:31pm UTC](https://forum.opencv.org/t/opencv-hardware-acceleration-not-working/8223 "2022-04-01T15:31:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chun\_Leong\_Lee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/chun_leong_lee/32/4899_2.png) [@Chun\_Leong\_Lee](https://forum.opencv.org/u/Chun_Leong_Lee)\
**Post date:** [April 1, 2022, 3:31pm UTC](https://forum.opencv.org/t/opencv-hardware-acceleration-not-working/8223/1 "2022-04-01T15:31:47Z")

</div>

Hi

i had the following config in a python file which is run in a docker container  
os.environ[“OPENCV\_FFMPEG\_CAPTURE\_OPTIONS”] = “hwaccel;qsv|vsync;0”  
os.environ[“OPENCV\_FFMPEG\_CAPTURE\_OPTIONS”] = “video\_codec”

cap = cv2.VideoCapture(“testvideo.mp4”, cv2.CAP\_FFMPEG,(cv2.CAP\_PROP\_HW\_ACCELERATION, cv2.VIDEO\_ACCELERATION\_ANY))

and have rebuilt my opencv to 4.5.4 with cuda being turn on and validate with opencv check if gpu available However when it run the code, the nvdec is consistently showing 0. any advise ? thanks

However, my issue that when i checked the

---

<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 1, 2022, 3:47pm UTC](https://forum.opencv.org/t/opencv-hardware-acceleration-not-working/8223/2 "2022-04-01T15:47:19Z")

</div>

Hi, I would read the following post to see if it helps

> [@Trouble using NVDIA hardware decoder when streaming from Camera](https://forum.opencv.org/t/trouble-using-nvdia-hardware-decoder-when-streaming-from-camera/7908/13):
>
> I was refering to the source of information, sorry for the confusion. The point is cv::cudacodec::VideoReader() should work on all versions of CUDA any information to the contrary may be for specific circumstances which I would be interested to investigate if you have a link to the information? Anyway this thread is getting confusing, I have just performed some tests on my build of 4.5.5 to confirm everything is working as it should, and it appears to be. I will try to compress the relevent …

If you don’t have time and you are on windows, then opening your stream with

```auto
cap = cv.VideoCapture(SRC_PATH, cv.CAP_FFMPEG, [cv.CAP_PROP_HW_ACCELERATION, cv.VIDEO_ACCELERATION_D3D11]);

```

should enable Nvidia hardware decoding.

The environmental variables you were setting look wrong to me, but I don’t have time to test them to be 100% sure.

> [@Chun\_Leong\_Lee](#):
>
> os.environ[“OPENCV\_FFMPEG\_CAPTURE\_OPTIONS”] = “hwaccel;qsv|vsync;0”

Would enable quicksync if it worked which is not what you want.

> [@Chun\_Leong\_Lee](#):
>
> os.environ[“OPENCV\_FFMPEG\_CAPTURE\_OPTIONS”] = “video\_codec”

This as far as I know wouldn’t do anything as you haven’t specified the video codec.
