If you need to load, display or process videos using OpenCV, it is a pain to have all these installed and configured to work correctly on Ubuntu 14.04 (and to a lesser extent 16.04). OpenCV requires the ffmpeg libs to work with video formats like .avi, .mp4 etc.
The problem is Ubuntu did not ship ffmpeg with 14.04 (its not even in the software repository as an optional install). If you have admin rights, then you could compile ffmpeg from source or use unofficial 3rd party PPAs. If you do not have admin rights on your Linux machine, what are your options then?
(a) Install Python distributions like Anaconda or Enthought Canopy.
(b) Use their package manager to install opencv binaries with Python support.
However, these binaries are typically compiled without ffmpeg support. In Anaconda, user-contributed packages are available through (Anaconda Cloud). Anaconda provides a build-chain called conda-build that simplifies the process of building python libs which are not part of the official distribution. It is possible to install newer versions of OpenCV (like OpenCV 3.1.0 -lookup for ‘menpo’ channel)
I’m installing the 2.4.11 version of OpenCV from the menpo channel, but it still lacks ffmpeg support. Fret not, there is a solution; we simply re-compile OpenCV by enabling ffmpeg support:
$ conda install conda-build $ conda install cmake $ git clone https://github.com/menpo/conda-opencv $ conda config --add channels menpo
At this point, go to the conda-opencv/conda folder and edit the build.sh file. Modify the following cmake flag in that file:
-DWITH_FFMPEG = 1
Depending upon the version of cmake installed by Anaconda, edit the meta.yaml as follows:
... requirements: build: - cmake 3.3.x # change x to whatever version is installed
If you want to know which version of cmake is installed, you can issue:
$ conda list
$ conda build /conda $ conda install /PATH/TO/OPENCV/PACKAGE.tar.gz
If you installed Anaconda in your home directory, then the path would be
If everything went smoothly, you should have opencv with ffmpeg support!
Note, you might need to have ffmpeg compiled or installed on your machine. I did not test it on machines where ffmpeg wasn’t available.