Ask Your Question
0

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

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

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 -0600 )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 -0600 )edit
2

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

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

Hi antithing, May you show me your solution? I'm working on Linux and I got the same error like you. I able to write *.avi too. But not *mp4. I downloaded libopenh264-1.6.0-linux32.3.so file and copy to /lib/ folder but the output is still empty.

ToanVnET gravatar imageToanVnET ( 2020-02-16 21:42:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-13 07:46:52 -0600

antithing gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-13 07:30:57 -0600

Seen: 7,894 times

Last updated: Sep 13 '17