<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<br>
<div>
<div dir="ltr">
<div dir="ltr">> 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.</div>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">I had similar problems and I found that the problem was my video stream time_base.<br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">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:<br>
<br>
<div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal; font-size: 14px; line-height: 21px;">
<span><span style="color: rgb(220, 220, 170);">av_packet_rescale_ts</span><span>(</span><span style="color: rgb(156, 220, 254);">pkt_</span><span>,
</span><span style="color: rgb(156, 220, 254);">vc_</span><span>-></span><span style="color: rgb(156, 220, 254);">time_base</span><span>,
</span><span style="color: rgb(156, 220, 254);">vs_</span><span>-></span><span style="color: rgb(156, 220, 254);">time_base</span><span>);</span></span><br>
<span><span></span><span style="color: rgb(220, 220, 170);">av_interleaved_write_frame</span><span>(</span><span style="color: rgb(156, 220, 254);">oc_</span><span>,
</span><span style="color: rgb(156, 220, 254);">pkt_</span><span>);</span></span></div>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">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.<br>
<br>
The problem was more evident when encoding with videotoolbox on macOS that has a fixed bitrate mode.<br>
</div>
</div>
</body>
</html>