0

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

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.

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

diningphil
  • 416
  • 5
  • 18
  • Can you check what is the encoding format and bitrate of the input video? – Steeve Feb 01 '17 at 10:32
  • The bitrate appears to be 23.67 and the fourcc of the input is AVC1 – diningphil Feb 01 '17 at 10:52
  • Can you try calling `writer.set(VIDEOWRITER_PROP_QUALITY, 0.1);` before write? Default setting seems to be 100% quality according to [this](http://docs.opencv.org/trunk/d4/d15/group__videoio__flags__base.html#gga41c5cfa7859ae542b71b1d33bbd4d2b4a1cc2ab47f60a115ff9624ff71715b93b). – Steeve Feb 01 '17 at 10:59
  • I have just tried, but it has no effects on the final result. – diningphil Feb 01 '17 at 11:55
  • Maybe the codec doesn't support setting encoding quality this way, if you can experiment with trying other codecs (x264 maybe?) – Steeve Feb 01 '17 at 11:57

1 Answers1

0

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

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

Shawn Mathew
  • 2,198
  • 1
  • 14
  • 31