hls_variant

The `hls_variant` directive is used to specify a variant stream for HLS (HTTP Live Streaming) in the NGINX RTMP module.

Syntaxhls_variant name bandwidth | resolution;
Defaultnone
Context
Arguments1+

Description

The hls_variant directive is utilized within the NGINX RTMP module to define multiple streaming variants for an HLS (HTTP Live Streaming) application. By using this directive, you can stream different bitrate versions of the same content, allowing clients to choose the best quality stream based on their current network conditions. This is particularly useful for adaptive streaming, where the server can automatically switch between different video quality levels to optimize the user experience.

Each hls_variant entry requires an argument that specifies the characteristics of the stream variant, including its bandwidth and resolution. The directive operates by providing the necessary metadata that assists in generating the appropriate playlist files (.m3u8) which clients use to access different stream variants. As clients adapt to changing network conditions, the HLS player can seamlessly switch between these variants based on the specified attributes of each variant stream provided by the hls_variant directive.

It’s important to configure stream variants carefully to ensure that they are appropriately encoded. If the variants differ significantly in encoding parameters, users may encounter playback issues when attempting to switch between streams on-the-fly. Therefore, maintaining consistency in codecs and keyframe intervals across different variants is critical for a smooth adaptive streaming experience.

Config Example

application live {
    live on;
    hls on;
    hls_variant low bandwidth=200000;
    hls_variant mid bandwidth=800000;
    hls_variant high bandwidth=5000000;
}

Ensure that the bandwidth settings match the actual bitrate of the content to avoid playback issues.

All variants should have consistent encoding parameters to ensure smooth transitions between streams.

It is crucial to properly configure the HLS context where the variants are defined to avoid conflicts.

← Back to all directives