[FFmpeg-user] output bitrate equal to expected bitrate

negin tebyani negin.tebyani at gmail.com
Thu Apr 13 16:25:37 EEST 2017


I am using this command to transcode my videos in ffmpeg:

ffmpeg -i 1_med.mp4 -movflags faststart -c:v libx264 -x264opts
'keyint=100:min-keyint=25:no-scenecut:8x8dct:sliced-threads=0' -deblock 1:1
-flags +loop -b:v 850k -maxrate 850k -bufsize 2000k -vf
"scale=-1280:720:flags=spline+full_chroma_inp+full_chroma_int+accurate_rnd+bitexact"
-acodec libfdk_aac -b:a 320k -coder 1 -me_range 16 -bf 10 -q:v 1 -qmin 0
-qmax 69 -trellis 2 -mbtree 1 -mixed-refs 1 -preset veryfast medfull.mp4


and here is the output of mediainfo:

Complete name                            : medToCheck.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom
File size                                : 79.0 MiB
Duration                                 : 10mn 0s
Overall bit rate mode                    : Variable
Overall bit rate                         : 1 104 Kbps
Writing application                      : Lavf56.25.101

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High at L3.1
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 10mn 0s
Bit rate                                 : 779 Kbps
Nominal bit rate                         : 850 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.034
Stream size                              : 55.7 MiB (71%)
Writing library                          : x264 core 142 r2495 6a301b6
Encoding settings                        : cabac=1 / ref=1 / deblock=1:1:1
/ analyse=0x3:0x113 / me=hex / subme=2 / psy=1 / psy_rd=1.00:0.00 /
mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 /
deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=4 /
lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 /
bluray_compat=0 / constrained_intra=0 / bframes=10 / b_pyramid=2 /
b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 /
keyint=100 / keyint_min=25 / scenecut=0 / intra_refresh=0 / rc_lookahead=10
/ rc=cbr / mbtree=1 / bitrate=850 / ratetol=1.0 / qcomp=0.60 / qpmin=0 /
qpmax=69 / qpstep=4 / vbv_maxrate=850 / vbv_bufsize=2000 / nal_hrd=none /
filler=0 / ip_ratio=1.40 / aq=1:1.00
Language                                 : English

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 10mn 0s
Bit rate mode                            : Variable
Bit rate                                 : 320 Kbps
Maximum bit rate                         : 850 Kbps
Channel count                            : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Delay relative to video                  : 80ms
Stream size                              : 22.9 MiB (29%)
Language                                 : English

and ffmpeg console output:

[root at vm1-108 FullVideoToTestOurCommand2]# ffmpeg -i 1_med.mp4 -movflags
faststart -c:v libx264 -x264opts
'keyint=100:min-keyint=25:no-scenecut:8x8dct:sliced-threads=0' -deblock 1:1
-flags +loop -b:v 850k -maxrate 850k -bufsize 2000k -vf
"scale=-1280:720:flags=spline+full_chroma_inp+full_chroma_int+accurate_rnd+bitexact"
-acodec libfdk_aac -b:a 320k -coder 1 -me_range 16 -bf 10 -q:v 1 -qmin 0
-qmax 69 -trellis 2 -mbtree 1 -mixed-refs 1 -preset veryfast -ss 00:00:00
-t 00:10:00 medToCheckNominalBitrateWithBufzieEqualToMaxrate.mp4
ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
  configuration: --prefix=/usr --bindir=/usr/bin
--datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg
--libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2
-g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches
-m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls
--enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394
--enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree
--disable-indev=jack --enable-libfreetype --enable-libgsm
--enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus
--enable-libpulse --enable-libschroedinger --enable-libsoxr
--enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2
--enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab
--enable-avfilter --enable-avresample --enable-postproc --enable-pthreads
--disable-static --enable-shared --enable-gpl --disable-debug
--disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1_med.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.52.100
  Duration: 01:08:51.20, start: 0.042667, bitrate: 810 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 741 kb/s, 25 fps, 25
tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
File 'medToCheckNominalBitrateWithBufzieEqualToMaxrate.mp4' already exists.
Overwrite ? [y/N] y
[libx264 @ 0x1c2cee0] -qscale is ignored, -crf is recommended.
[libx264 @ 0x1c2cee0] using SAR=1/1
[libx264 @ 0x1c2cee0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX AVX2 FMA3 BMI2
[libx264 @ 0x1c2cee0] profile High, level 3.1
[libx264 @ 0x1c2cee0] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec
- Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1
ref=1 deblock=1:1:1 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00
mixed_ref=0 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11
fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=1
sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0
constrained_intra=0 bframes=10 b_pyramid=2 b_adapt=1 b_bias=0 direct=1
weightb=1 open_gop=0 weightp=1 keyint=100 keyint_min=25 scenecut=0
intra_refresh=0 rc_lookahead=10 rc=cbr mbtree=1 bitrate=850 ratetol=1.0
qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=850 vbv_bufsize=2000
nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'medToCheckNominalBitrateWithBufzieEqualToMaxrate.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021),
yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=0-69, 850 kb/s, 25 fps, 12800 tbn,
25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: aac (libfdk_aac) ([64][0][0][0] / 0x0040),
48000 Hz, stereo, s16, 320 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc56.26.100 libfdk_aac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[mp4 @ 0x1c2be00] Starting second pass: moving the moov atom to the
beginning of the filerop=0
frame=15000 fps=158 q=-1.0 Lsize=   80894kB time=00:10:00.00
bitrate=1104.5kbits/s dup=1 drop=0
video:57061kB audio:23439kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.489798%
[libx264 @ 0x1c2cee0] frame I:150   Avg QP:11.96  size: 68404
[libx264 @ 0x1c2cee0] frame P:3087  Avg QP:17.97  size:  8810
[libx264 @ 0x1c2cee0] frame B:11763 Avg QP:17.67  size:  1783
[libx264 @ 0x1c2cee0] consecutive B-frames:  8.3%  0.9%  0.9%  0.9%  1.6%
28.5% 31.9%  3.4%  2.9%  2.3% 18.3%
[libx264 @ 0x1c2cee0] mb I  I16..4: 28.7% 29.4% 42.0%
[libx264 @ 0x1c2cee0] mb P  I16..4: 11.5%  3.8%  0.4%  P16..4: 31.8%  7.8%
 3.4%  0.0%  0.0%    skip:41.4%
[libx264 @ 0x1c2cee0] mb B  I16..4:  0.4%  0.1%  0.0%  B16..8:  7.4%  1.3%
 0.1%  direct:12.1%  skip:78.6%  L0:49.2% L1:44.4% BI: 6.4%
[libx264 @ 0x1c2cee0] 8x8 transform intra:24.3% inter:26.3%
[libx264 @ 0x1c2cee0] coded y,uvDC,uvAC intra: 24.7% 47.8% 14.8% inter:
2.6% 18.2% 0.3%
[libx264 @ 0x1c2cee0] i16 v,h,dc,p: 55% 26% 14%  5%
[libx264 @ 0x1c2cee0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 31% 32%  2%  1%
 1%  2%  1%  2%
[libx264 @ 0x1c2cee0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 29% 13%  4%  5%
 4%  6%  5%  4%
[libx264 @ 0x1c2cee0] i8c dc,h,v,p: 57% 22% 18%  3%
[libx264 @ 0x1c2cee0] Weighted P-Frames: Y:8.6% UV:7.4%
[libx264 @ 0x1c2cee0] kb/s:779.06


I need the bitrate to be constant and equal to the one specified (-b:v).
after transcoding and using mediainfo, I see that there is a bitrate (which
is lower that what I specified) and a nominal bitrate that is equal to
expected bitrate.

how can I fix this issue??


More information about the ffmpeg-user mailing list