Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 3.0.0 make error with FFMPEG

I have been using OpenCV for a while. However I have recently changed my system to a cluster where I do not have any admin permission. The problem is like this :

In my home folder, I installed FFMPEG (latest stable version available on ffmpeg site). I installed it in $HOME, and so in $HOME/lib there are the library files installed. For more information I compiled FFMPEG with following options :

./configure --prefix=$HOME --enable-shared --enable-pic

I then downloaded the latest stable version of OpenCV 3.0.0 and configured it using ccmake. When I try to make -j8, it gives me the following error.

 Scanning dependencies of target opencv_videoio
[ 63%] [ 63%] [ 63%] [ 63%] [ 63%] [ 63%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap.cpp.o
Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_mjpeg_decoder.cpp.o
Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_images.cpp.o
Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_v4l.cpp.o
Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_mjpeg_encoder.cpp.o
Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o
In file included from /home/uujjwal/libraries/opencv-nogpu/opencv-3.0.0/modules/videoio/src/cap_ffmpeg.cpp:45:0:
/home/uujjwal/libraries/opencv-nogpu/opencv-3.0.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1546:71: error: use of enum 'AVCodecID' without previous declaration
/home/uujjwal/libraries/opencv-nogpu/opencv-3.0.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1556:83: error: use of enum 'AVCodecID' without previous declaration
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

However without ffmpeg support it works fine. However I need ffmpeg support due to the nature of my work.

In trying to resolve the problem, I tried installing OpenCV 2.4.11 but it also gave this error. The latest GIT version does not give me this error but rather an error a part of which goes like this

Linking CXX shared library ../../lib/libopencv_highgui.so /usr/bin/ld: /home/matheus/ffmpeg_build/lib/../lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used

I have pasted the above error from another unresolved question online and so the folder names are different but the relocation error is exactly the same.

In trying to resolve the problem I searched and found the following link http://answers.opencv.org/question/12597/build-problems-for-opencv-241-with-ubuntu-1204-lts/

However, one of the answers over there mentioned changing some lines in cap_ffmpeg_impl.hpp file. I tried doing that but either i am not able to do it correctly or something else is going wrong and it is not working. Exact line numbers and exact changes are not mentioned and so I am having difficulty changing things and being sure.

I am using Fedora 19 (Schrodinger Cat) as the operating system I hope the details of my question are clear and I hope that the community would oblige me with a good response.

Regards Ujjwal

like image 676
Ujjwal Aryan Avatar asked Jul 27 '15 21:07

Ujjwal Aryan


2 Answers

I ran into this as well trying to build OpenCV 3.0.0 on Ubuntu 12.04. The problem appears to be a bug in OpenCV. I edited opencv-3.0.0/modules/videoio/src/cap_ffmpeg_impl.hpp, replacing AVCodecID with CV_CODEC_ID in all places but the #define -- in lines 1174 (optional), 1546, and 1556 -- and the build worked.

For more details, see my post on the OpenCV issue tracker. And the bug had been fixed on the OpenCV master branch prior to my post as part of this commit.

like image 188
Ulrich Stern Avatar answered Oct 20 '22 20:10

Ulrich Stern


Assuming you don't use FFMPEG with OpenCV, you can disable it being compiled:

When you run Cmake i.e. when you did this:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D PYTHON2_PACKAGES_PATH=~/.virtualenvs/cv/lib/python2.7/site-packages \
    -D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/bin \
    -D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \
    -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

Add this flag to the mix -DWITH_FFMPEG=0 to not compile the FFMPEG part

like image 1
Airman00 Avatar answered Oct 20 '22 21:10

Airman00