hls_max_fragment
The `hls_max_fragment` directive sets the maximum duration of each HLS fragment in milliseconds.
Description
The hls_max_fragment directive is part of the NGINX RTMP module, which facilitates live streaming using the HLS (HTTP Live Streaming) protocol. This directive takes a single argument representing the maximum duration for the HLS fragments that the server will generate during streaming sessions. It is crucial for balancing the trade-offs between responsiveness for client requests and the overall streaming experience. By configuring this directive, stream administrators can tailor the fragment durations to meet network bandwidth conditions, client requirements, or server processing capabilities.
When hls_max_fragment is set to a value, that duration is enforced so that each fragment created will not exceed this limit. Shorter fragment lengths may lead to a larger number of files created, increasing overhead for the client as they request these segments sequentially. Conversely, longer fragments can provide a smoother streaming experience but may introduce latency in the delivery of content. The choice of fragment length is therefore critical in optimizing performance based on expected user behavior and environmental conditions.
The directive must be specified within the application context of the server configuration file. If not defined, the server may resort to its default behavior, which may not align with the specific streaming use case stipulated by the server administrator. It is also important to ensure that this directive is compatible with other related streaming directives for optimal performance.
Config Example
application myapp {
live on;
hls on;
hls_max_fragment 2000;
}Make sure that the value set for hls_max_fragment is appropriate for the expected latency and the number of concurrent users.
Avoid setting extremely short fragment durations as it can lead to excessive load on the server and client disruptions.
Ensure compatibility with the hls_fragment directive.