在Linux上使用FFmpeg从OpenCV

在Linux上使用FFmpeg从OpenCV

本文介绍了在Linux上使用FFmpeg从OpenCV 3编写x264的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过FFmpeg('X','2','6','4'" FOURCC)用OpenCV 3编写h264视频.到目前为止,我已经看过所有与SO相关的文章,但是没有任何帮助.代码:

I'm having trouble writing h264 video with OpenCV 3 via FFmpeg ("'X','2','6','4'" FOURCC). I've seen all the related posts so far on SO, but nothing helps. Code:

cv::VideoWriter writer(output_path.string(),    CV_FOURCC('X','2','6','4'), 60, frame_size);

输出:

生成的视频非常小(按字节)并且不可读.将four_cc设置为-1会导致FFmpeg产生未知标签",我没有收到其他人建议的选择编解码器的提示.

The resulting video is extremely small (byte-wise) and unreadable. Setting the four_cc to -1 results in "unknown tag" from FFmpeg, I don't get any prompt to choose codec as others suggested.

OpenCV 3文档状态:

The OpenCV 3 doc states:

他们所引用的页面没有列出h264/x264,并且我不确定如何解释该声明,因为中,似乎都将X.2.6.4列为适当的代码.实际上,使用H.2.6.4会得到相同的输出.

That page they refrence doesn't have h264 / x264 listed, and I'm not sure how to interpret that statement, since earlier SO posts seem to all list X.2.6.4 as the appropriate code. Using H.2.6.4 actually gives identical output.

有什么建议/解决方法吗?

Any suggestions / workarounds?

P.S. ffmpeg是Ubuntu维护者最新提供的文件,它列出了它是使用--enable-libx264

P.S. the ffmpeg is most up-to-date from Ubuntu maintainers, it lists that it was configured with --enable-libx264

编辑:我尝试使用mkv容器而不是mp4.关于不支持标签的警告消失了,但是仍无法读取结果视频.

I tried to use the mkv container instead of mp4. The warning about tag not being supported went away, but the resulting video is still unreadable.

推荐答案

问题与显示的警告无关.我正在尝试编写单通道图像,而VideoWriter期望使用3通道彩色图像(VideoColor的构造函数的第5个参数isColor的默认值为"true").解决方案是将isColor设置为false.

The problem had nothing to do with the displayed warning. I was trying to write single-channel images, while the VideoWriter was expecting a 3-channel color image (default value of isColor, the 5-th argument to VideoWriter's constructor, is "true"). The solution was setting isColor to false.

这篇关于在Linux上使用FFmpeg从OpenCV 3编写x264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!