FFMPEG Command to Create HLS (m3u8) Live Video Streaming Variants & Segments and Download it in File in Command Line


Yes, you need to encode all variants and generate the media playlists first (the playlists containing the segments).

If you want you can do it in one command since ffmepg supports multiple inputs/outputs. Eg:

You must provide the variants in multiple qualities/bitrates but the aspect ratio should remain the same. Keeping the aspect ratio was initially mandatory but in the latest HLS authoring guide it’s downgraded to a recommendation.

All variant streams must be keyframe aligned so set a GOP size using the -g option, disable scene-cut detection and use a segment duration hls_time which is a multiple of your keyframe interval.

Once you have all 3x m3u8 media playlist you can manually create the master playlist which points to each media playlist.

Example from the Apple HLS documentation, you must change the bandwidth, codecs, resolution and playlist filenames according to your own encoding options:

Leave a Reply