Montag, 29. Juni 2009

Install OpenCV with support for ffmpeg in Ubuntu 9.04 (Jaunty)

Task: Install stable version of OpenCV with support for ffmpeg
(Update: svn devel version recognizes natively and has no error, recommended!)

(1) Download the current version of ffmpeg (version 0.5.0 in June, 2009), from ffmpeg website.
(2) un-tar the tar.bz2 file of ffmpeg to /ffmpeg/install/dir, enter the directory, use

./configure --enable-shared --enable-gpl --enable-swscale
make -j 4
sudo make install

To install the ffmpeg package. The options:
--enable-shared: Due to LGPL license
--enable-gpl: Must select to enable swscale
--enable-swscale: Used by OpenCV
(3) switch to /usr/local/include, use sudo to set up a new directory there named ffmpeg, and then link the header files needed by OpenCV. The complement command list:

cd /use/local/include
sudo -i
mkdir ffmpeg
ln -s ../libavcodec/avcodec.h ./
ln -s ../libavdevice/avdevice.h ./
ln -s ../libavformat/avformat.h ./
ln -s ../libavformat/avio.h ./
ln -s ../libavutil/avutil.h ./
ln -s ../libswscale/swscale.h ./

(4) Download current version of OpenCV from, unzip the file and enter the unzipped directory
(5) Configure the install with

./configure --with-ffmpeg

Use --help option to check for other options
(6) When the configure finishes, check the output 'use ffmpeg' should display 'yes'
(7) Once the configure succeeds, make and install the OpenCV with

make -j 4
sudo make install

Note and Update
a. I have always used '-j 4' in make scripts since the working computer has quad-core. Adjust to the number of threads according to your computer configuration
b. Current stable version of OpenCV (1.1pre1) leads to segmentation fault when user tries to call cvCreateVideoWriter function, since it always returns NULL. It seems to be related to inconsistent change of ffmpeg package. The svn version of OpenCV recognizes ffmpeg perfectly and does not cause error anymore. Therefore for people familiar with svn it is strongly recommended to use the devel version of OpenCV.