Introduction
Low-latency HLS (LL-HLS) playback feature has been introduced in Ant Media Server version 2.11 and above. It allows you to stream with minimal latency (around 2-5 seconds), making it ideal for near real-time streaming applications.
What is LL-HLS?
Low Latency HLS (LL-HLS) is a streaming protocol designed to minimize latency in live streaming. Traditional HLS can have latency ranging from 20-30 seconds, while LL-HLS reduces this to around 2-5 seconds.
LL-HLS achieves this by using smaller video segments (called "parts") that allow the video player to start playback before an entire segment is completed.
Key Differences: HLS vs. LL-HLS
Standard HLS | Low Latency HLS (LL-HLS) |
---|---|
Latency: ~20-30 secs | Latency: ~2-5 secs |
Segment-based | Part-based (smaller chunks) |
Larger file sizes | Smaller, more frequent parts |
How to Enable LL-HLS in Ant Media Server
LL-HLS is a paid plugin offered by the Ant Media Server. So before using LL-HLS, you need to purchase and install the plugin on your Ant Media Server. For more information about plugin structure in Ant Media Server, take a look at the Ant Media Server Plugins
Step 1: Purchase and Install the LL-HLS Plugin
- Purchase the Plugin
- Email contact@antmedia.io to purchase the LL-HLS plugin.
- Alternatively, you can also get it directly from the website based on a monthly subscription basis.
- Install the Plugin
- Upload/copy the plugin file to your instance running the Ant Media Server.
- Run the following commands to install:
unzip low-latency-hls-plugin.zip
cd low-latency-hls-plugin
sudo ./install_low-latency-hls-plugin.sh
sudo service antmedia restart
Step 2: Publish a Stream
Ant Media Server provides LL-HLS endpoints for all ingested streams. You can check the publish live streams section to learn how to publish streams using different protocols with Ant Media Server. For this example, let's publish with WebRTC.
- Access the WebRTC Publish Page Open the following URL in your browser:
https://yourserver.com:5443/live/?streamId=stream1
- Replace yourserver.com with your Ant Media server's domain.
- You can use stream1 or any custom stream ID.
- Start Publishing the Stream
Click the Start Publishing button on the page.
Step 3: Play the Stream with LL-HLS
- Open a Video Player
Use a player that supports LL-HLS, like THEOPlayer, Safari, or others.
- For this example, we are going to use THEOPlayer test page
- Enter the LL-HLS URL
In the player, enter the following URL to play the stream:
https://yourserver.com:5443/live/streams/ll-hls/stream1/stream1__master.m3u8
- Ensure two underscores (__) exist between the stream ID and
master.m3u8
. - The URL pattern:
https://{YOUR_SERVER}:{PORT}/{APP}/streams/ll-hls/{STREAM_ID}/{STREAM_ID}__master.m3u8
Customizing LL-HLS
You can fine-tune LL-HLS settings in the Advanced section of the application settings of the Ant Media Server web panel. These settings allow you to adjust the behavior of LL-HLS to meet specific needs, like controlling segment durations or playlist updates.
Customization Parameters
- partTargetDurationMs
The maximum duration of partial segments in milliseconds (recommended: 1002 ms).
"partTargetDurationMs": 1002
- targetDuration
Target duration for media files (default: 10 seconds). Lower values provide faster response times but increase server load.
"targetDuration": 10
- slidingWindowEntries
Number of media segments retained in the playlist (default: 5). Increasing this value can improve stability but may consume more resources.
"slidingWindowEntries": 5
- deleteFiles
Determines whether old media files are deleted after being removed from the playlist (default: true). It is set to false if you want to keep old segments.
"deleteFiles": true
- program
Indicates if a VOD-style program is being captured, which means all segments are retained in the playlist (default: false).
"program": false
- addDateTime
Controls whether the date and time are added to media file names (default: true)
"addDateTime": true
- receiveDataTimeout
Timeout duration in seconds after which the segmenter pauses if no data is received (default: 0, meaning no timeout).
"receiveDataTimeout": 0
- exitOnReceiveDataTimeout
If set to true, the segmenter will exit when the receiveDataTimeout is reached. Otherwise, it will just pause (default: false).
"exitOnReceiveDataTimeout": false
- fileCompleteCommand
Command executed when a media or index file is completed. You can use %P
for the full path and %F
for the file name.
"fileCompleteCommand": "/path/to/script %P %F"
- fileDeleteCommand
Command executed when a media or index file is deleted after being removed from the playlist.
"fileDeleteCommand": "/path/to/delete_script %P %F"
- quiet
If set to true, only error messages will be displayed in the logs (default: false).
"quiet": false
Applying Customization
To apply the above settings, add them under the customSettings section in the Ant Media Server application advanced settings:
"customSettings": {
"plugin.ll-hls": {
"partTargetDurationMs": 1002,
"targetDuration": 10,
"slidingWindowEntries": 5,
"deleteFiles": true,
"program": false,
"addDateTime": true,
"receiveDataTimeout": 0,
"exitOnReceiveDataTimeout": false,
"fileCompleteCommand": "/path/to/script %P %F",
"fileDeleteCommand": "/path/to/delete_script %P %F",
"quiet": false
}
}
- You can easily enable Low-Latency HLS (LL-HLS) on Ant Media Server with this guide. For a more detailed explanation of the LL-HLS and its related properties, check the Low-latency HLS blogpost.