2

I'm fairly new to transcoding.I've been generating some mp4's from mxf files. I've been playing around with some settings on ffmpeg and been specifying various bitrate's for audio and video with the -b:v and -b:a arguments. When I check the file after they have been created with mediainfo I notice that the audio bitrate displayed is always exactly the same I as specified, but video bitrate is different. For example, I specified -b:v 1500k but the video bitrate for file created when interrogated with mediainfo says 6 943 kb/s. I was just wondering why this is? Why is audio bitrate always the same as selected and not video? The full command is:

 ffmpeg -i mediafile.mxf -vcodec libx264 -crf 23 -b:v 1500k mediafile.mp4

The output is:

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
Guessed Channel Layout for  Input Stream #0.1 : mono
Guessed Channel Layout for  Input Stream #0.2 : mono
Guessed Channel Layout for  Input Stream #0.3 : mono
Guessed Channel Layout for  Input Stream #0.4 : mono
Input #0, mxf, from 'mediafile.mxf':
  Metadata:
    uid             : adab4424-2f25-4dc7-92ff-29bd000b0000
    generation_uid  : adab4424-2f25-4dc7-92ff-29bd000b0001
    company_name    : FFmbc
    product_name    : OP1a Muxer
    product_version : 53.6.0
    product_uid     : adab4424-2f25-4dc7-92ff-29bd000b0002
    modification_date: 2016-04-08 15:58:38
    material_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD200
    timecode        : 00:00:00:00
  Duration: 00:02:42.56, start: 0.000000, bitrate: 118682 kb/s
    Stream #0:0: Video: dvvideo, yuv422p, 1440x1080 [SAR 4:3 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
    Stream #0:2: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
    Stream #0:3: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
    Stream #0:4: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
File 'mediafile.mp4' already exists. Overwrite ? [y/N] y
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0xe3b9a0] using SAR=4/3
[libx264 @ 0xe3b9a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0xe3b9a0] profile High 4:2:2, level 4.0, 4:2:2 8-bit
[libx264 @ 0xe3b9a0] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'mediafile.mp4':
  Metadata:
    uid             : adab4424-2f25-4dc7-92ff-29bd000b0000
    generation_uid  : adab4424-2f25-4dc7-92ff-29bd000b0001
    company_name    : FFmbc
    product_name    : OP1a Muxer
    product_version : 53.6.0
    product_uid     : adab4424-2f25-4dc7-92ff-29bd000b0002
    modification_date: 2016-04-08 15:58:38
    material_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD200
    timecode        : 00:00:00:00
    encoder         : Lavf56.25.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv422p, 1440x1080 [SAR 4:3 DAR 16:9], q=-1--1, 1500 kb/s, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
      encoder         : Lavc56.26.100 libx264
    Stream #0:1: Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 48000 Hz, mono, s16, 128 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D0013D24E0A529471342FD24E0A00529471342FD201
      encoder         : Lavc56.26.100 libfaac
Stream mapping:
  Stream #0:0 -> #0:0 (dvvideo (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (libfaac))
Press [q] to stop, [?] for help
frame= 4064 fps= 22 q=-1.0 Lsize=  139476kB time=00:02:42.56 bitrate=7028.7kbits/s    
video:137744kB audio:1640kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.065406%
[libx264 @ 0xe3b9a0] frame I:72    Avg QP:21.59  size: 65595
[libx264 @ 0xe3b9a0] frame P:3978  Avg QP:24.85  size: 34252
[libx264 @ 0xe3b9a0] frame B:14    Avg QP:23.42  size:  5032
[libx264 @ 0xe3b9a0] consecutive B-frames: 99.3%  0.7%  0.0%  0.0%
[libx264 @ 0xe3b9a0] mb I  I16..4: 12.6% 85.9%  1.5%
[libx264 @ 0xe3b9a0] mb P  I16..4:  2.4% 25.6%  0.5%  P16..4: 44.5%  9.3%  5.3%  0.0%  0.0%    skip:12.5%
[libx264 @ 0xe3b9a0] mb B  I16..4:  0.2%  0.9%  0.0%  B16..8: 27.5%  0.5%  0.1%  direct: 1.0%  skip:69.9%  L0:41.2% L1:57.3% BI: 1.5%
[libx264 @ 0xe3b9a0] 8x8 transform intra:89.8% inter:88.5%
[libx264 @ 0xe3b9a0] coded y,uvDC,uvAC intra: 76.2% 60.7% 7.8% inter: 38.4% 53.3% 0.1%
[libx264 @ 0xe3b9a0] i16 v,h,dc,p:  5% 72%  3% 19%
[libx264 @ 0xe3b9a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 21% 35%  4%  4%  5%  4%  4%  5%
[libx264 @ 0xe3b9a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 57% 13%  3%  3%  3%  3%  2%  3%
[libx264 @ 0xe3b9a0] i8c dc,h,v,p: 55% 20% 21%  4%
[libx264 @ 0xe3b9a0] Weighted P-Frames: Y:3.7% UV:2.4%
[libx264 @ 0xe3b9a0] ref P L0: 43.9% 13.1% 26.1% 16.5%  0.4%
[libx264 @ 0xe3b9a0] ref B L0: 68.4% 31.6%
[libx264 @ 0xe3b9a0] kb/s:6941.41

Thanks

  • Show the command and full console output. – Gyan Feb 8 '17 at 11:38
  • Looks like you made two accounts (otherwise you could have edited the question without needing to wait for approval). See I accidentally created two accounts; how do I merge them?. – llogan Feb 8 '17 at 18:18
  • 1
    CRF and bitrate mode are exclusive, and x264 is using CRF here. Drop the former. Add -bufsize 1600k -maxrate 1600k – Gyan Feb 8 '17 at 19:55
1

The issue is that you are using -crf with -b:v. ffmpeg is a well built program, so it's just ignoring -b:v and using -crf. If you want to have a specific bitrate, remove the crf command.

CRF is "constant rate factor", which means a quality variable is specified then a variable bitrate is calculated based on the content. It's my favorite for h.264 because it usually comes out vey well.

Setting a constant bitrate works as expected. Compression will be nearly exactly what you entered, but quality may suffer for it. I never use it for h.264. I can't think of a use case where I would.

  • 1
    The answer by DigiVision Media resolved it for me, I was using -crf and -b:v as soon as i removed -crf the output bitrate was as set in the b:v paramater. (had to post as answer as cannot comment) – Sruli Dec 15 '17 at 12:23
0

The bitrate you specify is a target bitrate, not a guaranteed bitrate. There is no way to know exactly how large a frame will be until after its encoded. Going into a frame, its possible to be a little more or a little less aggressive on how much information you are willing to lose while encoding, but how information loss leads to data size reduction (data is not the same thing as information (AAAA and A4 both contain he same information (4 A's), but A4 is half the data)) is not 100% predictable. Encoders use something called rate control to achieve this. If the frames end up being slightly larger than expected, it will more aggressively loose information on the next frame. Since most people specify bitrate to target specific use cases (streaming over the internet for example) a lot of stream control algorithms err on the side of to low, as too high could cause issues like buffering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.