Media (Intel® oneAPI Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools from Intel. This includes Intel® oneAPI Video Processing Library and Intel® Media SDK.
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

setting LA_ICQ and CQP parameters within ffmpeg?


I'm attempting to benchmark (or just play around with) some of the different ratecontrol methods in the h264_qsv encoder.  I'm able to use the minrate/maxrate/b:v parameters to change the final bitrate for modes that take those parameters, but I have not been able to determine which set of command line options actually impact the CQP/LA_ICQ/ICQ rate control selection?

If I use:

-global_quality 5 -c:v h264_qsv  -look_ahead 1 -look_ahead_depth 100 

I get LA_ICQ as the rate control method, but I cannot find any parameter that will change the actual rate control/quality that is used.  On my machine, this mode *invariably* results in an exceptionally high bitrate (hundreds of megabits / second!!!).  Changing the value of global_quality makes no difference.

If I set -look_ahead 0, the RateControlMethod changes to "ICQ" and the value of "global_quality" adjusts the bitrate (similar to -crf XX in the libx264 encoder)

If I use -global_quality 10 -c:v h264_qsv -qscale 20 -look_ahead 0  this results in CQP being selected as the rate control method, but again I can't figure out what parameters to pass via the command line to actually modify the quality/bitrate that the encoder chooses to use.


[lwobker:/dtop]$ ffmpeg -y -v verbose -i input.mp4 -global_quality 50 -c:v h264_qsv -look_ahead 1 -look_ahead_depth 10 output-global_qual3-crf20.mp4 ffmpeg version N-81045-g450cf40 Copyright (c) 2000-2016 the FFmpeg developers

  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 50.100 / 57. 50.100
  libavformat    57. 42.100 / 57. 42.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100



[lwobker:/dtop]$ ffmpeg -hide_banner -y -v verbose -i input.mp4 -t 15 -global_quality 10 -c:v h264_qsv -q:v 20 -look_ahead 0  output.mp4
[h264 @ 00000000024f4b60] Reinit context to 1920x1088, pix_fmt: yuvj420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.42.100
  Duration: 00:00:15.02, start: 0.000000, bitrate: 10144 kb/s
    Stream #0:0(eng): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 10138 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
      handler_name    : VideoHandler
      timecode        : 16:11:08:04
    Stream #0:1(eng): Data: none (tmcd / 0x64636D74), 0 kb/s
      handler_name    : TimeCodeHandler
      timecode        : 16:11:08:04
[graph 0 input from stream 0:0 @ 00000000024e2620] w:1920 h:1080 pixfmt:yuvj420p tb:1/60000 fr:60000/1001 sar:1/1 sws_param:flags=2
[auto-inserted scaler 0 @ 0000000000d29d20] w:iw h:ih flags:'bicubic' interl:0
[format @ 0000000000d29560] auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed_null_0' and the filter 'format'
[swscaler @ 0000000002517200] deprecated pixel format used, make sure you did set range correctly
[auto-inserted scaler 0 @ 0000000000d29d20] w:1920 h:1080 fmt:yuvj420p sar:1/1 -> w:1920 h:1080 fmt:nv12 sar:1/1 flags:0x4
[h264_qsv @ 0000000000d2e340] Initialized an internal MFX session using hardware accelerated implementation
[h264_qsv @ 0000000000d2e340] Using the constant quantization parameter (CQP) ratecontrol method
[h264_qsv @ 0000000000d2e340] profile: high; level: 42
[h264_qsv @ 0000000000d2e340] GopPicSize: 250; GopRefDist: 4; GopOptFlag: closed ; IdrInterval: 0
[h264_qsv @ 0000000000d2e340] TargetUsage: 4; RateControlMethod: CQP
[h264_qsv @ 0000000000d2e340] QPI: 0; QPP: 0; QPB: 1
[h264_qsv @ 0000000000d2e340] NumSlice: 1; NumRefFrame: 2
[h264_qsv @ 0000000000d2e340] RateDistortionOpt: OFF
[h264_qsv @ 0000000000d2e340] RecoveryPointSEI: OFF IntRefType: 0; IntRefCycleSize: 0; IntRefQPDelta: 0
[h264_qsv @ 0000000000d2e340] MaxFrameSize: 783360; MaxSliceSize: 0;
[h264_qsv @ 0000000000d2e340] BitrateLimit: ON; MBBRC: OFF; ExtBRC: unknown
[h264_qsv @ 0000000000d2e340] Trellis: auto
[h264_qsv @ 0000000000d2e340] RepeatPPS: ON; NumMbPerSlice: 0; LookAheadDS: unknown
[h264_qsv @ 0000000000d2e340] AdaptiveI: unknown; AdaptiveB: unknown; BRefType: off
[h264_qsv @ 0000000000d2e340] MinQPI: 0; MaxQPI: 0; MinQPP: 0; MaxQPP: 0; MinQPB: 0; MaxQPB: 0
[h264_qsv @ 0000000000d2e340] Entropy coding: CABAC; MaxDecFrameBuffering: 2
[h264_qsv @ 0000000000d2e340] NalHrdConformance: OFF; SingleSeiNalUnit: ON; VuiVclHrdParameters: OFF VuiNalHrdParameters: OFF
[mp4 @ 00000000025d09e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, mp4, to 'output.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.42.100
    Stream #0:0(eng): Video: h264 (h264_qsv), 1 reference frame ([33][0][0][0] / 0x0021), nv12, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1000 kb/s, 0.02 fps, 60k tbn, 59.94 tbc (default)
      handler_name    : VideoHandler
      timecode        : 16:11:08:04
      encoder         : Lavc57.50.100 h264_qsv
    Side data:
      cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_qsv))
Press  to stop, [?] for help
[h264 @ 000000000252ae60] Reinit context to 1920x1088, pix_fmt: yuvj420p
No more output streams to write to, finishing.e=00:00:14.73 bitrate=317220.2kbits/s speed=1.38x
frame=  900 fps= 84 q=-0.0 Lsize=  581823kB time=00:00:14.98 bitrate=318142.0kbits/s speed=1.39x
video:581810kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.002283%
Input file #0 (input.mp4):
  Input stream #0:0 (video): 900 packets read (19028307 bytes); 900 frames decoded;
  Input stream #0:1 (data): 1 packets read (4 bytes);
  Total: 901 packets (19028311 bytes) demuxed
Output file #0 (output.mp4):
  Output stream #0:0 (video): 900 frames encoded; 900 packets muxed (595772946 bytes);
  Total: 900 packets (595772946 bytes) muxed


0 Kudos
1 Reply

Change the global_quality param to a value of from 28 to 32 and you will get reduced bitrates. I suffered from the same problem. If you tell the algorithm to maintain the quality 1:1, then - of course - the bitrate is raised to maintain the quality. Hope this helps!