[FFmpeg-user] Actual bitrate is lower than target

Wesley Wen delbin.wen at gmail.com
Tue Jul 14 23:00:48 CEST 2015


Hi,

We transcoded source file to multiple resolution/bitrate in order to create
adaptive stream. One of the profile is 7M bps and we tried to encode it as
near CBR.

We prepared one FFmpeg command and it worked quite well for most content.
However, for some content, the actual bitrate of encoded file is way
smaller than target 7M bps, say 4M bps.

Here is the probe info of source file:
ffprobe video.ts
ffprobe version git-2015-07-14-b90b6af Copyright (c) 2007-2015 the FFmpeg
developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM
3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-ffplay --enable-libfdk-aac --enable-libx265 --enable-nonfree
--enable-vda
  libavutil      54. 28.100 / 54. 28.100
  libavcodec     56. 48.100 / 56. 48.100
  libavformat    56. 40.100 / 56. 40.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 21.100 /  5. 21.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegts, from 'video.ts':
  Duration: 00:01:10.44, start: 0.215811, bitrate: 36361 kb/s
  Program 1
    Stream #0:0[0x1000]: Video: mpeg2video (High) ([2][0][0][0] / 0x0002),
yuv420p(tv, bt709), 1440x1080 [SAR 4:3 DAR 16:9], 35000 kb/s, 29.97 fps,
29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x1001]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, s16p, 384 kb/s

We used 2-pass transcoding, and here are the console output of both passes.
ffmpeg -y -i /tmp/video.ts -dn -sn -an -threads 0 -map 0 -c:v libx264 -b:v
7000k -vsync 1 -pix_fmt yuv420p -profile:v high -level 3.1 -g 29.9002997
-rc-lookahead 40 -refs 4 -muxdelay 0 -pass 1 -maxrate 7000k -bufsize 10500k
-bf 0 -x264opts
stitchable:scenecut=0:me=umh:merange=32:subme=11:direct=auto:qcomp=0:ratetol=0.1
-vf yadif,scale="trunc(oh*dar/2)*2:720" -f mp4 /dev/null
ffmpeg version git-2015-07-14-b90b6af Copyright (c) 2000-2015 the FFmpeg
developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM
3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-ffplay --enable-libfdk-aac --enable-libx265 --enable-nonfree
--enable-vda
  libavutil      54. 28.100 / 54. 28.100
  libavcodec     56. 48.100 / 56. 48.100
  libavformat    56. 40.100 / 56. 40.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 21.100 /  5. 21.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegts, from '/tmp/video.ts':
  Duration: 00:01:10.44, start: 0.215811, bitrate: 36361 kb/s
  Program 1
    Stream #0:0[0x1000]: Video: mpeg2video (High) ([2][0][0][0] / 0x0002),
yuv420p(tv, bt709), 1440x1080 [SAR 4:3 DAR 16:9], 35000 kb/s, 29.97 fps,
29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x1001]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, s16p, 384 kb/s
[libx264 @ 0x7ff1e8816e00] using SAR=1/1
[libx264 @ 0x7ff1e8816e00] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7ff1e8816e00] profile Main, level 3.1
[libx264 @ 0x7ff1e8816e00] 264 - core 146 r2538 121396c - H.264/MPEG-4 AVC
codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options:
cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0 me=umh subme=9 psy=1
psy_rd=1.00:0.00 mixed_ref=0 me_range=32 chroma_me=1 trellis=0 8x8dct=0
cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6
lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
bluray_compat=0 stitchable=1 constrained_intra=0 bframes=0 weightp=2
keyint=30 keyint_min=3 scenecut=0 intra_refresh=0 rc_lookahead=40 rc=cbr
mbtree=1 bitrate=7000 ratetol=0.1 qcomp=0.00 qpmin=0 qpmax=69 qpstep=4
vbv_maxrate=7000 vbv_bufsize=10500 nal_hrd=none filler=0 ip_ratio=1.40
aq=1:1.00
Output #0, mp4, to '/dev/null':
  Metadata:
    encoder         : Lavf56.40.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p,
1280x720 [SAR 1:1 DAR 16:9], q=-1--1, pass 1, 7000 kb/s, 29.97 fps, 30k
tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc56.48.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 2111 fps= 79 q=-1.0 Lsize=   26247kB time=00:01:10.43
bitrate=3052.6kbits/s
video:26237kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.037053%
[libx264 @ 0x7ff1e8816e00] frame I:71    Avg QP: 2.19  size: 46261
[libx264 @ 0x7ff1e8816e00] frame P:2040  Avg QP: 2.51  size: 11560
[libx264 @ 0x7ff1e8816e00] mb I  I16..4: 86.1%  0.0% 13.9%
[libx264 @ 0x7ff1e8816e00] mb P  I16..4:  3.3%  0.0%  0.0%  P16..4: 12.6%
 0.0%  0.0%  0.0%  0.0%    skip:84.1%
