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!
"The ffmpeg.dll is in the application folder" -- ok, but do you also start your application there ?
Hi, thanks for your reply. Yup! The dll is in with the exe, and all the other opencv dlls. MJPG works fine
FFMPEG build includes support for H264 encoder based on the OpenH264 library. OpenH264 Video Codec provided by Cisco Systems, Inc. See https://github.com/cisco/openh264/releases for details and OpenH264 license. OpenH264 library should be installed separatelly. Downloaded binary file can be placed into global system path (System32 or SysWOW64) or near application binaries (check documentation of "LoadLibrary" Win32 function from MSDN).
You need to download openh264 version 1.6 (opencv 3.2 and 3.3)
One more question though... Does H265 (HVEC) support exist ?
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.