用opencv保存mp4 [英] Save mp4 with opencv

查看:239
本文介绍了用opencv保存mp4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么没有保存视频?

    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 )

我也使用了 WriteFrame,但仍然没有创建文件或大小为 0kb.

I used WriteFrame too but still no file created or the size is 0kb.

推荐答案

根据 OpenCV 2.4.11.0 文档-

According to the OpenCV 2.4.11.0 documentation-

但是OpenCV主要是一个计算机视觉库,不是视频流,编解码器和写一个.因此,开发人员试图使这部分尽可能简单.由于这个用于视频容器的 OpenCV 仅支持 avi 扩展,它的第一个版本.这样做的一个直接限制是您不能保存大于 2 GB 的视频文件.

However, OpenCV is mainly a computer vision library, not a video stream, codec and write one. 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. A direct limitation of this is that you cannot save a video file larger than 2 GB.

解决方法-

或者,使用 OpenCV 创建视频轨道并使用音轨对其进行扩展,或者使用 VirtualDub 或 AviSynth 等视频处理程序将其转换为其他格式.

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.

请阅读描述视频文件结构的完整部分.另请查看 https://stackoverflow.com/a/29746666/3681882

Do read the complete section describing the structure of video files. Also have a look at https://stackoverflow.com/a/29746666/3681882

这篇关于用opencv保存mp4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