Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OPenCv VideoWriter, can only use MJPG for some reason...

I am trying to write a video file from a camera stream. My code is:

writer = new VideoWriter();
                Size *s = new Size((int)frameBlank.cols, frameBlank.rows);
                writer->open("Facerecord.avi", CV_FOURCC('M', 'J', 'P', 'G'), 60, *s, true);        

                if (!writer->isOpened())
                {
                    std::cout << "Error: Failed to write the video" << std::endl;

                }

                bRecFirst = true;
            }

            writer->write(frameBlank);

... then to stop recording

if (writer->isOpened())
            {
                writer->release();

            }

If I use :

writer->open("Facerecord.avi", CV_FOURCC('M', 'J', 'P', 'G'), 60, *s, true);

This works great. But when i try:

writer->open("Facerecord.mp4", CV_FOURCC('H', '2', '6', '4'), 60, *s, true);

or

writer->open("Facerecord.mp4", CV_FOURCC('D', 'I', 'V', 'X'), 60, *s, true);

It creates a 0kb file.

I have installed DIVX, and the K-Lite codec pack, yet when i use:

writer->open("Facerecord.avi", CV_FOURCC_PROMPT, 60, *s, true);

and it pops up a 'choose codec' window, i only see the 4 default windows codecs listed. How can I write a video using external codecs?

(I have opencv 3.2, built from source, with ffmpeg support. The ffmpeg.dll is in the application folder)

thanks!