Unable to use CUDA decoder

I am working on a desktop PC running Linux Mint 21.3, with the proprietary NVIDIA drivers (v545) installed from the Driver Manager. I have built OpenCV (v4.9.0) with CUDA (v12.3.2) support, using the -D WITH_NVCUVID=ON and -D CUDA_nvcuvid_LIBRARY=path/Video_Codec_SDK_12.0.16/Lib/linux/stubs/x86_64/libnvcuvid.so flags. The build process completes without any errors.

When I try to test the CUDA decoder using the following lines of Python code:

import cv2
cap = cv2.cudacodec.createVideoReader('video.mkv')

I get the following error message:

error: OpenCV(4.9.0) /home/<user>/build/opencv_contrib/modules/cudacodec/src/video_parser.cpp:63: error: (-217:Gpu API call) Unknown error code [Code = -1122707968] in function 'VideoParser'

I looked at a few issues raised on Github about similar issues and found these:

Following the suggestions there, I tried running the following command:

ldd /home/<user>/build/opencv/build/bin/opencv_test_cudacodec | grep libnvcuvid

and got the following result, which seems okay:

libnvcuvid.so.1 => /lib/x86_64-linux-gnu/libnvcuvid.so.1 (0x0000760f1d600000)

When I run the actual test using the following command:


however, all the tests fail.

Any assistance on getting the CUDA decoder working would be much appreciated.


Which version of the Video Codec SDK are you using?

That error usually imples a mismatch between the library that you linked against when you built and the one you are using at runtime. Its possible that you linked against the stub which requires a newer version of the driver than you have installed.

@cudawarped - Thanks a lot for your response.

You’re right there. I did link against the stub when building OpenCV. The version of the Video Codec SDK I used was 12.0.16. The version of the driver I have installed is 545. Wasn’t sure where to check whether or not they are compatible.

For what it’s worth, I tried rebuilding OpenCV with the -D CUDA_nvcuvid_LIBRARY=/lib/x86_64-linux-gnu/libnvcuvid.so flag instead, to check if it resolves the issue, but it did not. I still get the same error message when I run my simple Python script, and all the cudacodec tests still fail.

I would expect both to work.

Its a long shot but are you sure you didn’t accidently overwrite /lib/x86_64-linux-gnu/libnvcuvid.so with the stub library, or copy the stub into the CUDA toolkit directory (this shouldn’t matter as ldd reports the correct path).

Additionally can you check which library you linked against

cat build/opencv/CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY

Note: You “should” be able to build without specifying -D CUDA_nvcuvid_LIBRARY with CMake picking up /lib/x86_64-linux-gnu/libnvcuvid.so.1 automatically.

Yup, confident I didn’t overwrite /lib/x86_64-linux-gnu/libnvcuvid.so. I just checked again to confirm:

% ls -l /lib/x86_64-linux-gnu/libnvcuvid* 
lrwxrwxrwx 1 root root   15 Jan  9 04:06 /lib/x86_64-linux-gnu/libnvcuvid.so -> libnvcuvid.so.1
lrwxrwxrwx 1 root root   23 Jan  9 04:06 /lib/x86_64-linux-gnu/libnvcuvid.so.1 -> libnvcuvid.so.545.29.06
-rw-r--r-- 1 root root 3528 Apr  1 00:01 /lib/x86_64-linux-gnu/libnvcuvid.so.545.29.06

Looks like /lib/x86_64-linux-gnu/libnvcuvid.so and /lib/x86_64-linux-gnu/libnvcuvid.so.1 are linked to /lib/x86_64-linux-gnu/libnvcuvid.so.545.29.06 as expected.

And no, I didn’t copy the stubs into the CUDA toolkit directory in /usr/local either.

And here’s what you asked for:

% cat ~/build/opencv/build/CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY 

And I acknowledge your note about CMake being able to automatically pick up the location of libnvcuvid.so.1. I guess I got a bit paranoid about it after the series of attempts at building OpenCV to get the CUDA decoder to work.


The library looks a little small to me. I need to check my linux distro later but in wsl libnvcuvid.so is 12MB

ls -lh /usr/lib/wsl/lib/libnvcuvid.so.1
-r-xr-xr-x 1 root root 12M Feb 15 18:42 /usr/lib/wsl/lib/libnvcuvid.so.1

Which GPU are you using?

Oh yes, never noticed that. 3.5kB does seem a bit small. Will try reinstalling the driver to see if that works. I have a GTX 1070 graphics card.

Oh yeah! @cudawarped - You are awesome! Looks like it was a driver issue after all. Downgraded to driver version 535 (marked as “recommended” by the Linux Mint Driver Manager) and the size of /lib/x86_64-linux-gnu/libnvcuvid.so.535.161.07 is now 9.3 MB. Rebuilt OpenCV and CUDA decoding works like a charm!

Thanks so much for your assistance with this. Really appreciate it!

1 Like