Hi everyone,
unfortunately I’m having trouble building OpenCV successfully. I am trying to run a code that uses #if defined(HAVE_OPENCV_CUDACODEC). Therefore, I am trying to install OpenCV2 with the extra modules. I am using gcc-8 in order to circumvent another error message I received. The disable-ffmpeg-versions -disable-ffmpeg-versions=OFF was a try to solve the error message in the topic.
Thank you for helping me out
$ cmake --build .
[ 1%] Built target libopenjp2
[ 1%] Built target opencv_videoio_plugins
[ 3%] Built target ippiw
[ 3%] Built target opencv_cudev
[ 3%] Built target ittnotify
[ 8%] Built target opencv_core
[ 12%] Built target opencv_imgproc
[ 17%] Built target libwebp
[ 18%] Built target opencv_imgcodecs
[ 18%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o
In file included from /home/user/Downloads/opencv-master/modules/videoio/src/cap_ffmpeg.cpp:50:
/home/user/Downloads/opencv-master/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘void CvCapture_FFMPEG::close()’:
/home/user/Downloads/opencv-master/modules/videoio/src/cap_ffmpeg_impl.hpp:606:34: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’
avcodec_close( video_st->codec );
_________________________^~~~~
/home/user/Downloads/opencv-master/modules/videoio/src/cap_ffmpeg_impl.hpp: At global scope:
/home/user/Downloads/opencv-master/modules/videoio/src/cap_ffmpeg_impl.hpp:789:39: error: ‘AVLockOp’ has not been declared
static int LockCallBack(void **mutex, AVLockOp op)
_____________________________________ ^~~~~~~~
[…]
Sidenote: I have ffmpeg installed and configured as described here.
looks like your available ffmpeg is “too new” and they (deprecated and) removed the codec member from AVStream recently, in favor of codecpar.
what version of OpenCV did you do this with? I’m assuming latest.
OpenCV would need a fix for that. feel free to open an issue on OpenCV’s github. don’t worry too much about all the things they ask for in the issue template.
for now you could use an older version of ffmpeg (its libraries). I think that should work.
the deprecated field is still available if #define FF_API_LAVF_AVCTX (LIBAVFORMAT_VERSION_MAJOR < 59) so you could choose your ffmpeg based on that information.
Hi Crackwitz,
thank you for your prompt reply. I just closed the issue after I noticed yours.
Yes, you are correct. I was following this guide, which suggest to use this git.
Thanks for your help!
I went ahead and did a git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/
then, I found the n4.4 in the repository here and clicked on the commit. Then, I did a checkout of that specific commit as follows: git checkout dc91b913b6260e85e1304c74ff7bb3c22a8c9fb1
I guess we could call it progress. Now, I have a new error:
[ 1%] Built target libopenjp2
[ 1%] Built target opencv_videoio_plugins
[ 3%] Built target ippiw
[ 3%] Built target opencv_cudev
[ 3%] Built target ittnotify
[ 3%] Linking CXX shared library …/…/lib/libopencv_core.so
[ 8%] Built target opencv_core
[ 8%] Linking CXX shared library …/…/lib/libopencv_imgproc.so
[ 12%] Built target opencv_imgproc
[ 17%] Built target libwebp
[ 17%] Linking CXX shared library …/…/lib/libopencv_imgcodecs.so
[ 18%] Built target opencv_imgcodecs
[ 18%] Linking CXX shared library …/…/lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pw_9’ can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:311: lib/libopencv_videoio.so.4.5.2] Error 1
make[1]: *** [CMakeFiles/Makefile2:6716: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
or check out the tag by name, whatever hash it has: git checkout tags/n4.4
or optionally create a branch, if “detached head” seems inconvenient: git checkout tags/n4.4 -b tagged-n4.4
looks like your build directory still has some .a files, which are for static linking. I think you’re supposed to build ffmpeg as a shared library (.so files). OpenCV usually wants ffmpeg like that.
SOLUTION:
So for ffmpeg I did: ./configure --enable-shared --disable-static --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
Then, for openCV I did: cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules -DCMAKE_C_COMPILER=$(which gcc-8) -DCMAKE_CXX_COMPILER=$(which g++-8) -DWITH_CUDA=ON -DWITH_OPENGL=ON ../opencv-master
SOLUTION IN SHORT:
For now (until openCV resolves the issue) use ffmpeg v4.4 and if you get an error message with ff_pw_9, include --enable-shared --disable-static in the ./configure step.