[libx264 @ 0x7ff1e8816e00] coded y,uvDC,uvAC intra: 30.0% 30.0% 27.7%
inter: 7.1% 6.6% 4.2%
[libx264 @ 0x7ff1e8816e00] i16 v,h,dc,p: 78% 11%  4%  7%
[libx264 @ 0x7ff1e8816e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 15% 13%  9%
10%  7% 11%  8% 11%
[libx264 @ 0x7ff1e8816e00] i8c dc,h,v,p: 72%  7% 15%  6%
[libx264 @ 0x7ff1e8816e00] Weighted P-Frames: Y:2.5% UV:1.3%
[libx264 @ 0x7ff1e8816e00] kb/s:3051.35

ffmpeg -y -i /tmp/video.ts -dn -sn -an -threads 0 -map 0 -c:v libx264 -b:v
7000k -vsync 1 -pix_fmt yuv420p -profile:v high -level 3.1 -g 29.9002997
-rc-lookahead 40 -refs 4 -muxdelay 0 -pass 2 -maxrate 7000k -bufsize 10500k
-bf 0 -x264opts
stitchable:scenecut=0:me=umh:merange=32:subme=11:direct=auto:qcomp=0:ratetol=0.1
-vf yadif,scale="trunc(oh*dar/2)*2:720" output.mp4
ffmpeg version git-2015-07-14-b90b6af Copyright (c) 2000-2015 the FFmpeg
developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM
3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-ffplay --enable-libfdk-aac --enable-libx265 --enable-nonfree
--enable-vda
  libavutil      54. 28.100 / 54. 28.100
  libavcodec     56. 48.100 / 56. 48.100
  libavformat    56. 40.100 / 56. 40.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 21.100 /  5. 21.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegts, from '/tmp/video.ts':
  Duration: 00:01:10.44, start: 0.215811, bitrate: 36361 kb/s
  Program 1
    Stream #0:0[0x1000]: Video: mpeg2video (High) ([2][0][0][0] / 0x0002),
yuv420p(tv, bt709), 1440x1080 [SAR 4:3 DAR 16:9], 35000 kb/s, 29.97 fps,
29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x1001]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, s16p, 384 kb/s
[libx264 @ 0x7f948a822800] using SAR=1/1
[libx264 @ 0x7f948a822800] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7f948a822800] target: 7000.00 kbit/s, expected: 4523.40
kbit/s, avg QP: 11.9682
[libx264 @ 0x7f948a822800] profile High, level 3.1
[libx264 @ 0x7f948a822800] 264 - core 146 r2538 121396c - H.264/MPEG-4 AVC
codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options:
cabac=1 ref=4 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=9 psy=1
psy_rd=1.00:0.00 mixed_ref=1 me_range=32 chroma_me=1 trellis=1 8x8dct=1
cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6
lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
bluray_compat=0 stitchable=1 constrained_intra=0 bframes=0 weightp=2
keyint=30 keyint_min=3 scenecut=0 intra_refresh=0 rc_lookahead=40 rc=2pass
mbtree=1 bitrate=7000 ratetol=0.1 qcomp=0.00 qpmin=0 qpmax=69 qpstep=4
cplxblur=20.0 qblur=0.5 vbv_maxrate=7000 vbv_bufsize=10500 nal_hrd=none
filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf56.40.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p,
1280x720 [SAR 1:1 DAR 16:9], q=-1--1, pass 2, 7000 kb/s, 29.97 fps, 30k
tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc56.48.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 2111 fps= 50 q=-1.0 Lsize=   29221kB time=00:01:10.43
bitrate=3398.5kbits/s
video:29211kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.033448%
[libx264 @ 0x7f948a822800] frame I:71    Avg QP: 1.80  size: 48058
[libx264 @ 0x7f948a822800] frame P:2040  Avg QP: 2.04  size: 12990
[libx264 @ 0x7f948a822800] mb I  I16..4: 84.4%  6.9%  8.7%
[libx264 @ 0x7f948a822800] mb P  I16..4:  1.9%  0.7%  0.6%  P16..4:  6.9%
 2.6%  2.3%  0.0%  0.0%    skip:84.9%
[libx264 @ 0x7f948a822800] 8x8 transform intra:14.5% inter:44.0%
[libx264 @ 0x7f948a822800] coded y,uvDC,uvAC intra: 30.5% 31.1% 29.7%
inter: 6.4% 6.7% 4.2%
[libx264 @ 0x7f948a822800] i16 v,h,dc,p: 88%  6%  2%  4%
[libx264 @ 0x7f948a822800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 21% 16%  6%
 6%  5%  9%  5%  6%
[libx264 @ 0x7f948a822800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 19% 16%  6%
 9%  6%  8%  6%  8%
[libx264 @ 0x7f948a822800] i8c dc,h,v,p: 72%  7% 15%  6%
[libx264 @ 0x7f948a822800] Weighted P-Frames: Y:2.5% UV:1.3%
[libx264 @ 0x7f948a822800] ref P L0: 57.3%  6.6% 18.4% 13.2%  4.4%  0.1%
[libx264 @ 0x7f948a822800] kb/s:3397.26

I do notice the line, "target: 7000.00 kbit/s, expected: 4523.40 kbit/s,
avg QP: 11.9682", but I don't know the cause. And if we want to make the
transcoded file size close to 7M bps, how could we do?

Most source files are encoded as 1440x1080 35M bps, and same FFmpeg command
is applied. However, just some of them have this issue.

Thanks,
Wesley


More information about the ffmpeg-user mailing list