OpenCV(C ++):与输入相比,写入产生大文件 [英] OpenCV (C++): write produces big file compared to input

查看:72
本文介绍了OpenCV(C ++):与输入相比,写入产生大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV(C ++)读取视频文件,对每个帧应用过滤器,然后将新修改的帧写入输出文件.代码的关键部分是这些:

I am trying to read a video file using OpenCV (C++), apply a filter to each frame and write a new modified frame into an output file. The crucial parts of the code are these:

int out_format = CV_FOURCC('M','P','4','2');  // can be another one
double fps = media.get(CV_CAP_PROP_FPS),
       width = media.get(CV_CAP_PROP_FRAME_WIDTH),
       height = media.get(CV_CAP_PROP_FRAME_HEIGHT);

// On Linux FFMPEG is used to write videos
VideoWriter writer("./" + outputname + ".mkv", out_format, fps, Size(width, height) );
.......
.......
writer.write(newFrame); // Mat newFrame

事实是,我不熟悉编解码器和视频输出格式,因此我想知道为什么大约280 MB的文件会产生2 GB的输出.

The fact is, I am not proficient with codecs and video output formats, thus I would like to know why a file which is around 280 MB produces an output of 2 GB.

这是编解码器问题吗?我尝试过DIVX,MPEG等.此外,某些输出格式必须与特定的编解码器一起使用.

Is that a codec problem? I have tried DIVX, MPEG and others. Moreover, some output formats must go together with specific codecs.

推荐答案

尝试与.mp4容器一起使用'M','P','4','V'编解码器,即,将扩展名设置为您的文件名作为something.mp4

Try using the 'M','P', '4', 'V' codec with the .mp4 container, that is, set the extension to your filename as something.mp4

对于mp4容器,您还可以尝试MPEG,MJPG,FMP4

For the mp4 container, you could also try, MPEG, MJPG, FMP4

这篇关于OpenCV(C ++):与输入相比,写入产生大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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