hls_fragment

Sets the duration of each HLS fragment in milliseconds for streaming applications.

Syntaxhls_fragment milliseconds;
Defaultnone
Context
Arguments1

Description

The hls_fragment directive specifies the length of each fragment in milliseconds when used in conjunction with HLS (HTTP Live Streaming) streaming through the NGINX RTMP module. By defining the fragment duration, you can determine how often the stream will create a new segment, which is critical for both performance and latency in streaming applications.

When the fragment length is too short, it can increase the overhead of segment generation, leading to higher CPU usage and decreased performance. Conversely, a longer fragment length can result in increased latency, as viewers will have to wait longer for new segments to begin downloading. To strike a balance, users should test various settings based on their specific requirements and the nature of the content being streamed.

In the configuration file, this directive can be placed within an application block and requires one argument, which defines the fragment duration. The value must be specified in milliseconds to ensure proper segment timing during live streaming or on-demand viewing. Properly adjusting the hls_fragment can enhance user experience by optimizing both the loading time and the responsiveness of the HLS stream.

Config Example

application live {
    live on;
    hls on;
    hls_fragment 5000;
    hls_playlist_length 30000;
}

Setting hls_fragment too low can lead to increased CPU load and higher latency. Maximum fragmentation can vary greatly based on network conditions and server load.

The value must be in milliseconds; values specified in seconds will not work as intended.

← Back to all directives