Enable cudacodec::VideoReader

asked 2018-04-03 13:48:38 -0600

Damien45 gravatar image

updated 2018-04-04 03:35:19 -0600

EDIT : Thanks to comments, I have been able to go further :

The error is raised here : https://github.com/opencv/opencv/blob..., because the flag HAVE_NVCUVID isn't defined.

This flag is defined here if CUDA_nvcuvid_LIBRARY is defined

And this variable seems to be user-defined, according to this But the doc says that this is only usefull for Windows ; so I think that I miss something. I try to build with WITH_NVCUVID that I wasn't using before because it is needed.

Whatever, In the cudareader source code, I see that the FFMPEG backend is used only if the cudacodec (CuvidVideoSource) doesn't work : https://github.com/opencv/opencv/blob...

But this code is invoked only if OpenCV is built with WITH_NVCUVID. And I think that if somebody choose to use a cuda-enabled FFMPEG backend, it is not necessary to build OpenCV with NVCUVID as FFMPEG will do the job. Am I wrong ? If I'm right, maybe I can propose a patch to try to use FFMPEG backend instead of throw_no_cuda() if HAVE_NVCUVID is not defined. Would it be useful ?

ORIGINAL post : Good morning,

I try to use the cuda VideoReader to read a mkv/h264 file. I see in the doc that this reader uses FFMPEG.

I'm able to read it using non-cuda VideoCapture, even using FFMPEG as the backend :

cap->open("file.mkv", CAP_FFMPEG);

I try to read it using CUDA :

cudacodec::createVideoReader("file.mkv")

I get this exception :

OpenCV(3.4.1) Error: The function/feature is not implemented (The called functionality is disabled for current build or platform) in throw_no_cuda, file /home/damien/code/lib/opencv-3.4.1/opencv-3.4.1/modules/core/include/opencv2/core/private.cuda.hpp, line 111
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.1) /home/damien/code/lib/opencv-3.4.1/opencv-3.4.1/modules/core/include/opencv2/core/private.cuda.hpp:111: error: (-213) The called functionality is disabled for current build or platform in function throw_no_cuda

N.B. : I use other cuda functions without problems.

So I read here or elsewhere that the latests versions of FFMPEG can use the Nvidia nvdec/nvenc with CUDA 9.1 toolkit (the one I use). Then, I decided to build it from sources (FFMPEG 3.4 from git https://git.ffmpeg.org/gitweb/ffmpeg....) using this configure :

./configure --enable-cuda --enable-nvenc --enable-cuvid --enable-nonfree --extra-cflags="-I/usr/local/cuda/include -I/home/damien/code/lib/Video_Codec_SDK_8.1.24/Samples/NvCodec/NvEncoder" --extra-ldflags=-L/usr/local/cuda/lib64 --enable-shared --disable-static

It compiles well and I can use ffmpeg :

$ ffmpeg
ffmpeg version n3.4.2-6-g1b9b469 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --enable-cuda --enable-nvenc --enable-cuvid --enable-nonfree --extra-cflags='-I/usr/local/cuda/include -I/home/damien/code/lib/Video_Codec_SDK_8.1.24/Samples/NvCodec/NvEncoder' --extra-ldflags=-L/usr/local/cuda/lib64 --enable-shared --disable-static
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100 ...
(more)
edit retag flag offensive close merge delete

Comments

This comment is for windows may be it can be usefull for linux In cmakelist it's here : you will need nvcuvid and nvcuvenc. Check in cmakecache CUDA_nvcuvid variable and CUDA_nvcuvenc

You must check WITH_NVCUVID

macro cuda_find_library_local_first search for lib nvcuvid and nvcuvenc

PS NVIDIA GPU arch: 30 35 37 50 52 60 61 70 you need all architecture?

LBerger gravatar imageLBerger ( 2018-04-03 14:40:05 -0600 )edit
1

Thank you, it helps me to go further (see EDIT on the question)

Damien45 gravatar imageDamien45 ( 2018-04-04 03:36:20 -0600 )edit

Did not work with WITH_NVCUVID. Always the same error message.

Damien45 gravatar imageDamien45 ( 2018-04-04 05:46:04 -0600 )edit

I think that it is a bug, so I created an issue : https://github.com/opencv/opencv/issu...

Damien45 gravatar imageDamien45 ( 2018-04-04 06:47:46 -0600 )edit

Hi @Damien45, did you perhaps manage to solve this? I'm stuck at the same exact point

Alocin gravatar imageAlocin ( 2019-07-03 09:21:07 -0600 )edit