Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cuda 10.0 fatal error: dynlink_nvcuvid.h: No such file or directory #1786

Closed
achalshah20 opened this issue Sep 20, 2018 · 15 comments · Fixed by #1946
Closed

Cuda 10.0 fatal error: dynlink_nvcuvid.h: No such file or directory #1786

achalshah20 opened this issue Sep 20, 2018 · 15 comments · Fixed by #1946

Comments

@achalshah20
Copy link

@achalshah20 achalshah20 commented Sep 20, 2018

System information (version)
  • OpenCV => Master branch
  • Operating System / Platform => Linux 18.04
  • Compiler => GCC 7.3
Detailed description

Trying to compile opencv and getting this error

In file included from /home/achal/achal/tools/opencv/build/modules/cudacodec/opencv_cudacodec_pch_dephelp.cxx:1:0:
/home/achal/achal/tools/opencv_contrib/modules/cudacodec/src/precomp.hpp:60:18: fatal error: dynlink_nvcuvid.h: No such file or directory
         #include <dynlink_nvcuvid.h>
                  ^~~~~~~~~~~~~~~~~~~
compilation terminated.
modules/cudacodec/CMakeFiles/opencv_cudacodec_pch_dephelp.dir/build.make:62: recipe for target 'modules/cudacodec/CMakeFiles/opencv_cudacodec_pch_dephelp.dir/opencv_cudacodec_pch_dephelp.cxx.o' failed

I checked the include directory of cuda 10, there is not dynlink_nvcuvid.h or nvcuvid.h. So may be they moved this code to somewhere.

Steps to reproduce
mkdir build  

cd build  

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DCUDA_ARCH_BIN="3.0 3.5 3.7 5.0 5.2 6.0 6.1" -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DWITH_CUDA=ON -DWITH_OPENCL=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_OPENCLAMDFFT=OFF -DCUDA_NVCC_FLAGS="--expt-relaxed-constexpr" -DOPENCV_ENABLE_NONFREE=ON -DBUILD_opencv_cnn_3dobj=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_dnn_modern=OFF -DBUILD_opencv_cudacodec=ON -DWITH_GTK_2_X=ON ..  

make -j

@alalek

This comment has been minimized.

Copy link
Contributor

@alalek alalek commented Sep 21, 2018

Try cmake -DBUILD_opencv_cudacodec=OFF ....
It is tested with CUDA <= 6.5 only.
After that CUDA API is changed for decoding/encoding - updates are not supported yet.

Also try to disable precopmiled headers (it is buggy in some configurations):

cmake -DENABLE_PRECOMPILED_HEADERS=OFF ...

