Wednesday, November 30, 2011

Installing OpenCV 2.3.1 with FFmpeg on 64-bit Ubuntu

There are many good tutorials out there which describe the installation procedure of OpenCV with FFmpeg. However few of them are comprehensive and even fewer explain the proper setup procedure for a 64-bit machine. Below are the steps that I have been following while setting up OpenCV with FFmpeg on a couple of new 64-bit systems in our lab (with Ubuntu 11.10). OK, here we go:

Create a directory where the installation files will be downloaded:

$ mkdir ~/Tools
$ cd ~/Tools

Update your package index:

sudo apt-get update

Install the dependencies for x264 and FFmpeg:

$ sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev

Get gstreamer:

$ sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg

Get yasm:

$ sudo apt-get install yasm

Download x264 and install it:

$ git clone git://
$ cd x264
$ ./configure --enable-static --enable-shared
$ make
$ sudo make install
$ cd ..

Get the libs necessary for FFmpeg installation:

$ sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev

Download FFmpeg and install it:

$ git clone --depth 1 git://
$ cd ffmpeg
$ ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
 --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 \
 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-shared
$ make
$ sudo make install
$ cd ..

Install gtk:

$ sudo apt-get install libgtk2.0-0 libgtk2.0-dev

Install libjpeg:

$ sudo apt-get install libjpeg62 libjpeg62-dev

Install v4l:

Get the latest version of v4l from here. The version used in this installation is 0.8.5

$ wget
$ tar -xvf v4l-utils-0.8.5.tar.bz2 
$ cd v4l-utils-0.8.5
$ make
$ sudo make install
$ cd ..

Get the python libraries:

$ sudo apt-get install python-numpy python-sphinx python-dev

Finally install OpenCV:

Get the latest version from here. The version used in this installation is 2.3.1

$ wget
$ tar -xvf OpenCV-2.3.1a.tar.bz2 
$ cd OpenCV-2.3.1
$ mkdir Build
$ cd Build
$ make
$ sudo make install

If you want to see all the options while building OpenCV, use "ccmake .." instead of the above mentioned cmake command. Done! Hope that helped.