Range of "global_quality" value for h264_qsv encoder?

What is the range of the -global_quality setting for ffmpeg's h264_qsv encoder (4.3.2-2021-02-27-full_build-www.gyan.dev, Windows)?

Ffmpeg's documentation for the encoder (archive) states:

The ratecontrol method is selected as follows:

  • When global_quality is specified, a quality-based mode is used. Specifically this means either
    • CQP - constant quantizer scale, when the qscale codec flag is also set (the -qscale ffmpeg option).
    • LA_ICQ - intelligent constant quality with lookahead, when the look_ahead option is also set.
    • ICQ – intelligent constant quality otherwise.

But it doesn't state what the values mean.


Solution 1:

For CQP mode, global_quality is divided by 118 (let's call this quant) and then quantization parameters are computed as per frame type.

For I-frames, QP is quant * 0.8, clipped to between 0 and 51.
For P-frames, QP is quant, clipped to between 0 and 51.
For B-frames, QP is quant * 1.25 + 1.25, clipped to between 0 and 51.

For the ICQ modes, quality is the global_quality, clipped to between 1 and 51.