[Libav-user] Bitrate parameter ignored when writing videos

Masneri, Stefano stefano.masneri at brain.mpg.de
Wed Aug 10 16:35:57 EEST 2016

I am trying to write an .mp4 video with a specified bitrate and gopsize set to 1.
Apparently libavcodec ignores the settings I provide and creates a video with a much higher bitrate

Here's the code I use to setup the output video:

  m_pcVideoSt->codec->gop_size = m_iGopSize; /* emit one intra frame every m_iGopSize frames at most */
  m_pcVideoSt->codec->pix_fmt = AV_PIX_FMT_YUV420P; /* default pix_fmt */
  m_pcVideoSt->codec->max_b_frames = 1;
  AVDictionary* pcOpts = nullptr;
  int res1 = av_dict_set(&pcOpts, "b", "20k", 0);
  int res = avcodec_open2(m_pcVideoSt->codec, codec, &pcOpts);

m_pcVideoSt is of type AVStream*

This is the output of ffprobe ran on the video I wrote:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'testGray.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:20.00, start: 0.000000, bitrate: 8905 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x576, 8904 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
      handler_name    : VideoHandler

When watching the video, it seems that the quality is low for the first few frames, but then the quality gets much better (explaining the 8905Kb/s bitrate).
Any idea on what I am missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160810/fd102a18/attachment.html>

More information about the Libav-user mailing list