Install OpenCV in Linux with video (ffmpeg) support

Faced with the task of running Computer Vision problems in Linux environment, i started googling for the methods.. Though i found the install steps at many places, but my install always failed, getting stuck while doing a make operation on the source files.

Finally, i managed to install it from source.. I am listing the steps here, with a special thanks to all the people, their blogs and google for helping me succeed in installing OpenCV.

  • Download ffmpeg
  • Extract contents to a folder. do a cd to the folder location in the terminal. Build ffmpeg as follows (as root) :
  • su -c
  • ./configure –enable-shared
  • make all
  • make install
  • The –enable-shared option during configuration ensures compatibility between LGPL licence of ffmpeg contents and BSD licence of OpenCV.
  • ADDITIONAL IMPORTANT STEPS (before installing OpenCV)
  • goto the folder where library files of ffmpeg have got installed in your system. you can do a “locate ffmpeg” to know that. for e.g, in my case, its /usr/include/ffmpeg/
  • Now, type in the follwing (as root):
  • ln -s libavcodec/avcodec.h avcodec.h
  • ln -s libavformat/avformat.h avformat.h
  • ln -s libavformat/avio.h avio.h
  • ln -s libavutil/avutil.h avutil.h
  • ln -s libswscale/swscale.h swscale.h
  • Download latest build of OpenCV 2.1 or OpenCV 2.0
  • install swig in your version of linux.. its available in the repos of all the distros. Swig is the application that interacts between different programming languages like C / C++, Python, etc. Swig is extremely essential for succesfull build of OpenCV.
  • yum install swig sip (Fedora)
  • apt-get install swig python-sip (Debian based distros)
  • Extract and build OpenCV as follows :
  • ./configure –enable-shared

ENSURE the summary of this step is somewhat similar to

If not, please install the required dependencies from your package manager (yum / Synaptic) as mentioned in the link. Any missing dependency will lead to some problem or the other.

  • make
  • make install
  • Now, comes the finishing touch stage.. you need to let the system know where the OpenCV library files are located.
  • export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
  • ldconfig

And you are done.. enjoy the OpenCV build by running examples as mentioned in the technical documentation : OpenCV install Guide

OpenCV summary of configure step

Example of playing a file using ffplay command

playing a video file using ffplay

Convert Youtube video format

In case you want to convert the format of the videos you download from Youtube from flv to say, mpg.. the fabulously powerful DSP codec pack ffmpeg is the tool you need..

Just ensure that ffmpeg is installed in your system.. Follow the steps given to complete the requirement…

  • su -c ‘yum install ffmpeg*’
  • ffmpeg -i old_flv_file.flv new_file_name.mpg

The input file old_flv_file.flv, specified after the “-i” option, gets converted to new_file_name.mpg