Creating AVI files in OpenCV

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.


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).


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.