(but this can't help if file is missing)

@achalshah20

This comment has been minimized.

Copy link
Author

@achalshah20 achalshah20 commented Sep 21, 2018

Seems like cuda video decoder is deprecated.

https://docs.nvidia.com/cuda/video-decoder/index.html

That's why -DBUILD_opencv_cudacodec=OFF fixes the issue. Thanks @alalek !

@kooscode

This comment has been minimized.

Copy link

@kooscode kooscode commented Nov 22, 2018

this really sucks.. because if you read from video cameras via videocapture.read, the yuy2rgb conversion is no longer done via gpu and it drops 1080p framerates from over 30fps down to 5fps... :(

@alealv

This comment has been minimized.

Copy link

@alealv alealv commented Dec 27, 2018

Regarding this issue. When compiling with the option WITH_NVCUVID I get:

fatal error: nvcuvid.h: No such file or directory
         #include <nvcuvid.h>
                  ^~~~~~~~~~~

I found out that the NVIDIA Video Decoder (NVCUVID) is deprecated since CUDA 10. One should get the NVIDIA VIDEO CODEC SDK, which is default installed on /opt/nvidia-video-codec.

So it's needed to modify the FindCUDA.cmake, OpenCVDetectCUDA.cmake or add a new file to find the module and include the path /opt/nvidia-video-codec/include as:
/usr/bin/c++ ... -isystem /opt/nvidia-video-codec/include ...

The quickest solution is to add the following flag
-DCMAKE_CXX_FLAGS=-isystem\ /opt/nvidia-video-codec/include

Although, I've also found that the FindCUDA module has been superseded by first-class support for the CUDA language in CMake

@kooscode

This comment has been minimized.

Copy link

@kooscode kooscode commented Dec 27, 2018

doesnt work.. I downloaded the codec sdk

I then I actually copied the cuviddec.h and nvcuvid.h files into /usr/local/cuda/include/ and renamed nvcuvid.h to dynlink_nvcuvid.h

recompiled opencv 3.4.3 with -D BUILD_opencv_cudacodec=ON

still same problem with video feeds decoding via CPU with 5fps...

When I use OpenCV 3.2 it works 30+ fps as expected...

@alealv

This comment has been minimized.

Copy link

@alealv alealv commented Dec 27, 2018

Be careful, because the solution that I posted is for:

OpenCV ==> master branch
CUDA ==> v10.0 (the older version of CUDA still contains the video decoder)

The option that should be activated is:
cmake -DWITH_NVCUVID=ON -DBUILD_opencv_cudacodec=ON ..

Hope it helps!

@kooscode

This comment has been minimized.

Copy link

@kooscode kooscode commented Dec 28, 2018

This does NOT work...

it still takes 200ms for cv::VideoCapture::read(Mat) to read from USB3 camera.. i.e. 5 frames per second..

OpenCV 3.2 reads video over 60 frames per second...

I am compiled and linked against:

 GNU-Linux$ ldd videothreading | grep opencv
 	libopencv_core.so.4.0 => /usr/local/lib/libopencv_core.so.4.0 (0x00007f696ce63000)
 	libopencv_highgui.so.4.0 => /usr/local/lib/libopencv_highgui.so.4.0 (0x00007f696cc1e000)
 	libopencv_imgcodecs.so.4.0 => /usr/local/lib/libopencv_imgcodecs.so.4.0 (0x00007f696c22c000)
 	libopencv_imgproc.so.4.0 => /usr/local/lib/libopencv_imgproc.so.4.0 (0x00007f696ab0b000)
 	libopencv_videoio.so.4.0 => /usr/local/lib/libopencv_videoio.so.4.0 (0x00007f696a8b0000)

And OpenCV 4.0.1 compiled with Cuda 10.- with these options:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=OFF \
      -D INSTALL_PYTHON_EXAMPLES=OFF \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D WITH_GSTREAMER=ON \
      -D WITH_CUDA=ON \
      -D WITH_NVCUVID=ON \
      -D ENABLE_FAST_MATH=1 \
      -D CUDA_FAST_MATH=1 \
      -D WITH_CUBLAS=ON \
      -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
      -D BUILD_opencv_cudacodec=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=OFF ..

Here is my CUDA version:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

Result after building OpenCV:

--   NVIDIA CUDA:                   YES (ver 10.0, CUFFT CUBLAS NVCUVID FAST_MATH)
--     NVIDIA GPU arch:             30 35 37 50 52 60 61 70 75

Final OpenCV version built..

$ opencv_version 
4.0.1

@alalek

This comment has been minimized.

Copy link
Contributor

@alalek alalek commented Dec 28, 2018

cv::VideoCapture doesn't use CUDA. You should try separate CUDA-related API.

@kooscode

This comment has been minimized.

Copy link

@kooscode kooscode commented Dec 28, 2018

So why does OpenCV 3.2 work at 60fps and OpenCV 4.0.1 only get max 5fps ??

EDIT - I think there is something else afoot.. this webcam supports h264 1080p at 30fps, but i cant seem to get more than 5fps, no matter wat i use.. only the opencv 3.2 build i tried seemed to work..

even native v4l ioctl captures doesnt work... weird!!!

@alalek

This comment has been minimized.

Copy link
Contributor

@alalek alalek commented Dec 28, 2018

  1. GStreamer backend is used. Was V4L2 backend.

  2. Higher resolution is used. Was 640x480.

  3. MJPEG mode for V4L should be enabled explicitly: opencv/opencv#9479 (comment)
    It may help with USB2.0 cameras.

  4. Why we are discussing this in CUDA build issue?

Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org

@kooscode

This comment has been minimized.

Copy link

@kooscode kooscode commented Dec 28, 2018

  1. I tried GStreamer with OpenCV 3.4.3, but still getting 5fps..

  2. I used to get 30fps using OpenCV 3.2.x at 1080p (sounds like it was v4l)

  3. Thanks, I'll have a look to see if MJPG can be used as per comment.

  4. Because this seemed to be a nvcuvid codec issue.. i.e. its bypassing the CUDA codec and using CPU.. I could have been wrong, but thats the only thing that changed in building Opencv since the build broke wihtout "-DBUILD_opencv_cudacodec=OFF" but then I got 5fps when not using cudacodec..

FYI - I have full 30fps now working via v4l2 and using V4L2_PIX_FMT_MJPEG going straight ioctl with /dev/video0 access.. I will see if I can get it going through opencv..

@hz658832

This comment has been minimized.

Copy link

@hz658832 hz658832 commented Apr 9, 2019

Hey guys,
I also ran into this problem, this is because of the deprecation for NVCUVID. Instead, NVIDIA provides Video Codec SDK. if you are going to use cuda 10 with opencv 3.4.x, then you need to copy the header and libs from Video Codec SDK into cuda AND change the related opencv header to use nvcuvid.h BUT NOT dynlink_nvcuvid.h.
Then you get compling done, but if it can work well, I am not sure.

Cheers.

HZ

@quanticsolutions

This comment has been minimized.

Copy link

@quanticsolutions quanticsolutions commented Sep 9, 2019

Hey guys,
I also ran into this problem, this is because of the deprecation for NVCUVID. Instead, NVIDIA provides Video Codec SDK. if you are going to use cuda 10 with opencv 3.4.x, then you need to copy the header and libs from Video Codec SDK into cuda AND change the related opencv header to use nvcuvid.h BUT NOT dynlink_nvcuvid.h.
Then you get compling done, but if it can work well, I am not sure.

Cheers.

HZ

Grettings, how can I do this?

@hz658832

This comment has been minimized.

Copy link

@hz658832 hz658832 commented Sep 10, 2019

@quanticsolutions : there are two ways to overcome this problem.

  1. just don't compile opencv_cudacodec, you could disable it via cmake gui or ccmake
  2. As above, install the nvidia Video Codec SDK and try to have a look into the opencv_contrib git repo, in the master branch, in modules/cudacodec, they have already fixed the bug, so a patch is not necessary anymore. Gernerally specking, you need sth like this
    #if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
    #include <dynlink_nvcuvid.h>
    #else
    #include <nvcuvid.h>
    #endif
@Zacrain

This comment has been minimized.

Copy link

@Zacrain Zacrain commented Nov 19, 2019

@quanticsolutions : there are two ways to overcome this problem.

1. just don't compile opencv_cudacodec, you could disable it via cmake gui or ccmake

2. As above, install the nvidia Video Codec SDK and try to have a look into the opencv_contrib git repo, in the master branch, in modules/cudacodec, they have already fixed the bug, so a patch is not necessary anymore. Gernerally specking, you need sth like this
   #if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
   #include <dynlink_nvcuvid.h>
   #else
   #include <nvcuvid.h>
   #endif

Thank you!
Worked for me using CUDA 10.1 and OpenCV 3.4.8. I had to modify these files:

./opencv/modules/cudacodec/src/cuvid_video_source.hpp
./opencv/modules/cudacodec/src/video_decoder.hpp
./opencv/modules/cudacodec/src/frame_queue.hpp
./opencv/modules/cudacodec/src/video_parser.hpp
./opencv/modules/cudacodec/src/precomp.hpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
7 participants
You can’t perform that action at this time.