Howto install OpenCV with FFMPEG functionality
This tutorial describes how to compile and install the OpenCV library correctly under Linux and make use of the ffmpeg video functions which allow video encoding and video decoding in different formats. This could be used for streaming a video capture stream from a webcam in realtime to disc, for example. Afterwards this stream could be read from disc to do computer vision experiments on it. So lets go...
First of all you will have to download the current versions of ffmpeg and OpenCV from the websites as described below. This Tutorial works for Ubuntu Linux with OpenCV 1.0 and ffmpeg subversion release 0.4.9-pre1. If you get it to work with other versions or encounter problems, please let me know!
- Download the current OpenCV source code and checkout the current ffmpeg snapshot. For getting the ffmpeg snapshot you will have to install subversion (for Ubuntu users: sudo apt-get install subversion) and follow the instructions on the ffmpeg website. Checkout ffmpeg via subversion to your home directory and extract the OpenCV tarball there, too.
- Build ffmpeg (as root):
./configure --enable-shared
The --enabled-shared option is needed because libavcodec is LGPL and OpenCV is published under a BSD license.
make
make install
- Build and install the OpenCV library (as root) now (first make sure that you have installed gtk+ 2.0
properly on your system: sudo apt-get install libgtk...):
./configure
Make sure that configure outputs something like (in general there should be a bunch of yes marked items, depending on what you intend to do, I prefer having the image libraries, too, but you will need at least ffmpeg, gtk+2.0, v4l, v4l2):
make
make install
- If errors arise in "cvcap_ffmpeg.cpp" like "cvcap_ffmpeg.cpp:250: error: integer constant is too large for
'long' type" while executing the makefile of OpenCV you will have
to add the following 2 lines of code to the top of file "otherlibs/highgui/cvcap_ffmpeg.cpp":
#define INT64_C
Then try step 3 again! If there is still a problem with a pointer (in newer versions of ffmpeg), try to change the line containing
#define __STDC_CONSTANT_MACROS
url_fclose(&mywriter->oc->pb);
tourl_fclose(mywriter->oc->pb);
- Now you should be able to run the demo files!