ffmpeg and OpenCV

As of Oct 11, 2009, I reinstalled OpenCV and ffmpeg again on Ubuntu Jaunty. The previous installation procedure doesn’t seem to work. I can install OpenCV but it doesn’t cooperate happily with ffmpeg.

I came across this wonderful guide and it more or less solves all my problems. Below repeats some of the steps described in the guide.

First, we need some packages for building,

sudo apt-get build-dep python-opencv
sudo apt-get install libswscale-dev swig

There is a problem with OpenCV. The structure of ffmpeg has changed but OpenCV isn’t catching up. We have to set soft links for several include files as follows.

sudo mkdir /usr/include/ffmpeg
cd /usr/include/ffmpeg
sudo ln -s ../libavcodec/avcodec.h avcodec.h
sudo ln -s ../libavformat/avformat.h avformat.h
sudo ln -s ../libavformat/avio.h avio.h
sudo ln -s ../libavutil/avutil.h avutil.h
sudo ln -s ../libswscale/swscale.h swscale.h

Now, check out latest OpenCV snapshot.

cd
svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/tags/latest_tested_snapshot

Here, I diverge from the guide and go through cmake as suggested in the OpenCV website instead.

cd ~/latest_tested_snapshot/opencv  # the directory should contain CMakeLists.txt, INSTALL etc.
mkdir release # create the output directory
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
make

Here, I diverge from both guides. Instead of running sudo make install, it is safer to run checkinstall. If checkinstall is not installed, install it from synaptic and then run

sudo checkinstall

For Python 2.6, it moves cv.so incorrectly to /usr/local/lib/python2.6/site-packages/. We will need to move cv.so back to /usr/local/lib/python2.6/dist-packages/

It spent me a day to get ffmpeg and OpenCV working together. There are quite a lot of guides on the web but some of them are probably outdated.

I have Ubuntu 8.10 installed and these two installation guides for ffmpeg and OpenCV work for me after a few tweaks.

1. For ffmpeg, one has to add –enable-shared as a config option. That is,

./configure --enable-shared --enable-gpl --enable-postproc --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid

2. I first got error message for using ffmpeg after installation.

ffmpeg: symbol lookup error: /usr/local/lib/libavcodec.so.52: undefined symbol: av_gcd

But adding

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

to .bashrc will do the trick.

3. Before installing OpenCV, I have to run

sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev

to avoid compilation error.

N.B. For 64 bit Ubuntu, an additional flag –enable-pic is needed to configure x264.

Leave a Reply

Your email address will not be published. Required fields are marked *