Configure HLS Segment Duration and Playlist Size in FFmpeg

This article provides a quick guide on how to configure HTTP Live Streaming (HLS) segment duration and maximum playlist size using FFmpeg. You will learn the specific command-line flags required to control individual chunk lengths, limit the number of active segments in your M3U8 playlist, and manage disk space during live streaming.

To configure these settings in FFmpeg, you primarily use the -hls_time and -hls_list_size options. Below is a practical command example followed by a detailed breakdown of how these parameters work.

Example FFmpeg Command

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 6 -hls_list_size 5 -hls_flags delete_segments output.m3u8

Parameter Breakdown

1. Configuring Segment Duration (-hls_time)

The -hls_time option sets the target segment duration in seconds.

2. Configuring Maximum Playlist Size (-hls_list_size)

The -hls_list_size option defines the maximum number of segment files kept in the .m3u8 playlist file.

3. Managing Old Segments (-hls_flags delete_segments)

When running a live stream with a limited playlist size, older segment files will be removed from the .m3u8 index, but they will remain on your disk by default.

To automatically delete expired segment files from your storage and prevent your disk from filling up, append -hls_flags delete_segments to your command.