Closed ThinkWD closed 2 years ago
[Code = 723438896]
Looks like an unusual error code. Are you able to run any other OpenCV cuda functions? If so can you 1) confirm that the big_buck_bunny.mp4 test video produces the same issue and, 2) if possible try running the encoding sample from the Nvidia Video Codec SDK?
Which GPU and driver version are you using?
I'm sorry to reply to your message so late.
Looks like an unusual error code.
In fact this error code is indeterminate, I got several different error codes in several attempts, such as:
[Code = -244827920]
[Code = 652536048]
[Code = 1594538224]
[Code = -1155204880]
[Code = 1572964592]
Are you able to run any other OpenCV cuda functions?
and
if possible try running the encoding sample from the Nvidia Video Codec SDK?
I'm sorry I can't verify this at the moment, maybe you can provide an example to help me verify this?
Since I'm building opencv on Ubuntu, I didn't find an example in the examples that looked right to run, and when I tried to run video_writer.cpp I got the following error:
Device 0: "NVIDIA GeForce RTX 3080" 10010Mb, sm_86, Driver/Runtime ver.11.70/11.30
Read 1 frame
Frame Size : 672x384
Open CPU Writer
Open CUDA Writer
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.6.0) /home/lx_dir/opencv/opencv-4.6.0/modules/core/include/opencv2/core/private.cuda.hpp:112: error: (-213:The function/feature is not implemented) The called functionality is disabled for current build or platform in function 'throw_no_cuda'
confirm that the big_buck_bunny.mp4 test video produces the same issue and,
Yes, I got the same error.
Which GPU and driver version are you using?
I also suspected that it might be a problem with my device, so I tried it on another device with a different GPU, but encountered the same problem.
Device 1:
Product Name: NVIDIA GeForce RTX 3080
# nvidia-smi
NVIDIA-SMI 515.65.01 Driver Version: 515.65.01 CUDA Version: 11.7
# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0
Device 2:
Product Name: NVIDIA GeForce RTX 2060
# nvidia-smi
NVIDIA-SMI 515.65.01 Driver Version: 515.65.01 CUDA Version: 11.7
# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0
And this is the cmake command I used when building opencv. Maybe there is something wrong with it?
mkdir -p build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=../../opencv \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.6.0/modules \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D WITH_NVCUVID=ON \
-D WITH_CUBLAS=ON \
-D WITH_CUFFT=ON \
-D WITH_FFMPEG=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
..
make -j$(nproc) && make install
I'm sorry I can't verify this at the moment, maybe you can provide an example to help me verify this?
I just noticed that you are using the sample code. As far as I am aware that is broken so that could be your issue.
Try replacing
cv::imshow("GPU", d_frame);
with
d_frame.download(frame);
cv::imshow("CPU", frame);
here.
The sample should display the video decoded on the cpu then the gpu, does the cpu version display correctly?
When the program runs to cv::cudacodec::createVideoReader(fname)
, it stops working and reports an error. The code after that will not be executed. So I don't think this is the problem
Good point. Have you built the tests if so does opencv_test_cudaarithm work?
If you haven't built the tests then you need to confirm that CUDA is working, a different error each time implies it could be returning an error from a previous CUDA call.
If something simple like the below
GpuMat src(100, 100, CV_8UC1);
GpuMat dst(1000, 1000, CV_8UC1);
cv::cuda::resize(src, dst, { 1000,1000 });
Mat dstHost; dst.download(dst);
works then CUDA is working and the next step would be to download and build the Nvidia samples and see if they work.
If something simple like the below works then CUDA is working
I modified and ran this example
cv::cuda::GpuMat src(cv::imread("./img.jpg"));
cv::cuda::GpuMat dst;
cv::cuda::resize(src, dst, {1000, 1000});
cv::Mat dstHost; dst.download(dstHost);
cv::imwrite("./res.jpg", dstHost);
and got the correct output.
and the next step would be to download and build the Nvidia samples and see if they work.
I tried to build Nvidia samples and ran Video_Codec_SDK_11.1.5/Samples/AppDec
with the following command:
./AppDec -i big_buck_bunny.mp4 -o ouput.mp4 -resize 800x600
I got the following output:
GPU in use: NVIDIA GeForce RTX 3080
Decode with demuxing.
[INFO ][13:15:52] Media format: QuickTime / MOV (mov,mp4,m4a,3gp,3g2,mj2)
Session Initialization Time: 3 ms
[INFO ][13:15:52] Video Input Information
Codec : MPEG-4 (ASP)
Frame rate : 24/10 = 2.4 fps
Sequence : Progressive
Coded size : [672, 384]
Display area : [0, 0, 672, 384]
Chroma : YUV 420
Bit depth : 8
Video Decoding Params:
Num Surfaces : 4
Crop : [0, 0, 672, 384]
Resize : 800x600
Deinterlace : Weave
Total frame decoded: 125
Saved in file ouput.mp4 in NV12 format
Session Deinitialization Time: 1 ms
I can't view output.mp4, but I think it's working properly
Looks to be related to https://github.com/opencv/opencv_contrib/issues/3362 and https://github.com/opencv/opencv_contrib/issues/3359.
So I should try to lower the opencv version? Also I only found example of decoding in the examples, no example of encoding and pushing streams, is there anything relevant for my reference? Thank you very much for your reply!
So I should try to lower the opencv version?
I wouldn't think that would make a difference, it looks like an error generated by the driver api but I can't recreate on my side. That said I'm using wsl with the same CUDA runtime and driver version (11.7) but I wouldn't expect that to be the issue.
Also I only found example of decoding in the examples, no example of encoding and pushing streams, is there anything relevant for my reference?
The encoding hasn't worked for a few years and if you want to push rtsp streams you probably want to use a different library to OpenCV.
Can you run bin/opencv_test_cudaarithm to see if you get the same errors as https://github.com/opencv/opencv_contrib/issues/3361?
Of course. I ran all the test programs starting with opencv_test_cuda
, where opencv_test_cudafilters
and opencv_test_cudabgsegm
did not report any errors.
The following are some of the results obtained by running (intercepting the last part)
The encoding hasn't worked for a few years and if you want to push rtsp streams you probably want to use a different library to OpenCV.
I see in the build information that FFMPEG and GStreamer are available in Video I/O, can I use them through opencv? Are there any examples or any other references about this? Thank you for your help
Just to confirm:
Which libs did you link against the stubs or the driver, you can check with
cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY
I see in the build information that FFMPEG and GStreamer are available in Video I/O, can I use them through opencv?
Usage questions should be placed on the OpenCV forum. Video writing in OpenCV is performed usign the cv::VideoWriter
api which can optionaly use FFmpeg or GStreamer behind the scenes. As far as I know the FFmpeg backend will only write to files but I would have thourght you could construct a GStreamer pipeline to push streams via ip.
I see above you built the samples for the latest version of Nvidia's Video Coding SDK, did you also use the headers from this when you built OpenCV?
Yes, I used Video_Codec_SDK_11.1.5 when I built opencv
Which libs did you link against the stubs or the driver
cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY
output
CUDA_nvcuvid_LIBRARY=/usr/local/cuda-11.3/lib64/libnvcuvid.so
I copied this library from Video_Codec_SDK_11.1.5
Usage questions should be placed on the OpenCV forum.
I will be there for help, thank you
Do you have both cuda toolkit 11.3 and 11.6 on your machine?
I'm wondering if OpenCV is trying to use the stub library at runtime, what is the output from
ldd bin/opencv_test_cudacodec | grep libnvcuvid
Do you have both cuda toolkit 11.3 and 11.6 on your machine?
No, I have two machine, one with cuda toolkit 11.3 and the other with 11.6
I'm wondering if OpenCV is trying to use the stub library at runtime, what is the output from
ldd bin/opencv_test_cudacodec | grep libnvcuvid
libnvcuvid.so.1 => /usr/local/cuda-11.3/lib64/libnvcuvid.so.1 (0x00007f88a8b72000)
What happens if you remove the stub library libnvcuvid.so
which you copied accross to /usr/local/cuda-11.3/lib64/
then generate your build files, does it pick up the driver's version of libnvcuvid?
If not can you remove the stub library from the installation directory /usr/local/cuda-11.3/lib64/
and build by passing
-DCUDA_nvcuvid_LIBRARY=Video_Codec_SDK_11.1.5/Lib/linux/stubs/x86_64/libnvcuvid.so
to cmake to see if this fixes your issue.
I remove the stub library libnvcuvid.so and rebuild, now cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY
output that:
CUDA_nvcuvid_LIBRARY=/usr/lib/x86_64-linux-gnu/libnvcuvid.so
Can you try building and see if the error remains and if
ldd bin/opencv_test_cudacodec | grep libnvcuvid
has changed.
Yes, I'm in the process of building it, it may take a while
I rebuild, now cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY
output that:
libnvcuvid.so.1 => /lib/x86_64-linux-gnu/libnvcuvid.so.1 (0x00007f2fcb831000)
But when I run bin/opencv_test_cudaarithm
I get the same error as before.
After that I tried to run video_reader.cpp without any more errors and everything seems to be fine.
But when I run
bin/opencv_test_cudaarithm
I get the same error as before.
Is it the same error, or just an error related to OPENCV_TEST_DATA_PATH not being set?
After that I tried to run video_reader.cpp without any more errors and everything seems to be fine.
Thats great, I thought it was a long shot but it seems to have paid off!
Is it the same error, or just an error related to OPENCV_TEST_DATA_PATH not being set?
It's the exact same error, but I'm not sure if it's caused by my incorrect operation and I think I should rebuild it once to verify it.
The previous multiple builds generated files scattered in multiple similarly named folders, so I deleted them all and rebuilt.
Now I can be sure that running bin/opencv_test_cudaarithm
and all the test programs starting with opencv_test_cuda will output the exact same error
So the video_reader sample is still working for you?
What is your output from
opencv_test_cudacodec --gtest_filter=CUDA_Codec/Video.Reader/0
It is it similar to
Note: Google Test filter = CUDA_Codec/Video.Reader/0 [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from CUDA_Codec/Video [ RUN ] CUDA_Codec/Video.Reader/0, where GetParam() = (NVIDIA GeForce RTX 3070 Ti Laptop GPU, "highgui/video/big_buck_bunny.mp4") unknown file: Failure C++ exception with description "OpenCV(4.6.0-dev) /home/b/repos/opencv/opencv_contrib/modules/cudacodec/src/cuvid_video_source.cpp:66: error: (-217:Gpu API call) CUDA_ERROR_FILE_NOT_FOUND [Code = 301] in function 'CuvidVideoSource' " thrown in the test body. [ FAILED ] CUDA_Codec/Video.Reader/0, where GetParam() = (NVIDIA GeForce RTX 3070 Ti Laptop GPU, "highgui/video/big_buck_bunny.mp4") (419 ms) [----------] 1 test from CUDA_Codec/Video (419 ms total)
[----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (419 ms total) [ PASSED ] 0 tests. [ FAILED ] 1 test, listed below: [ FAILED ] CUDA_Codec/Video.Reader/0, where GetParam() = (NVIDIA GeForce RTX 3070 Ti Laptop GPU, "highgui/video/big_buck_bunny.mp4")
If so you need to clone the extra repo and add
export OPENCV_TEST_DATA_PATH=extra/testdata1/
or similar before running the test.
So the video_reader sample is still working for you?
Yes, it still works.
What is your output from
opencv_test_cudacodec --gtest_filter=CUDA_Codec/Video.Reader/0
It is similar to the one you mentioned.
If so you need to clone the extra repo and add
export OPENCV_TEST_DATA_PATH=extra/testdata1/
or similar before running the test.
I don't quite understand how this is to be done and I didn't notice where the extra repo is. Also, thanks to your help, isn't the codec already working as expected?
I don't quite understand how this is to be done and I didn't notice where the extra repo is. Also, thanks to your help, isn't the codec already working as expected?
Yes, I just wanted to cofirm that the errors you are seeing from opencv_test_cudacodec
are a result of not having the input video's which are contained in OpenCV's extra repository and not a result of another internal error.
Yes, I just wanted to cofirm that the errors you are seeing from opencv_test_cudacodec are a result of not having the input video's which are contained in OpenCV's extra repository and not a result of another internal error.
yes, clone the extra repo and add export OPENCV_TEST_DATA_PATH=extra/testdata/
, opencv_test_cudacodec
now passes without any more errors.
and opencv_test_cudafeatures2d
, opencv_test_cudalegacy
, opencv_test_cudaobjdetect
, opencv_test_cudastereo
and opencv_test_cudawarping
all passed without error
Great thanks for checking that, I guess this issue can be closed then?
I rebuild, now
cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY
output that:libnvcuvid.so.1 => /lib/x86_64-linux-gnu/libnvcuvid.so.1 (0x00007f2fcb831000)
But when I run
bin/opencv_test_cudaarithm
I get the same error as before.After that I tried to run video_reader.cpp without any more errors and everything seems to be fine.
Hello there, could you explain how you built your OpenCV as I have faced a same issue? I have tried: 1- Linking /usr/lib/x86_64-linux-gnu/libnvcuvid.so directly to CUDA_nvcuvid_LIBRARY. And then, making opencv with this command: cmake -D OPENCV_EXTRA_MODULES_PATH= /opencv/opencv/contrib/modules/ -D WITH_XINE=ON -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D OPENCV_DNN_CUDA=ON -D WITH_NVCUVID=ON -D WITH_CUDNN=ON -D BUILD_DOCS=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D CUDA_nvcuvid_LIBRARY=/usr/lib/x86_64-linux-gnu/libnvcuvid.so ..
2- Making a soft link of libnvcuvid.so in /usr/lib which is linked to /usr/lib/x86_64-linux-gnu/libnvcuvid.so. And then, building opencv with this command: cmake -D OPENCV_EXTRA_MODULES_PATH= /opencv/opencv/contrib/modules/ -D WITH_XINE=ON -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D OPENCV_DNN_CUDA=ON -D WITH_NVCUVID=ON -D WITH_CUDNN=ON -D BUILD_DOCS=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D CUDA_nvcuvid_LIBRARY=/usr/lib/libnvcuvid.so ..
In the both cases, opencv_test_cudacodec is not linked to libnvcuvid. I.e, ldd bin/opencv_test_cudacodec | grep libnvcuvid does not give me anything, and accordingly I cannot execute cv::cudacodec::createVideoReader. CUDA 11.2 Ubuntu 22.04.2 LTS
Thx again.
1- Linking /usr/lib/x86_64-linux-gnu/libnvcuvid.so directly to CUDA_nvcuvid_LIBRARY. And then, making opencv with this command: cmake -D OPENCV_EXTRA_MODULES_PATH= /opencv/opencv/contrib/modules/ -D WITH_XINE=ON -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D OPENCV_DNN_CUDA=ON -D WITH_NVCUVID=ON -D WITH_CUDNN=ON -D BUILD_DOCS=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D CUDA_nvcuvid_LIBRARY=/usr/lib/x86_64-linux-gnu/libnvcuvid.so ..
If you have the Nvidia driver installed and a GPU which supports the Nvidia Video Coding SDK then I would expect /usr/lib/x86_64-linux-gnu/libnvcuvid.so
to exist and be picked up by CMake. Did /usr/lib/x86_64-linux-gnu/libnvcuvid.so
exist or did you manually create it by copying the stub library?
1- Linking /usr/lib/x86_64-linux-gnu/libnvcuvid.so directly to CUDA_nvcuvid_LIBRARY. And then, making opencv with this command: cmake -D OPENCV_EXTRA_MODULES_PATH= /opencv/opencv/contrib/modules/ -D WITH_XINE=ON -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D OPENCV_DNN_CUDA=ON -D WITH_NVCUVID=ON -D WITH_CUDNN=ON -D BUILD_DOCS=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D CUDA_nvcuvid_LIBRARY=/usr/lib/x86_64-linux-gnu/libnvcuvid.so ..
If you have the Nvidia driver installed and a GPU which supports the Nvidia Video Coding SDK then I would expect
/usr/lib/x86_64-linux-gnu/libnvcuvid.so
to exist and be picked up by CMake. Did/usr/lib/x86_64-linux-gnu/libnvcuvid.so
exist or did you manually create it by copying the stub library?
THX for the reply. The drivers are pre-installed. I have tried different versions of drivers that NVIDIA provided for my GPU. Just to be more specific, I installed driver version 450.245 with GTX 1060. (plz note that I tried newer drivers versions but the problem is not resolved). And yes, as long as I install the driver, /usr/lib/x86_64-linux-gnu/ would change based on the installed driver (I do not copy libnvcuvid manually).
The weird thing is that, as you said, CMake should pick up /usr/lib/x86_64-linux-gnu/ as search directory and it does. I recheck it by : cat CMakeVars.txt | grep CUDA_LIBS_PATH CUDA_LIBS_PATH=/usr/local/cuda/lib64;/usr/lib/x86_64-linux-gnu
inside CMakeVars.txt. There are other shared libraries picked from /usr/lib/x86_64-linux-gnu that are linked in CMakeVars.txt. But it seems it cannot pick libnvcuvid. Other thing may worth to note is that, I followed your suggestion for removing the soft links (so I removed the soft link from /usr/lib/libnvcuvid and just kept libnvcuvid.so in x86_64-linux-gnu, which is made by the driver). Then I build opencv with this cmake commad: cmake -D OPENCV_EXTRA_MODULES_PATH=/opencv/opencv/contrib/modules/ -D WITH_XINE=ON -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D OPENCV_DNN_CUDA=ON -D WITH_NVCUVID=ON -D WITH_CUDNN=ON -D BUILD_DOCS=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_OPENNI=ON -D WITH_OPENCL=ON ..
Then I check cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY =/usr/lib/libnvcuvid.so meaning that it is not picked from /usr/lib/x86_64-linux-gnu, but still the old location.
Then I check cat CMakeVars.txt | grep CUDA_nvcuvid_LIBRARY =/usr/lib/libnvcuvid.so meaning that it is not picked from /usr/lib/x86_64-linux-gnu, but still the old location.
You need to remove the stub library /usr/lib/libnvcuvid.so
and possibly clean your build directory. The stub libs should not be on a path which can be picked up at run time.
Hi I am unable to run video reader GPU Sample using cv::cudacodec::createVideoReader . My configuration is as follows Ubuntu 20.04 CUDA 11.6. Open CV build from Source.
opencv build:
This is the code I run:
I tried rtsp and video files and got the same error:
Thanks in advance!