Skip to main content

nvenc_level

Function nvenc_level 

Source
fn nvenc_level(
    codec: Codec,
    width: u32,
    height: u32,
    fps: u32,
    bitrate_bps: u64,
    hevc_high_tier: bool,
) -> u32
Expand description

The level an NVENC session advertises for a width x height stream at fps carrying up to bitrate_bps (NV_ENC_LEVEL shares each codec’s own numbering: level_idc for H.264, general_level_idc for HEVC, seq_level_idx for AV1).

H.264 and HEVC carry the current geometry’s level, the lowest a decoder is asked to accept, so a hardware decoder that gates on it – older Apple and Intel fixed-function parts refuse a stream whose SPS names a level above their ceiling even for a picture they could hold – takes the stream. reconfigure_resolution re-declares the level with a forced IDR on every resize; the frame rate is floored at HEADROOM_FPS, so a live rate change between the common rates, which carries no IDR, never moves it. AV1 instead holds the resize headroom’s level: NVENC validates an AV1 session’s level against maxEncodeWidth x maxEncodeHeight at init and refuses one that cannot hold it, and an AV1 hardware decoder is recent enough to take that level whatever the picture. The driver holds every codec’s level to its bitrate ceiling as well, refusing a CBR target past it as an invalid level, so a declared rate raises the level to the first that admits it; hevc_high_tier names the HEVC tier the session declares, whose ceiling is the one that applies. Driver 595.71.05 holds an AV1 level to two thirds of its Annex A MaxBitrate, NVENC_AV1_RATE (5.1 26.7 Mbit/s rather than 40, on an RTX 4090 and an L4, whatever the frame rate or buffer), where 595.91.07 and 615.71.09 hold Annex A’s, so a session asks for the Annex A level first and, refused, for the level level_rate weighs the rate to (NVENC_AV1_WEIGHTED). An HEVC picture is counted in whole 32-pixel coding tree blocks, NVENC’s, as the driver counts it: 1280x720 at 144 fps is inside 4.1 by its own samples, and the driver refuses it as 4.1.