openCV cvCreateVideoWriter always returns null

南笙酒味 提交于 2019-12-06 16:25:35

This will depend on how your OpenCV library was configured. In particular I believe HAVE_FFMPEG must be defined in order for the 'IYUV' FOURCC value to be handled. Was your library built with HAVE_FFMPEG defined?

The default writer object (which is created when fourcc is zero, or the fourcc value is not handled by one of the available handlers) creates an image file per frame. In this case the filename needs to be something like "file%04d.foo" or "file0001.foo", otherwise writer creation fails. You might try passing something like "test0001.png" for the filename parameter as an experiment to verify that the default image writer is created successfully (this won't help directly, but might be a way to confirm that your fourcc value is not being recognized by an available writer.)

According to documentation, the option to open a selection dialog when the fourcc equal -1 is Windows-specific.

I read your post, Lance's reply and your comments to it, then finally found workaround for myself and decided to add some notes for everyone struggling with that issue.

First thing to check is whether CMake has built OpenCV with FFmpeg. My fast and horrible way to do this is just to run cmake with flags and parameters, as you wrote them during installation, again. In the end of output there will be logs about which components will be installed. If your parameters copy those used during the actual installation, you'll get info about what is already installed.

Next you may want to check available encoders and decoders for codecs on your linux system. I do this by using ffmpeg -codecs.

Third note is reliable and primitive arguments set for cvCreateVideoWriter:

"a0000.png", 0, fps, size, 0

fps and size here are variables containing your values for fps and frame_size fields respectively. You'll get bags of images -- what Lance Richardson and rics already noted.

Finally, for my system, on which OpenCV is built with FFmpeg and XVID encoder is installed, I plug these arguments into cvCreateVideoWriter:

"/home/me/openCVOut/a.avi", CV_FOURCC('X','V','I','D'), fps, size

and finally get what I want.

Hope my answer is of some use!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!