[Libav-user] Filesize difference between using ffmpeg command line and C API

Gabriele Greco gabriele.greco at hudl.com
Wed Apr 7 15:49:00 EEST 2021

> Still investigating the problem, by constraining my application with -qmin=10 -qmax=10, and doing the same using ffmpeg command line I have the exact same bitrate and file size.

I had similar problems and I found that the problem was my video stream time_base.

When you call avformat_write_header() avformat silently change your stream time_base to some values that it likes, so you cannot assume that the video stream time_base was the one you have configured on the stream creation but you need to do before encoding every frame:

av_packet_rescale_ts(pkt_, vc_->time_base, vs_->time_base);
av_interleaved_write_frame(oc_, pkt_);

if you don't do that x264 (and other encoders) will think that the frame duration is different from the real one and will behave accordingly.

The problem was more evident when encoding with videotoolbox on macOS that has a fixed bitrate mode.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210407/1ebec168/attachment.html>

More information about the Libav-user mailing list