简体   繁体   English

用opencv保存mp4

[英]Save mp4 with opencv

Why No video saved? 为什么没有保存视频?

    self.writer = cv.CreateVideoWriter("test1.mp4", cv2.cv.CV_FOURCC('M', 'J', 'P', 'G'), fps, frame_size, is_color )

    self.writer = cv.CreateVideoWriter("tsest3.mp4",cv.CV_FOURCC(*'H264'), fps, (320, 240), is_color )
    self.writer = cv.CreateVideoWriter("test4.mpg", cv.CV_FOURCC('P', 'I', 'M', '1'), fps, (320, 240), is_color )

I used WriteFrame too but still no file created or the size is 0kb. 我也使用WriteFrame,但是仍然没有创建文件,或者大小为0kb。

According to the OpenCV 2.4.11.0 documentation - 根据OpenCV 2.4.11.0文档 -

However, OpenCV is mainly a computer vision library, not a video stream, codec and write one. 但是,OpenCV主要是计算机视觉库,而不是视频流,编解码器和编写库。 Therefore, the developers tried to keep this part as simple as possible. 因此,开发人员试图使这一部分尽可能简单。 Due to this OpenCV for video containers supports only the avi extension, its first version. 由于此视频容器OpenCV仅支持avi扩展程序(第一个版本)。 A direct limitation of this is that you cannot save a video file larger than 2 GB. 直接限制是您不能保存大于2 GB的视频文件。

Workaround- 解决方法

As an alternative, create the video track with OpenCV and expand it with sound tracks or convert it to other formats by using video manipulation programs such as VirtualDub or AviSynth. 或者,使用OpenCV创建视频轨道,并使用声轨对其进行扩展,或者使用诸如VirtualDub或AviSynth之类的视频处理程序将其转换为其他格式。

Do read the complete section describing the structure of video files. 请阅读描述视频文件结构的完整部分。 Also have a look at https://stackoverflow.com/a/29746666/3681882 也可以看看https://stackoverflow.com/a/29746666/3681882

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

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