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

asked 2017-09-13 07:30:57 -0500

antithing gravatar image

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!

edit retag flag offensive close merge delete

Comments

"The ffmpeg.dll is in the application folder" -- ok, but do you also start your application there ?

berak gravatar imageberak ( 2017-09-13 07:40:46 -0500 )edit

Hi, thanks for your reply. Yup! The dll is in with the exe, and all the other opencv dlls. MJPG works fine

antithing gravatar imageantithing ( 2017-09-13 07:42:20 -0500 )edit
2

AH, I'm an idiot. I must have had the wrong cv dlls in the folder. Re-copying them from the ffmpeg.enabled build folder has fixed this.

antithing gravatar imageantithing ( 2017-09-13 07:46:52 -0500 )edit

One more question though... Does H265 (HVEC) support exist ?

antithing gravatar imageantithing ( 2017-09-13 07:47:33 -0500 )edit