Ask Your Question

cv::cudacodec::createVideoReader segfault

asked 2017-11-13 12:56:06 -0600


I'm trying to run an OpenCV sample code presented here: opencv-3.3.1/samples/gpu/video_reader.cpp, but always get an segmentation fault signal within cv::cudacodec::createVideoReader(fname).

The stack trace is:

 1 cv::cudacodec::detail::CuvidVideoSource::CuvidVideoSource(cv::String const&) 
 2 cv::cudacodec::createVideoReader(cv::String const&) 
 3 main

Further debugging told me that memory access violation occurs at this line of code in opencv-3.3.1/modules/cudacodec/src/cuvid_video_cource.cpp:

CUresult cuRes = cuvidCreateVideoSource(&videoSource_, fname.c_str(), &params);

And seems like it calls an invalid address. Disasm also shows memory access violation at callq command.

Cuda video SDK samples shows that there's a robust dynamic linking presents. Do I need some extra dynamic linking while using OpenCV? Or maybe I do something wrong?

Running ./opencv_test_cudacodec also ends up with segfault.

What is being linked when I compile the sample:

g++ -Wl,--trace,--rpath,/usr/local/lib,--rpath,/usr/local/cuda/lib64 -Wl,-rpath,/home/den/Qt/5.7/gcc_64/lib -o opencv_cuda_test main.o   -lopencv_core -lopencv_cudacodec -lopencv_videoio -lopencv_highgui -lnvcuvid -L/usr/local/cuda/lib64 -L/home/den/Qt/5.7/gcc_64/lib -lQt5Core -lpthread


  • Ubuntu 16.04;
  • GeForce GTX 960;
  • Driver Version: 384.90;
  • CUDA 9.0
  • opencv-3.3.1 (tried both release version and latest 'master' branch)
  • This is a configuration of OpenCV:
    -- General configuration for OpenCV 3.3.1-dev =====================================
    --   Version control:               3.3.1-144-gba940de
    --   Platform:
    --     Timestamp:                   2017-11-13T17:54:56Z
    --     Host:                        Linux 4.4.0-98-generic x86_64
    --     CMake:                       3.5.1
    --     CMake generator:             Unix Makefiles
    --     CMake build tool:            /usr/bin/make
    --     Configuration:               RELEASE
    --   CPU/HW features:
    --     Baseline:                    SSE SSE2 SSE3
    --       requested:                 SSE3
    --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
    --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2
    --       SSE4_1 (3 files):          + SSSE3 SSE4_1
    --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
    --       FP16 (2 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
    --       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
    --       AVX2 (9 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
    --   C/C++:
    --     Built as dynamic libs?:      YES
    --     C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
    --     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    --     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    --     C Compiler:                  /usr/bin/cc
    --     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    --     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long ...
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2017-11-13 18:42:25 -0600

liyiwei gravatar image

I have seen similar problem with CUDA 9.0. Switching back to CUDA 8.0 works for me.

edit flag offensive delete link more

answered 2017-11-22 08:31:24 -0600

I've resolved this problem.

The fact is file /usr/local/cuda-9.0/targets/x86_64-linux/include/dynlink_cuviddec.h contains code which requires additional symbol loading (which you can faound either in /usr/local/cuda-9.0/samples/3_Imaging/cudaDecodeGL/dynlink_nvcuvid.cpp or in the Video Codec SDK samples here: Video_Codec_SDK_8.0.14/Samples/common/src/

So, if you want to compile OpenCV sample decoder, you must compile dynlink_nvcuvid.cpp with your project while including files dynlink_cuviddec.h and dynlink_nvcuvid.h from Video Codec SDK

Also, don't forget to init API functions:

    void* hHandleDriver = 0;
    CUresult res = cuInit(0, __CUDA_API_VERSION, hHandleDriver);
    if (res != CUDA_SUCCESS) {
        throw exception();
    res = cuvidInit(0);
    if (res != CUDA_SUCCESS) {
        throw exception();
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-11-13 12:56:06 -0600

Seen: 48 times

Last updated: 2 days ago