Installing OpenCV with ffmpeg
As far as I can tell it is possible to install OpenCV without
root access, but it's slightly more complicated. If you have root access
then su now and ignore any of the instructions in italics.
The version I downloaded was opencv-0.9.7, so if you suddenly see numbers
popping up, that's why. Substitute your version if using a later one.
-
If you had to download subversion, do the following to extract, install and use it to download ffmpeg:
      tar -xvzf subversion-1.3.2.tar.gz
      cd subversion-1.3.2
      sh autogen.sh
      ./configure --prefix="/tmp/svn-bin"
      make
      make install
      cd subversion/clients/cmdline
      ./svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
      mv ffmpeg /tmp
      cd /tmp -
In order to get OpenCV to see ffmpeg, you must install ffmpeg first. This
can be done by first changing to the directory and then configuring and
installing the package.
      cd ffmpeg
      ./configure --prefix="/home/ffmpeg" --enable-shared
      make
      make install
You should now have a working copy of ffmpeg, so next we install OpenCV. -
Change to the directory:
      cd ../opencv
Without knowing where the ffmpeg libraries are, the configure script for OpenCV will not know how to use ffmpeg. Using the bash shell, the next line you need to enter on to the command line is:
      export LD_LIBRARY_PATH=/home/ffmpeg/lib:/home/opencv/lib
However, other shells may require a different syntax - the csh shell, for example uses the command 'setenv' instead of export, but I'm not certain of the syntax. A quick google search will probably put you right.
Once discovered, this line can and should be added/appended to your shell's rc file, e.g. .bashrc, .cshrc, etc. -
NON-ROOT ONLY: Create a new folder somewhere you have access to - the
desktop or your home folder are good places. Try to give the folder a
suitable name, something that will help you identify it at a later date.
(For the sake of continuity I will use /home/opencv/ in all examples on
this page. Simply substitute your directory for that one.)
Then type:
      ./configure --prefix=/home/opencv --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing CFLAGS=-I/tmp/ffmpeg-bin/include CPPFLAGS=-I/tmp/ffmpeg-bin/include LDFLAGS=-L/tmp/ffmpeg-bin/lib -
ROOT ONLY: Configure the installation:
      ./configure --prefix=/home/intel/opencv-0.9.7 --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing CFLAGS=-I/tmp/ffmpeg-bin/include CPPFLAGS=-I/tmp/ffmpeg-bin/include LDFLAGS=-L/tmp/ffmpeg-bin/lib
(substituting 'opencv-0.9.7' for the version number you downloaded, if necessary). -
Assuming all goes well, the configuration program will end with a prompt
to 'make'. Do that and then register the libraries (make install).
      make
      make install -
Copy the documentation from your decompressed folder to the folder made
during configuration.
NON-ROOT:       cp -R docs/  /home/opencv/
ROOT:       cp -R docs/ /home/intel/opencv-0.9.7/ -
ROOT ONLY: If you wish to do so at this point, a simlink can be handy
when updating to new versons and builds. (A simlink is a virtual link
to somewhere, essentially creating another way of referring to it.) If
you want to put one in, first change directory to the installation's
parent folder. For root users this will be /home/intel/.
Then use:
      ln -s opencv-0.9.7 opencv
The next time you update to a newer version of OpenCV, simply do the same but substituting the new folder name/version number. Provided you have used the simlink in paths then all your programs should still work, regardless of what version you're using. -
ROOT ONLY: You need to add a line to a config file so that linux knows
where to find the new libraries, so open '/etc/ld.so.conf' in your
favourite text editor and add '/home/intel/opencv/lib' to the end of the file
(or '/home/intel/opencv-0.9.7/lib' without the simlink). Then use the command:
      ldconfig -v
(If linux can't find ldconfig you get an error, in which case you can type 'locate ldconfig' and use the path it gives you.) -
Finally, you will need to add a line to your shell's rc file (e.g.
.bashrc, .cshrc, etc):
      cd ~
      vi .bashrc
As you'll notice, my system uses the bash shell. If yours uses csh then you'll need to use 'setenv' instead of 'export' below, but if you encounter problems then it may be because you need to use a slightly different syntax, in which case I recommend doing a quick google search for the proper way to set an environment variable in your shell. Once in vim, add or append the following:
      export LD_LIBRARY_PATH=/home/opencv/lib
      export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig
If this doesn't work, don't worry - I've added an extra bit in the Makefile which should get around the problem another way.
