jayrambhia / Install-OpenCV

shell scripts to install different version of OpenCV in different distributions of Linux
1.04k stars 946 forks source link

Video encoding issues #14

Closed ldodds closed 10 years ago

ldodds commented 10 years ago

I've tried various versions of your installation scripts. While this does get OpenCV installed under Ubuntu 12.10 I'm not sure the final configuration is correct.

When attempting to use video recording from Python I get errors like this:

OpenCV Error: Unsupported format or combination of formats (Gstreamer Opencv backend doesn't support this codec acutally.) in CvVideoWriter_GStreamer::open

This is with the standard AVI codec. My test case is the application included here:

http://nummist.com/opencv/3923_02.zip

Run python cameo.py and hit tab to begin recording. I get an error. I think the issue is something to do with how opencv and ffmpeg but I'm not clear what: I don't have any issue playing avi files, so I think this is a configuration issue.

Any ideas?

ldodds commented 10 years ago

I've just tried this on a relatively fresh install of Ubuntu 12.10 this time on 64 bit.

I used the 2.4.6.1 install script from this repository. The code builds correctly. I can read from the webcam, write to window, write to file, but any attempt to write video results in:

HIGHGUI ERROR: V4L2: Unable to get property (5) - Invalid argument OpenCV Error: Unsupported format or combination of formats (Gstreamer Opencv backend doesn't support this codec acutally.) in CvVideoWriter_GStreamer::open, file /home/ldodds/tmp/OpenCV/opencv-2.4.6.1/modules/highgui/src/cap_gstreamer.cpp, line 505

The first error seems to be related to trying to retrieve properties of the stream, but I think its unrelated to the encoding issue. The encoding passed to cv2.VideoWriter constructor is:

cv2.cv.CV_FOURCC('I','4','2','0')

I've attempted to use other formats and these all fail.

I've also tried adding WITH_FFMPEG=ON to the cmake command-line as this has been reported to help solve these issues elsewhere.

Any ideas on how to proceed? Both gstreamer and ffmpeg are installed and cmake appears to detect them correctly.

ldodds commented 10 years ago

Closing, I've tracked this down. For the record the issue wasn't with the encoding at all. The sample code I was using wasn't properly checking the return value of:

self._capture.get(cv2.cv.CV_CAP_PROP_FPS)

This appears to return -1 when this error is printed:

HIGHGUI ERROR: V4L2: Unable to get property (5) - Invalid argument

The sample code fell back to creating an estimate of the FPS but was only checking for zero not -1. This resulted in the call to cv2.VideoWriter having an fps of -1 which triggered the message about encodings.

I guess this is correct (gstreamer can't fix) but misleading as the error isn't with the local setup!