Ask Your Question
1

OpenCV 3.0 won't compile with FFMPEG support?

asked 2015-06-05 11:40:10 -0600

rexroni gravatar image

I would like to use the ffmpeg library so I have video support with my OpenCV 3.0 build. I'm using the excellent step-by-step instructions from the book Practical OpenCV by Samarth Brahmbhatt (http://www.it-ebooks.info/book/3145/) But every time I run make, the build quits while trying to link libopencv_videoio.so, and throws this error:

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

First, there was actually some similar error, and I fixed it by recompiling x264 with the additional option --enable-pic. That was easy.

But I've recompiled ffmpeg a bunch of times, with the options --extra-cflags=-fPIC, --extra-cxxflags=-fPIC, --enable-pic, and nearly every combination of those options. Nothing will make this work.

I don't have any problem following the same steps with OpenCV 2.4.9.

Help!

edit retag flag offensive close merge delete

Comments

Any reason why you want ffmpeg explicitly? It has been replaced by libav on newer linux systems :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-07 04:25:12 -0600 )edit
1

Really? I suppose I'm not too concerned where my video support comes from... I just wanted video support and I had instructions for how to make ffmpeg work. I actually solved the question before I asked it, only I wasn't able to answer immediately due to new-user restrictions.

Do you have instructions for setting up opencv with libav, or is it just an option in ccmake and it "just works"?

rexroni gravatar imagerexroni ( 2015-06-08 20:26:44 -0600 )edit
1

Just a compile option yes :) libav is pretty much preinstalled on linux systems

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-09 02:44:53 -0600 )edit
1

Thanks for the tip!

rexroni gravatar imagerexroni ( 2015-06-09 09:12:50 -0600 )edit

Ok, so I again have a need to compile opencv with video support, but I do not see a WITH_AV option or anything that looks like that when I run ccmake .., am I missing something?

rexroni gravatar imagerexroni ( 2015-09-01 12:46:50 -0600 )edit

It is still the flag WITH_FFMPEG but under the hood this has been changed by libav in Linux distributions.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-02 07:35:33 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2015-12-22 17:13:11 -0600

weston.pace gravatar image

Another option is to simply build ffmpeg as a shared library (pass --enable-shared --disable-static to configure) which removes the need for fPIC.

edit flag offensive delete link more

Comments

I like this, it is simpler.

rexroni gravatar imagerexroni ( 2016-04-22 15:54:02 -0600 )edit
2

answered 2015-06-08 20:23:30 -0600

rexroni gravatar image

updated 2015-09-01 15:10:55 -0600

Ah, great question Rex. I had the same exact problem, myself!

I tried all the same things you did actually. I finally found the answer by googling "ffmpeg --enable-pic", which led me to the ffmpeg website on advanced linking configuration (http://www.ffmpeg.org/platform.html#A...). It turns out my problem was two-fold: I needed to change how I was compiling ffmpeg, and how I was linking OpenCV

The short answer is, I recompiled ffmpeg with additional flags --enable-pic and --extra-ldexeflags=-pie, and then had to edit a particular option in my OpenCV build. I used ccmake to set CMAKE_SHARED_LINKER_FLAGS to a value of -Wl,-Bsymbolic, as described by the ffmpeg website.

Hopefully this helps you out, Rex. Best of luck!

Ok but seriously, this took me a while to find the answer, so hopefully this will help save somebody a couple hours of pain.

edit flag offensive delete link more

Comments

Can you elaborate this part a little ".. and then had to edit a particular option in my OpenCV build. I used ccmake to set CMAKE_SHARED_LINKER_FLAGS to a value of -Wl,-Bsymbolic, as described by the ffmpeg website." Which option did you edit particularly ? In my case OpenCV is picking up an older version of FFMPEG (libavcodec -54.35 instead of 56.1...) is there some setting to force OpenCV to force using another version ?

abhiguru gravatar imageabhiguru ( 2015-06-11 07:43:17 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-06-05 11:40:10 -0600

Seen: 9,624 times

Last updated: Sep 01 '15