Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV VideoWriter will not open

I'm having trouble instantiating and opening an OpenCV VideoWriter for recording video on a Raspberry Pi (Raspbian Weezy).

My project is written in C++, but I've written a minimal Python program that demonstrates the problem.

https://gist.github.com/chriscollins/11ff2f43852e1c93dae8

Both my C++ code and the Python code above run without problem on my Windows machine. Sometimes the writer does not open, but that's to be expected - I don't have all of the listed codecs installed (the list of codecs comes from the Open CV source), but a good number of them work correctly. However, on a Raspberry Pi, both the C++ code and the Python code fail with the VideoWriter never being opened. In the above Python code, writer.isOpened() returns false for every single codec, when run on a Raspberry Pi.

I've chowned the destination directory to the user I'm running the Python script as, and chmodded it to 777 so I don't believe that it is a permissions problem. I think it may be connected with how I've installed OpenCV or some of its dependencies, but I'm not sure how to rectify it.

The install process I've used is as follows:

  1. Update firmware/packages via rpi-update, apt-get update and apt-get upgrade.

  2. Install the following dependencies via apt-get: libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev

  3. Download and unzip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip to /root/opencv-2.4.9.

  4. cd /root/opencv-2.4.9 and run cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_ocl=OFF. Output of cmake is available at https://gist.github.com/chriscollins/d8060e03a6acd6d4336c

  5. make and make install from the same directory.

Various other OpenCV functionality works correctly on the Raspberry Pi (in C++ or in Python) - e.g. viewing a webcam via VideoCapture, but I can't get the VideoWriter to work. I'm tempted to try installing FFMPEG from source instead of via apt-get, but as make takes 5+ hours to run on a Raspberry Pi, I was hoping I'd find the answer here, rather than proceeding with a trial and error approach!

Any advice on how to solve (or debug) this is appreciated.

EDIT: Added output of cmake command (https://gist.github.com/chriscollins/d8060e03a6acd6d4336c)

like image 356
ChrisC Avatar asked Jun 11 '14 19:06

ChrisC


1 Answers

Looking at the output of make, I've found that it says NO to installation of gstreamer, which is a must for multimedia handling. This is the missing link.

Try sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev .

This should solve your problem.

like image 130
optimist Avatar answered Nov 05 '22 10:11

optimist