FFMpeg Reduced Latency HLS

This section will show you how to reduce HLS stream latency from the standard 30-40 seconds to 5-10 seconds.

The information provided here is based on the FFMpeg HLS section. We advise you to read the FFMpeg HLS section first if you have not yet done so.

The main reason for high latency is a large chunk size by default. We will reduce latency significantly if we reduce the size, but there is a higher chance of buffering and interruptions on the player side.

FFMpeg Command Line Parameters

ffmpeg -re -i https://s3.tebi.io/test/examples/bbb_1080p_30fps.mp4 \
-c:v libx264 -b:v 5000k -c:a copy -preset:v fast -method PUT -http_persistent 0 \
-x264-params keyint=15:min-keyint=15 -hls_time 1 \
-hls_flags delete_segments -hls_list_size 20 \
-f hls https://ffmpeg-hls-test.datastream.tebi.io/test.m3u8

The difference between this and the example provided in the FFMpeg HLS section are:

  • -x264-params keyint=15:min-keyint=15: Sets the key frame interval low enough to enable 1 second chunk size.

  • -hls_time 1: Use a small HLS chunk size to reduce HLS latency. 1 second is a good balance between latency and performance.

  • -hls_list_size 20: Keep at least 20 seconds (chunks) of playback in the playlist to allow slow clients’ buffer more chunks.

  • -http_persistent 0: This tells FFMpeg to close connection right after the data is transferred without waiting for an HTTP response.

After FFMpeg is started, give it a minute to prepare and upload a couple of video segments to the storage. You can watch your stream using your favorite HLS player here: https://ffmpeg-hls-test.s3.tebi.io/test.m3u8.

See Also