ts_hls

The `ts_hls` directive enables the generation of live HLS (HTTP Live Streaming) content for MPEG-TS streams in NGINX.

Syntaxts_hls path=PATH [segment=MIN[:MAX]] [segments=NUMBER] [max_size=SIZE] [noclean];
Defaultnone
Contextlocation
Arguments1+

Description

The ts_hls directive is utilized within an NGINX location block to set up live HTTP Live Streaming (HLS) for MPEG-TS content. When this directive is specified, it requires a PATH parameter that defines the directory where the HLS playlist and segment files will be stored. If the specified directory does not already exist, it will be created by NGINX. For every active MPEG-TS stream, a corresponding subdirectory is created within the specified PATH, with the stream name derived from the last component of the URI.

The HLS segments are generated based on several configurable parameters. The segment parameter defines the minimum and maximum duration of each segment, with the default being a minimum of 5 seconds. This means that segments will be created starting at video keyframes, and if the next keyframe is not available within the maximum duration, the segment will be truncated. Additionally, the segments parameter allows control over the maximum number of segments that can be retained in the HLS playlist, removing older segments as new ones are added, thus managing memory usage effectively.

There are options for limiting the size of segments with the max_size parameter and controlling file cleanup with noclean, which prevents automatic deletion of older files. It is important to note that the path specified in multiple ts_hls directives cannot be reused for different streams, ensuring unique management of each stream's files.

Config Example

location /live {
    ts;
    ts_hls path=/var/hls segment=10s segments=5;
}

Ensure the PATH specified is writable by the NGINX process.

Avoid reusing the same path in multiple ts_hls or ts_dash directives, as this will cause conflicts.

If using dynamic segments or sizes, be mindful of memory management to avoid excessive resource usage.

← Back to all directives