recent opencv svn compilation with ffmpg 0.5 or later

I downloaded a recent version of OpenCV from SVN. I also downloaded a recent SVN version of ffmpeg. This is an informal log of the installation “pains”. I have been using OpenCV since version 0.9.6 and my work fully relies on it. What follows is true for ffmpeg 0.5 also.

Short Version of how I did it

Install ffmpeg with ./configure –enable-shared. Then do ‘make’ & ‘make install’. Do ‘ldconfig’ after installation. check the ffmpeg version by ‘ffmpeg -version’. Note that ffmpeg dumps its header files in 5 header files like libavformat etc. Make a directory called ffmpeg under /usr/local/include., i.e., ‘mkdir /usr/local/include/ffmpeg’. Go to /usr/local/include. Copy ‘avcodec.h  avformat.h  avio.h  avutil.h  swscale.h’ from respective ‘lib’ directories to ffmpeg. I prefer sym-linking it.

Then download the latest SVN version of opencv from sourceforge. It is available as a tarball in case you do not feel inclined to run the SVN from command line. After gunzipping and untarring it, we get a directory called opencv. Change directory to opencv.  Make the file ‘configure’ by doing ‘chmod +x configure’. Then do ‘./configure –without-1394libs –without-python –disable-apps’. These arguments disable 1394/Firewire libraries, python support and building of applications. I have not faced major limitations by disabling these. There should be a series of messages. Confirm that ffmpeg is recognised and will be used. This will be indicated by a line “Use ffmpeg:       yes”. If this does not happen, go back to the step of ffmpeg installation. If you are sure that ffmpeg is installed correctly and you are able to see files in /usr/local/include/ffmpeg/, then one way of checking whether opencv finds the header files is that you search for the keyword ffmpeg in the output of ‘./configure’ typed exactly as previously. In other words, you do ‘./configure –without-1394libs –without-python –disable-apps | grep ffmpeg’. You should get the lines which confirm or deny the existence of the headers ‘ffmpeg/avcodec.h’ availability. If these headers are not found, then your linking or copying is not ok. If on the other hand, ffmpeg has been found, do ‘make’ and ‘make install’ and then ‘ldconfig’.

** For x86-64 users: the configure script has a peculiar tendency of identifying all intel CPUs as pentium4. if you run ‘make’ after ‘./configure’, then you will run into compilation errors saying that architecture specified cannot be compiled. Do not lose heart but open the config.status file and search for the word ‘pentium4’ in this file. You should get something like ‘-march=pentium4’ along with other options. Change ‘-march=pentium4’ to ‘-march=native’ or you can even delete the whole thing. If you have a recent version of gcc, you can enable openmp by  adding ‘-fopenmp’ in the same line where you found the previous expression.

The above worked for me. I hope it does for you.

Post a comment or leave a trackback: Trackback URL.


  • Serge BV  On July 8, 2009 at 2:08 pm

    Thank you!
    Very useful for me ’cause I ought to migrate to the new release of ffmpeg while older one somehow works with old opencv…

  • V Srikrishnan  On July 9, 2009 at 6:39 pm

    Good that at least one person found this useful. I had emailed the developer’s list regarding this, I got some hints there but worked out myself, not that it is a big deal. Do note however that you are disabling some of the feature while configuring.

  • zhenli  On February 11, 2010 at 10:51 pm

    Can you tell me how to install player stage gazebo on ubuntu 9.10 64 bit CPU. I often got the problem. It is better step by step.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: