title: Formula for calculating FFmpeg Minrate, Maxrate, and Bufsize?
body: <p>I'm looking for some kind of formula where I could put in the desired bitrate <code>-b:v</code> and have it calculate a good quality <code>-minrate</code>, <code>-maxrate</code>, and <code>-bufsize</code> for any video.</p>
  
  <p>So if a video's original bitrate is <code>8M</code> <code>8000K</code>, and you want to convert it to <code>2M</code> <code>2000K</code>, what should the <code>min/max/buf</code> be?</p>
  
  <p>Right now I have to guess and it always comes out pixelated unless I set the <code>-maxrate</code> and <code>-bufsize</code> really high.</p>
  
  <hr>
  
  <p>Using <code>-pix_fmt yuv420p</code>.</p>
  
  <hr>
  
  <h2>One-Pass / Two-Pass</h2>
  
  <p><strong>Desired (Pixelated)</strong></p>
  
  <p><code>ffmpeg -i input -c:v libx264 -b:v 2M -minrate 1M -maxrate 2M -bufsize 2M output.mkv</code></p>
  
  <p><strong>High Quality (Min/Maxrate)</strong></p>
  
  <p><code>ffmpeg -i input -c:v libx264 -b:v 2M -minrate 1M -maxrate 6M -bufsize 6M output.mkv</code></p>
  
  <p><strong>High Quality (No Min/Maxrate)</strong></p>
  
  <p><code>ffmpeg -i input -c:v libx264 -b:v 2M output.mkv</code></p>
  
  <hr>
  
  <h2>CRF</h2>
  
  <p>I notice in <code>CRF</code> sets the <code>maxrate</code> almost as high as the original video's bitrate, then lowers it for frames that are not as complex. The video come out very high quality and low file size.</p>
  
  <p><strong>Desired (Pixelated)</strong></p>
  
  <p><code>ffmpeg -y -i input -c:v libx264 -crf 20 -minrate 1M -maxrate 2M -bufsize 2M output.mkv</code></p>
  
  <p><strong>High Quality</strong></p>
  
  <p><code>ffmpeg -y -i input -c:v libx264 -crf 20 output.mkv</code></p>