6

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.

Ove
  • 6,227
  • 2
  • 39
  • 68

3 Answers3

21

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

SuperPro
  • 454
  • 2
  • 6
  • I have tried, and none of them work. Same thing: cvCreateVideoWriter does not return NULL, and I get a 0kb AVI file – Ove Jul 16 '09 at 12:14
  • 6
    Where did you get this list? Is there a way to generate one programmatically? – Dav Clark May 01 '11 at 22:53
  • 1
    I used cv.CV_FOURCC('i','Y', 'U', 'V') and and it worked for me... Using Windows 7 with Python 2.7 and OpenCV 2.2 (None of the ones in the above list worked for me) – hjweide Aug 13 '12 at 07:17
3

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.

aliassaila
  • 83
  • 1
  • 4
1

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.

Ove
  • 6,227
  • 2
  • 39
  • 68