CRF & Capped CRF Descriptions & Examples
CRF
Constant Rate Factor Mode, enabled by setting the rate factor parameter crf. With CRF the encoder varies the bitrate to maintain constant subjective quality.
CRF Sample Command:
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30.0 -i input1920x1080.yuv -c:v h265_ni_quadra_enc -xcoder-params "gopPresetIdx=5:RcEnable=0:crf=23:lookAheadDepth=10" output1920x1080.h265
Capped CRF
Capped Constant Rate Factor Mode is enabled by setting the rate factor parameter crf together with bitrate, vbvBufferSize, vbvMaxRate (optional), vbvMinRate (optional). Capped CRF combines the CRF mode with a maximum bitrate limit or caprate. In this approach, CRF is used to specify the target quality level, while the caprate prevents the average bitrate from exceeding the target bitrate. This combination is particularly useful in scenarios where a specific quality level is desired and it’s also crucial to constraint bitrate to meet bandwidth or storage requirements. Please also note that in Capped CRF mode, if encoder is restricted by caprate and cannot produce enough bits, it may not be able to maintain the quality level specified by the crf parameter. Additionally, in some cases, the maximum bitrate may not be strictly controlled. The following descriptions provide more details about these parameters –
-
crf determines the quality of encoded frames; generally speaking, the better the quality, the more bits each frame will consume. These bits cause the encoder buffer level to rise and can be considered as the "input rate" of the encoder buffer. Please note the quality will be limited by caprate, therefore setting low crf value (high quality) with low bitrate or vbvMaxRate is not recommended
-
bitrate or vbvMaxRate is the caprate. If vbvMaxRate is not specified, encoder will take bitrate as the caprate. If both bitrate and vbvMaxRate are specified, the encoder will instead take vbvMaxRate as the caprate. The caprate is also the "draining rate" of the encoder buffer; the higher the caprate, the faster the encoder buffer is drained. If user sets low crf value (high quality & high input rate) together with low caprate (low draining rate), the encoder will need to suppress bits and may not be able to maintain the high quality level specified by the user
-
vbvBufferSize determines the buffer size. The buffer size determines "tolerance" of peak rate. While bitrate or vbvMaxRate determines the maximum average bitrate, the instantaneous peak rate is decided by both the caprate and buffer size, e.g. peak rate < = caprate + buffer size. Please note that bitrate is required even if vbvMaxRate is already specified, because encoder needs both bitrate and vbvBufferSize parameters to calculate the actual buffer size: buffer size (bits) = bitrate (bps) * vbvBufferSize (ms) / 1000
Besides the maximum bitrate limit, the user may also set a minimum bitrate limit, so that encoder will produce more bits to achieve higher quality in low volatile scenes which would otherwise have produced bits less than the minimum bitrate limit.
Note that in Capped CRF mode, although the encoder attempts to maintain consistent subjective quality, it is also required to adjust quality to meet the bitrate limit, and therefore consistent quality is no longer guaranteed. More details –
- Capped CRF requires bitrate and vbvBufferSize, these parameters together define the size of the VBV buffer, which is used to constrain bitrate. Please note that bitrate is required even if vbvMaxRate is already specified, because encoder needs both bitrate and vbvBufferSize parameters to calculate the actual buffer size:
buffer size (bits) = bitrate (bps) * vbvBufferSize (ms) / 1000
-
If vbvMaxRate is not set, encoder will take bitrate as the maximum bitrate limit. If vbvMaxRate is set, the encoder will take vbvMaxRate as the maximum bitrate limit instead.
-
If vbvMinRate is not set, the encoder will not constrain bitrate by a minimum bitrate limit. If vbvMinRate is set, the encoder will produce more bits to meet the minimum bitrate, which may also raise quality to be higher than the specified consistent quality level (which depends on crf parameter value) when bits required at specified quality level is lower than the minimum bitrate.
-
Please also refer to bitrate, vbvBufferSize, vbvMaxRate, vbvMinRate descriptions in Section 8.4 “Encoding Parameters”
Capped CRF Sample Command (without vbvMaxRate and vbvMinRate):
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30.0 -i input1920x1080.yuv -c:v h265_ni_quadra_enc -xcoder-params "gopPresetIdx=5:RcEnable=0:crf=23:lookAheadDepth=10:vbvBufferSize=1000:bitrate= 3200000" output1920x1080.h265
Capped CRF Sample Command (with vbvMaxRate):
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30.0 -i input1920x1080.yuv -c:v h265_ni_quadra_enc -xcoder-params "gopPresetIdx=5:RcEnable=0:crf=23:lookAheadDepth=10:vbvBufferSize=1000:bitrate= 3200000:vbvMaxRate=4000000" output1920x1080.h265
Capped CRF Sample Command (with vbvMinRate):
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30.0 -i input1920x1080.yuv -c:v h265_ni_quadra_enc -xcoder-params "gopPresetIdx=5:RcEnable=0:crf=23:lookAheadDepth=10:vbvBufferSize=1000:bitrate= 3200000:vbvMinRate=1000000" output1920x1080.h265
Capped CRF Sample Command (with vbvMaxRate and vbvMinRate):
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30.0 -i input1920x1080.yuv -c:v h265_ni_quadra_enc -xcoder-params "gopPresetIdx=5:RcEnable=0:crf=23:lookAheadDepth=10:vbvBufferSize=1000:bitrate= 3200000:vbvMaxRate=4000000:vbvMinRate=1000000" output1920x1080.h265