Debian 11 install opencv with cuda

Hello, i’m trying to install opencv with cuda, but i keep getting errors. What i’m doing wrong ?

$ uname -a ; cat /etc/issue
Linux TEST 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.38-1 (2023-07-14) x86_64 GNU/Linux
Debian GNU/Linux 12 \n \l

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
$ lspci -v | grep VGA
01:00.0 VGA compatible controller: NVIDIA Corporation AD103 [GeForce RTX 4080] (rev a1) (prog-if 00 [VGA controller])

$ nvidia-smi
Mon Jul 31 05:12:31 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.125.06   Driver Version: 525.125.06   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| 30%   30C    P8    13W / 320W |    155MiB / 16376MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      3422      G   /usr/lib/xorg/Xorg                123MiB |
|    0   N/A  N/A      3589      G   /usr/bin/gnome-shell               12MiB |
|    0   N/A  N/A     32051      G   ...b/firefox-esr/firefox-esr       13MiB |
+-----------------------------------------------------------------------------+
~/opencv/build$ cmake \
      -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_PYTHON_EXAMPLES=OFF \
      -D INSTALL_C_EXAMPLES=OFF \
      -D OPENCV_ENABLE_NONFREE=ON \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
      -D PYTHON_EXECUTABLE=/home/dani/andrei_rec/andrei/bin/python \
      -D BUILD_EXAMPLES=ON \
      -D WITH_CUDA=ON \
      -D WITH_CUDNN=ON \
      -D OPENCV_DNN_CUDA=ON \
      -D WITH_CUBLAS=ON \
          -D WITH_FFMPEG=OFF \
      -D CUDA_TOOLKIT_ROOT_DIR=/usr/lib/cuda \
      -D OpenCL_LIBRARY=/usr/lib/x86_64-linux-gnu/libOpenCL.so \
      -D OpenCL_INCLUDE_DIR=/usr/lib/cuda/include/ \
      ..


log here: -- The CXX compiler identification is GNU 12.2.0-- The C compiler identificati - Pastebin.com

Either downgrade your version of CMake to 3.26 or set the new CMP0146 policy flag to old inside CMakeLists.txt, e.g.

if(POLICY CMP0146)
  cmake_policy(SET CMP0146 OLD)
endif()

for details see

TY cudawarped it worked.
Now i got a new error … :slight_smile:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-11 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=ON -D WITH_CUDNN=OFF -D OPENCV_DNN_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_ARCH_BIN=7.5 -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D HAVE_opencv_python3=ON -D PYTHON_EXECUTABLE=/home/dani/andrei_rec/andrei/bin/python -D BUILD_EXAMPLES=ON …

