简体   繁体   English

OpenCV:对于 mp4 文件,保存电影作品但编解码器错误

[英]OpenCV: for mp4 files, saving movie works but with wrong codec

I am making a video editor in Python with OpenCV, and testing different combinations of codecs and file formats.我正在使用 OpenCV 在 Python 中制作视频编辑器,并测试编解码器和文件格式的不同组合。 For this example, I'm focusing on avi and mp4 formats.对于这个例子,我主要关注avimp4格式。 I have tried multiple different four-character codecs ( http://www.fourcc.org/codecs.php ) and they all saved an actual movie I can play.我尝试了多种不同的四字符编解码器( http://www.fourcc.org/codecs.php ),它们都保存了我可以播放的实际电影。

The confusing things is when I reload them and extract the codec from the movie, it turns out that only the movie saved as avi seems to have been saved using the original codec.令人困惑的是,当我重新加载它们并从电影中提取编解码器时,结果发现只有保存为avi的电影似乎是使用原始编解码器保存的。 Below I have a chart showing the codec used for encoding (created using cv2.VideoWriter_fourcc() ), and then the corresponding codec extracted from the video after loading it later (extracted using get(cv2.CAP_PROP_FOURCC) ).下面我有一个图表显示用于编码的编解码器(使用cv2.VideoWriter_fourcc()创建),然后在稍后加载视频后从视频中提取相应的编解码器(使用get(cv2.CAP_PROP_FOURCC)提取)。 I also am putting the size in MB in parentheses.我还将 MB 的大小放在括号中。

For avi (encoded -> extracted):对于 avi(编码 -> 提取):

MJPG -> MJPG (3.9)
FFV1 -> FFV1 (12.3)
DIVX -> DIVX (0.7)

For mp4:对于 mp4:

MJPG -> mp4v (3.9)
FFV1 -> avc1 (26.1)
DIVX -> mp4v (0.7)

So you can see that the encoding does not match for the mp4 file types, even though the file sizes roughly match up.因此,您可以看到编码与 mp4 文件类型不匹配,即使文件大小大致匹配。 The videos all look pretty much the same for avi versus mp4. avi 和 mp4 的视频看起来都差不多。

Is this metadata from the loaded movies not trustworthy for mp4, is the encoding not working for mp4 so it is picking a default, or something else?来自加载电影的元数据对于 mp4 是否不可信,编码是否对 mp4 不起作用,所以它选择了默认值,还是其他什么?

Most probably you try to use combination of codec (how the video content is compressed) and container (the actual file format used to transport the compressed video (and usually audio, subtitiles,...) that are not compatible.很可能您尝试使用不兼容的编解码器(如何压缩视频内容)和容器(用于传输压缩视频(通常是音频、字幕等)的实际文件格式)的组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM