title: How to set buffer size when encoding video?
body: <p>I use the following code to encode an incoming h264 stream:</p>
  
  <pre><code>int ret;
  ffmpeg::AVDictionary *opts2 = NULL;
  av_dict_set(&amp;opts2, "preset", "medium", 0);
  av_dict_set(&amp;opts2, "crf", "29", 0);
  av_dict_set(&amp;opts2, "profile", "baseline", 0);
  av_dict_set(&amp;opts2, "level", "30", 0);
  av_dict_set(&amp;opts2, "maxrate", "200000", 0);
  av_dict_set(&amp;opts2, "minrate", "0", 0);
  av_dict_set(&amp;opts2, "bufsize", "2000000", 0);
  
  ffmpeg::AVOutputFormat* fmt = ffmpeg::av_guess_format("mpeg", NULL, NULL);
  // Open the context
  //---------------------------------------------------------------------
  outFormatCtx = ffmpeg::avformat_alloc_context();
  if (!outFormatCtx)
  {
      return false;
  }
  
  //Set the output format
  //----------------------------------------------------------------------
  outFormatCtx-&gt;oformat = fmt;
  
  // Open the output file
  //-------------------------------------
  if (!(outFormatCtx-&gt;flags &amp; AVFMT_NOFILE))
  {
      ret = ffmpeg::avio_open2(&amp;outFormatCtx-&gt;pb, "Record.avi", AVIO_FLAG_WRITE, NULL, NULL);
      if (ret &lt; 0)
      {
          return false;
      }
  }
  // Create the output stream
  // -------------------------------------
  ffmpeg::AVStream* out_stream = ffmpeg::avformat_new_stream(outFormatCtx, inputStream-&gt;codec-&gt;codec);
  if (!out_stream) 
  {
      return false;
  }
  
  //Set the stream parameters
  //-------------------------------------
  ret = ffmpeg::avcodec_copy_context(out_stream-&gt;codec, inputStream-&gt;codec);
  if (ret &lt; 0) 
  {
      return false;
  }
  
  // Check then setup for global headers
  //-------------------------------------
  if (outFormatCtx-&gt;oformat-&gt;flags &amp; AVFMT_GLOBALHEADER)
      out_stream-&gt;codec-&gt;flags |= CODEC_FLAG_GLOBAL_HEADER;
  
  av_dump_format(outFormatCtx, 0, "Record.avi", 1);
  
  
  
  //Write the header
  //--------------------------------------
  ret = ffmpeg::avformat_write_header(outFormatCtx, &amp;opts2);
  if (ret &lt; 0) 
  {
      return false;
  }
  </code></pre>
  
  <p>However I always get the warning: </p>
  
  <pre><code>"VBV buffer size not set, using default size of 130KB\n"                      
  "If you want the mpeg file to be compliant to some specification\n"                      
  "Like DVD, VCD or others, make sure you set the correct buffer size\n"
  </code></pre>
  
  <p>I have tried very hard, but how could I set this VBV buffer size?</p>