Install Opencv 2.3.1 on Ubuntu 12.04 Precise Pangolin

Here are instructions for installation of Opencv 2.3.1 on Ubuntu 12.04 Precise Pangolin. For opencv installation we need FFmpeg, x264, v4l and their dependencies. It is a bit longer process as compared to windows installations. Step by step process is shown below.

1. Install dependencies for FFmpeg and x264
Enter following lines in terminal to check and install dependencies.
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

2. Install Gstreamer by entering following lines in terminal
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

3. Download recent version (0.8+)of FFmpeg from extract it and go to the directory. Now configure and install FFmpeg by entering following commons one by one.

./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
sudo make install

4. Install recent version of x264 from extract it and go to the directory. Now configure and install x264 by entering following commons one by one.

./configure --enable-static
sudo make install

5. Download video for linux v4l libs from extract it and go to the directory. Install v4l using following command.
sudo make install

6. Install gtk libs using apt-get
sudo apt-get install libgtk2.0-0 libgtk2.0-dev

7. Install libjpeg using following command
sudo apt-get install libjpeg62 libjpeg62-dev

8. Now our dependencies are complete. We can install Opencv now. Download Opencv from Extract it and go to the directory. Enter following command to configure and install Opencv
mkdir build
cd build
cmake ..
sudo make install

We are done with installing Opencv on ubuntu 12.04 Precise Pangolin. In order to set path open /etc/bash.bashrc using your favorite text editor and add following lines

Restart your system and you are ready to use awesome Opencv!


  1. Hi.. I am entirely new to ubuntu and opencv...
    I am trying to install opencv but in first step only i am getting following error...
    E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)
    E: Unable to lock directory /var/cache/apt/archives/

    Please tell me now what should i do??

    1. Close any other software installing or repository accessing software like Software Center or Synaptic Manager and then try to execute.

  2. cant be install ffmpeg too from repository like (sudo apt-get install ffmpeg)?

  3. hi..
    please can you help me to find what i should download from the link of ffmpeg, there is a lot of things so i can't find my goal :(

    when i insert the instruction of ./configure, i'm getting the following error:

    bash: ./configure: Aucun fichier ou dossier de ce type

    please, can u help me!

  4. Hi..
    My webcam is not working. Its giving error like
    vidioc_querymenu invalid argument
    vidioc_querymenu invalid argument
    vidioc_querymenu invalid argument

    Any solution for this?

  5. root@xxx:/home/xxx/Downloads/OpenCV-2.4.4/build# make
    [ 5%] Built target libtiff
    [ 8%] Built target libjasper
    [ 16%] Built target IlmImf
    [ 16%] Built target opencv_core_pch_dephelp
    [ 16%] Built target pch_Generate_opencv_core
    [ 19%] Built target opencv_core
    [ 19%] Built target opencv_ts_pch_dephelp
    [ 19%] Built target pch_Generate_opencv_ts
    [ 19%] Built target opencv_imgproc_pch_dephelp
    [ 19%] Built target pch_Generate_opencv_imgproc
    [ 24%] Built target opencv_imgproc
    [ 25%] Built target opencv_flann_pch_dephelp
    [ 26%] Built target pch_Generate_opencv_flann
    [ 26%] Built target opencv_flann
    [ 26%] Built target opencv_highgui_pch_dephelp
    [ 26%] Built target pch_Generate_opencv_highgui
    Linking CXX shared library ../../lib/
    /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libavcodec.a: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make[2]: ** [lib/] Erro 1
    make[1]: ** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Erro 2
    make: ** [all] Erro 2

    help-me, please ;(

    1. try an earlier version of OpenCV. I had the same problem as you with OpenCV 3.0.0 and 2.4.10, but I had no issues with 2.4.9

  6. i have the same problem too please help

  7. same here please help :(

  8. I just followed your instruction on headless 64-bit Ubuntu 12.04.1 and it worked perfectly. Any other instructions failed with ("relocation R_X86_64_32S against.."). I suspect building the dependencies from source helped a lot.

  9. I've received the same error as above. Could you please elaborate on it?

  10. I think I followed the instructions exactly on Ubuntu 12.04 LTS headless. However, ffmpeg will not build and complains: "ERROR: libx264 not found". Which makes sense as x264 is built later, right? Please explain.

    Also, as a general question, why is OpenCV so incredibly hard to install? Software should be different.

  11. Oh, and this:

    root@...:~/dev/x264/x264-snapshot-20141205-2245-stable# ./configure --enable-static
    Found yasm
    Minimum version is yasm-1.2.0
    If you really want to compile without asm, configure with --disable-asm.

  12. I'm sorry, but it seems the instrucitons on this page are full of problems... the ./configure line is missing in the v4l segment. Also, v4l doesn't compile ("cannot find jpeglib.h"), at least not with "./configure" without options.

    How could anyone succeed using these instructions?

  13. ...and finally the "relocation against" bug mentioned above hit me too.

    I'm sorry but these instructions are not useful.