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.


  1. Hi Vinay, thanks for this useful guide.



  2. hey vinay..nice post..
    but can u help me out in installing openCV 2.3.1..i would b using MS Visual Studio 2008 Express Edition

    if u can...please mail me the steps..or any link wer i can find the steps to install..
    my email address is:
    thanks.. :)

    1. Sorry, I have no experience with Windows based installations.

    2. I used this video.

  3. This is an awesome post. Thank you so much. This works perfect!!!

    installing opencv is not a joke at all if you don't know what to do. This post explains what and how to install very straight forward.

    5 stars on this post!!!

  4. Hi,

    I have installed it following your instruction. Nevertheless, right now, my java program cannot recognize it. Do you know how to configure opencv libraries with my java program?? Thanks.

    1. Sorry, I have no experience with OpenCV + Java. I have always only worked on OpenCV with C++.

  5. This comment has been removed by the author.

  6. Very useful post Vinay. Thanks.


  7. I have ubuntu 10.10….
    I want ffmpeg with Opencv2.3.1 support….
    I did the installation many times before….with building ffmpeg manually as you said….
    Its working fine also its showing me ffmpeg support ON at the time of configuring OpenCv 2.3.1…
    But when I use CV_FOURCC(‘F’,'L’,'V’,’1′) to create .flv file through cvCreateVideoWriter I am getting this error [flv @ 0x9bf5000] Tag FLV1/0x31564c46 incompatible with output codec id ’22′….
    Is their any thing wrong I had done while installation….

  8. An easy way...

  9. Ffmpeg has to be version of 7.11 or earlier because OpenCV hasn't managed to keep up with the update of FFMPEG. If it's later than 7.11,then cap_ffmpeg_impl.cpp may give error while building at 33%.

  10. More over, if one wants include tbb and enable other options in cmake I think it's better to build by cmake from the cmake-gui rather than the terminal.

    1. That's true. I edited the post to mention this. Thanks for the comment.

  11. Mr. Vinay, will the steps be the same for 32bit linux?

    1. No. Some steps are different. There are several other excellent tutorials out there for a 32-bit build.

    + opencv 2.3.1 requires ffmpeg 0.8.x if you do it according to your guide you download 1.0

    1. Thanks, I edited the post to reflect this.

  13. In case you want to make a package out of your OpenCV compilation (and maybe hand it to other ppl), replace sudo make install with this:
    sudo checkinstall --pkgname=opencv-svn --pkgversion="2:$(date +%Y%m%d%H%M)-opencv" --default --backup=no

    1. Thanks for the info. I did not know about this.

  14. Hi Vinay...........Thanks for this nice and useful post.
    I am getting error at 14% after using make command.
    I dont know what is the problem.....

    pls help ...



  15. As mentioned in one of the replies, the instructions download the latest version of FFmpeg which is not supported in OpenCV 2.3.1.

    SOLUTION: Download FFmpeg 0.10 (from, untar it and continue from line 2 of the ffmpeg section (ignore the git-related line).

    I'd add one more line to this instruction set as a sanity check. Run the OpenCV test suite: ./opencv_test_core (located in OpenCV-2.3.1/Build/bin)

  16. About the FFmpeg support : following the instructions "git clone --depth 1 git://" generate an error when i build openCV. (about KGD post : the last version when i tried was the 0.10.3, so i guess 0.10 won't work either)
    An anonymous said "FFmpeg has to be version of 7.11 or earlier because OpenCV hasn't managed to keep up with the update of FFMPEG"
    So i randomly tried with 0.6.5, then the build is ok but not the bin/opencv_test_xxx which failed on many different points, and so in my owns programs the VideoCapture failed at the opening.
    Do you know a version of FFmpeg that work (for ubuntu 12.04 64b) ?
    Thanks in advance.

    1. I just installed it on 12.04 64bit with the provided instructions,

      just before building and deploying OpenCV after the instruction above circa june1st2012, I also installed the openCL cuda libs and sdk from
      currently 4.2,
      and followed the instructions here:
      and installed tbb with
      sudo apt-get install libtbb-dev
      I used ccmake to set the cuda and tbb options on. I just tested facedetect and it works in real time (the moment a face in in view) I'm stoked.

  17. Thanks so much for such an informative and well maintained site Vinay, you bring honor to the craft.

  18. if you are using CUDA and nvidia current you need to create a link : su -c 'ln -s /usr/lib/nvidia-current/ /usr/lib/ && ln -s /usr/lib/nvidia-current/ /usr/lib/'


  19. Haan..Finally stumbled upon it. FFMpeg is a Bitch!


  20. To install OpenCV using the terminal on Ubuntu:
    $ su -
    # apt-get update
    # apt-get install build-essential
    # apt-get install libavformat-dev
    # apt-get install x264 v4l-utils ffmpeg
    # apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev

  21. Hello Vinay

    I hope that you help me. I try install OpenCV. However, when I install OpenCV I had this error:
    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2
    Before I see your tutorial I tried with another intalling_OpenCV and I had the same error.

    I don't know why?? I have ubuntu 14.10, Can it be the problem??