--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv hdf java js matlab ovis python2 sfm viz
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         YES
--
--   GUI:
--     GTK+:                        YES (ver 3.24.37)
--       GThread :                  YES (ver 2.74.6)
--       GtkGlExt:                  NO
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.13)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 62)
--     WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.39)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.5.0)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      YES (2.2.6)
--     FFMPEG:                      YES
--       avcodec:                   YES (59.37.100)
--       avformat:                  YES (59.27.100)
--       avutil:                    YES (57.28.100)
--       swscale:                   YES (6.7.100)
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2019.0.0 Gold [2019.0.0]
--            at:                   /home/dani/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2019.0.0)
--               at:                /home/dani/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   YES (ver 11.8, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             75
--     NVIDIA PTX archs:
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/dani/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 /home/dani/andrei_rec/andrei/bin/python3 (ver 3.11.2)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.11.so (ver 3.11.2)
--     numpy:                       /home/dani/andrei_rec/andrei/lib/python3.11/site-packages/numpy/core/include (ver 1.24.3)
--     install path:                lib/python3.11/site-packages/cv2/python-3.11
--
--   Python (for build):            /home/dani/andrei_rec/andrei/bin/python3
--
--   Java:
--     ant:                         NO
--     JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done (8.8s)
-- Generating done (0.8s)
-- Build files have been written to: /home/dani/opencv/build

full log here: $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-11 -D CMAKE - Pastebin.com

make -j $(nproc)


      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1838:72: note: in expansion of macro ‘CV_CODEC’
 1838 |     if (c->codec_id == CV_CODEC(CODEC_ID_MPEG1VIDEO) || c->codec_id == CV_CODEC(CODEC_ID_MSMPEG4V3)){
      |                                                                        ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:81:26: error: ‘CODEC_ID_H264’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H264’?
   81 | #define AV_CODEC_ID_H264 CODEC_ID_H264
      |                          ^~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1851:24: note: in expansion of macro ‘AV_CODEC_ID_H264’
 1851 |     if (c->codec_id == AV_CODEC_ID_H264) {
      |                        ^~~~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1898:36: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1898 |     AVCodecContext * c = video_st->codec;
      |                                    ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1929:15: error: ‘avcodec_encode_video2’ was not declared in this scope; did you mean ‘avcodec_encode_subtitle’?
 1929 |         ret = avcodec_encode_video2(c, &pkt, picture, &got_output);
      |               ^~~~~~~~~~~~~~~~~~~~~
      |               avcodec_encode_subtitle
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::writeFrame(const unsigned char*, int, int, int, int, int)’:
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1994:35: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1994 |     AVCodecContext *c = video_st->codec;
      |                                   ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2112:19: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 2112 |     if( video_st->codec->pix_fmt != input_pix_fmt)
      |                   ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2128:29: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 2128 |     avcodec_close(video_st->codec);
      |                             ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘bool cv_ff_codec_tag_match(const AVCodecTag*, AVCodecID, unsigned int)’:
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:142:26: error: ‘CODEC_ID_NONE’ was not declared in this scope; did you mean ‘AV_CODEC_ID_NONE’?
  142 | #define AV_CODEC_ID_NONE CODEC_ID_NONE
      |                          ^~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2167:24: note: in expansion of macro ‘AV_CODEC_ID_NONE’
 2167 |     while (tags->id != AV_CODEC_ID_NONE)
      |                        ^~~~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘void cv_ff_codec_tag_dump(const AVCodecTag* const*)’:
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:142:26: error: ‘CODEC_ID_NONE’ was not declared in this scope; did you mean ‘AV_CODEC_ID_NONE’?
  142 | #define AV_CODEC_ID_NONE CODEC_ID_NONE
      |                          ^~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2193:29: note: in expansion of macro ‘AV_CODEC_ID_NONE’
 2193 |         while (ptags->id != AV_CODEC_ID_NONE)
      |                             ^~~~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:142:26: error: ‘CODEC_ID_NONE’ was not declared in this scope; did you mean ‘AV_CODEC_ID_NONE’?
  142 | #define AV_CODEC_ID_NONE CODEC_ID_NONE
      |                          ^~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_NONE’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2207:28: note: in expansion of macro ‘CV_CODEC’
 2207 |     CV_CODEC_ID codec_id = CV_CODEC(CODEC_ID_NONE);
      |                            ^~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2230:26: error: invalid conversion from ‘const AVOutputFormat*’ to ‘AVOutputFormat*’ [-fpermissive]
 2230 |     fmt = av_guess_format(NULL, filename, NULL);
      |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
      |                          |
      |                          const AVOutputFormat*
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2313:18: error: ‘AVFormatContext’ {aka ‘struct AVFormatContext’} has no member named ‘filename’
 2313 |     snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
      |                  ^~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2313:39: error: ‘AVFormatContext’ {aka ‘struct AVFormatContext’} has no member named ‘filename’
 2313 |     snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
      |                                       ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:131:28: error: ‘CODEC_ID_JPEGLS’ was not declared in this scope; did you mean ‘AV_CODEC_ID_JPEGLS’?
  131 | #define AV_CODEC_ID_JPEGLS CODEC_ID_JPEGLS
      |                            ^~~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_JPEGLS’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2321:10: note: in expansion of macro ‘CV_CODEC’
 2321 |     case CV_CODEC(CODEC_ID_JPEGLS):
      |          ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:97:29: error: ‘CODEC_ID_HUFFYUV’ was not declared in this scope; did you mean ‘AV_CODEC_ID_HUFFYUV’?
   97 | #define AV_CODEC_ID_HUFFYUV CODEC_ID_HUFFYUV
      |                             ^~~~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_HUFFYUV’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2328:10: note: in expansion of macro ‘CV_CODEC’
 2328 |     case CV_CODEC(CODEC_ID_HUFFYUV):
      |          ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:106:26: error: ‘CODEC_ID_FFV1’ was not declared in this scope; did you mean ‘AV_CODEC_ID_FFV1’?
  106 | #define AV_CODEC_ID_FFV1 CODEC_ID_FFV1
      |                          ^~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_FFV1’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2367:10: note: in expansion of macro ‘CV_CODEC’
 2367 |     case CV_CODEC(CODEC_ID_FFV1):
      |          ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:95:27: error: ‘CODEC_ID_MJPEG’ was not declared in this scope; did you mean ‘AV_CODEC_ID_MJPEG’?
   95 | #define AV_CODEC_ID_MJPEG CODEC_ID_MJPEG
      |                           ^~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_MJPEG’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2396:10: note: in expansion of macro ‘CV_CODEC’
 2396 |     case CV_CODEC(CODEC_ID_MJPEG):
      |          ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:96:27: error: ‘CODEC_ID_LJPEG’ was not declared in this scope; did you mean ‘AV_CODEC_ID_LJPEG’?
   96 | #define AV_CODEC_ID_LJPEG CODEC_ID_LJPEG
      |                           ^~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_LJPEG’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2397:10: note: in expansion of macro ‘CV_CODEC’
 2397 |     case CV_CODEC(CODEC_ID_LJPEG):
      |          ^~~~~~~~
/home/dani/opencv/modules/videoio/src/ffmpeg_codecs.hpp:100:30: error: ‘CODEC_ID_RAWVIDEO’ was not declared in this scope; did you mean ‘AV_CODEC_ID_RAWVIDEO’?
  100 | #define AV_CODEC_ID_RAWVIDEO CODEC_ID_RAWVIDEO
      |                              ^~~~~~~~~~~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:143:26: note: in expansion of macro ‘AV_CODEC_ID_RAWVIDEO’
  143 | #  define CV_CODEC(name) AV_##name
      |                          ^~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2401:10: note: in expansion of macro ‘CV_CODEC’
 2401 |     case CV_CODEC(CODEC_ID_RAWVIDEO):
      |          ^~~~~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2461:20: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 2461 |     c = (video_st->codec);
      |                    ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2468:33: error: invalid conversion from ‘const AVCodec*’ to ‘AVCodec*’ [-fpermissive]
 2468 |     codec = avcodec_find_encoder(c->codec_id);
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
      |                                 |
      |                                 const AVCodec*
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:230: modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:8120: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2

full log here: $ make -j $(nproc)[ 1%] Built target quirc[ 1%] Built target opencv_videoi - Pastebin.com

Did you try an older version of CMake or setting the policy flag?

I’m not 100% sure but I would try an older version of FFmpeg.

i installed older version of CMake

After inspecting the CMake docs futher it appears that the default for the policy is OLD in your version so downgrading CMake should not have made any difference. After inspecting your CMake output again I think your issue was that you didn’t have cuDNN installed

CMake Error at modules/dnn/CMakeLists.txt:39 (message):
DNN: CUDA backend requires cuDNN. Please resolve dependency or disable
OPENCV_DNN_CUDA=OFF

I installed cuDNN
Then, I reinstalled ffmpeg from GitHub.

./configure --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx264 --enable-libspeex --enable-shared --enable-pthreads --enable-libopenjpeg  --enable-nonfree

pastebin com/Dp0Bfp0E

pastebin com/ekY3Aj2X

Is it working now? Have you tried an older version of FFmpeg? The build instructions from here work out of the box, but for ease you can remove all the optional packages. So I would try FFmpeg 5.0.3 “Lorentz”

libavutil 57. 17.100
libavcodec 59. 18.100
libavformat 59. 16.100
libavdevice 59. 4.100
libavfilter 8. 24.100
libswscale 6. 4.100
libswresample 4. 3.100
libpostproc 56. 3.100

with the below once you have the dependencies

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs="-lpthread -lm" \
  --ld="g++" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-gnutls \
  --enable-nonfree --enable-pic --enable-shared && \
PATH="$HOME/bin:$PATH" make && \
make install && \
hash -r

then if you add the build dir to PKG_CONFIG_PATH and the shared library path to the LD_LIBRARY_PATH e.g.

export PKG_CONFIG_PATH=/home/USER/ffmpeg_build/lib/pkgconfig/
export LD_LIBRARY_PATH=/home/USER/ffmpeg_build/lib/

OpenCV will pick it up and be able to use it.

Still not working :frowning:

~$ ffmpeg
ffmpeg version 5.0.3 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12 (Debian 12.2.0-14)
  configuration: --prefix=/home/dani/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/dani/ffmpeg_build/include --extra-ldflags=-L/home/dani/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/dani/bin --enable-gpl --enable-gnutls --enable-nonfree --enable-pic --enable-shared
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100

/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1463:31: error: ‘buffer_height’ was not declared in this scope; did you mean ‘buffer_width’?
 1463 |                 buffer_width, buffer_height,
      |                               ^~~~~~~~~~~~~
      |                               buffer_width
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1493:33: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1493 |         frame.width = video_st->codec->width;
      |                                 ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1494:34: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1494 |         frame.height = video_st->codec->height;
      |                                  ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1504:26: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1504 |             0, video_st->codec->coded_height,
      |                          ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvCapture_FFMPEG::retrieveHWFrame(cv::OutputArray)’:
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1533:44: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1533 |     return hw_copy_frame_to_umat(video_st->codec->hw_device_ctx, picture, output);
      |                                            ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::getProperty(int) const’:
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1569:30: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1569 |         codec_id = video_st->codec->codec_id;
      |                              ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1570:40: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1570 |         codec_tag = (double) video_st->codec->codec_tag;
      |                                        ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1590:43: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
 1590 |         AVPixelFormat pix_fmt = video_st->codec->pix_fmt;
      |                                           ^~~~~
/home/dani/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1599:29: error: ‘bsfc’ was not declared in this scope
 1599 |         const AVPacket& p = bsfc ? packet_filtered : packet;

Apologies I assumed you were using the latest version of OpenCV, support for FFmpeg 5 was not added until

try upgrading to the latest (4.8.0).

Thank you !
It works now.

wget -O opencv.zip https://github.com/opencv/opencv/archive/refs/tags/4.8.0.zip ; wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.8.0.zip ; unzip opencv.zip ; unzip opencv_contrib.zip ; mv opencv_contrib-4.8.0 opencv_contrib ; cd opencv-4.8.0/build/ ;
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-11 -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON3_EXECUTABLE=/home/dani/andrei_rec/andrei/bin/python -D WITH_TBB=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=ON -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=OFF -D CUDA_ARCH_BIN=7.5 -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_GSTREAMER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv.pc -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_PYTHON3_INSTALL_PATH=/home/dani/andrei_rec/andrei/lib/python3.11/site-packages -D PYTHON_EXECUTABLE=~/home/dani/andrei_rec/andrei/bin/pytho -D OPENCV_EXTRA_MODULES_PATH=/home/dani/opencv_contrib/modules -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF .. 
make -j$(nproc) ; sudo make install ;

python -c "import cv2, re; cv_info = [re.sub('\s+', ' ', ci.strip()) for ci in cv2.getBuildInformation().strip().split('\n') if len(ci) > 0 and re.search(r'(nvidia*:?)|(cuda*:)|(cudnn*:)', ci.lower()) is not None]; print(cv_info)"

[‘NVIDIA CUDA: YES (ver 11.8, CUFFT CUBLAS FAST_MATH)’, ‘NVIDIA GPU arch: 75’, ‘NVIDIA PTX archs:’, ‘cuDNN: NO’]

1 Like