Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating AVI files in OpenCV

Tags:

opencv

video

I have been trying to create an application using OpenCV and Visual Studio 2008, to capture images from a webcam, apply a filter to them, and then write them to an AVI file. Everything works, except creating the AVI file.

The problem is that it works on my computer, but it doesn't work on my colleague's computer. The reason for that (I think) is that he does not have the necessary video encoders for OpenCV to use.

The cvCreateVideoWriter function does not return NULL, but I end up with a 0kb file on the disk.

like image 568
Ove Avatar asked Jul 16 '09 11:07

Ove


3 Answers

Why not testing all codecs, in order to play save:

CV_FOURCC('P','I','M','1')    = MPEG-1 codec

CV_FOURCC('M','J','P','G')    = motion-jpeg codec (does not work well)

CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec

CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec

CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec

CV_FOURCC('U', '2', '6', '3') = H263 codec

CV_FOURCC('I', '2', '6', '3') = H263I codec

CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec

A codec code of -1 will open a codec selection window (in windows).

like image 88
SuperPro Avatar answered Oct 27 '22 03:10

SuperPro


In OpenCV 3.0.0, the readme.txt for ffmpeg says

"There is also our self-contained motion jpeg codec, which you can use without any worries. It handles CV_FOURCC('M', 'J', 'P', 'G') streams within an AVI container (".avi")."

(sources\3rdparty\ffmpeg\readme.txt)

-1 and cv::VideoWriter::fourcc('M', 'J', 'P', 'G') are the only options that work for me on Windows 8.1.

like image 3
aliassaila Avatar answered Oct 27 '22 02:10

aliassaila


The problem was that my colleague had an older version of OpenCV installed. If I used the new OpenCV it had an encoder and it did all the work.

like image 1
Ove Avatar answered Oct 27 '22 01:10

Ove