Baby Steps in Producing an HLS Master Manifest With FFmpeg

This article has been superseded by this article entitled, An FFmpeg Script to Render and Package a Complete HLS Presentation.

So there I was, teaching a class at Streaming Media East entitled How To Build A Free Encoder/Packager With Watch Folder Operation Using Open Source Tools (handout and video available here). An attendee asked about creating an HLS manifest with FFmpeg, which I didn’t cover, opting instead to show Bento4. However, I vowed to learn and write about it, and with the help of Shaun Procter from Echo360 in Australia, have managed to produce the following working command line:

ffmpeg ^
-i TOS.mp4 ^
-i TOS.mp4 ^
-i TOS.mp4 ^
-i TOS.mp4 ^
-s:v:0 1920x1080 -c:v:0 libx264 -b:v:0 4000k ^
-s:v:1 1280x720 -c:v:1 libx264 -b:v:1 2000k ^
-s:v:2 854x480 -c:v:2 libx264 -b:v:2 1000k ^
-s:v:3 640x360 -c:v:3 libx264 -b:v:3 600k ^
-c:a:0 copy ^
-map 0:a -map 0:v -map 1:v -map 2:v -map 3:v ^
-var_stream_map "a:0,agroup:audio v:0,agroup:audio v:1,agroup:audio v:2,agroup:audio v:3,agroup:audio" ^
-threads 0 -f hls -movflags frag_keyframe -hls_flags single_file+independent_segments ^
-hls_segment_type fmp4 -hls_list_size 0 -hls_time 10 -hls_allow_cache 1 ^
-master_pl_name master.m3u8 -y video%v.m3u8

Which created this set of files:

Which plays fine in Edge or Safari if you click here (the file won’t play in Chrome or Firefox because I didn’t add a player; Edge and Safari both play HLS natively without a player).

Working is good, but this script is as ugly as someone else’s baby, particularly the need to duplicate the input file four times for the four streams. It bogs down terribly with larger files and is more of a live script than VOD.

I can’t find a good tutorial on creating HLS master manifests with FFmpeg. If anyone is aware of one or can provide some guidance on how to fix this for live streaming and/or create an HLS master manifest with FFmpeg for VOD, please ping me at [email protected]. I’ll publish everything I can get working and will give credit where credit is due.

About Jan Ozer

Avatar photo
I help companies train new technical hires in streaming media-related positions; I also help companies optimize their codec selections and encoding stacks and evaluate new encoders and codecs. I am a contributing editor to Streaming Media Magazine, writing about codecs and encoding tools. I have written multiple authoritative books on video encoding, including Video Encoding by the Numbers: Eliminate the Guesswork from your Streaming Video (https://amzn.to/3kV6R1j) and Learn to Produce Video with FFmpeg: In Thirty Minutes or Less (https://amzn.to/3ZJih7e). I have multiple courses relating to streaming media production, all available at https://bit.ly/slc_courses. I currently work as www.netint.com as a Senior Director in Marketing.

Check Also

Announcing Free Course on Controlling the AMD MA35D with FFmpeg

I’m pleased to announce a new free course, MA35D & FFmpeg Quick Start: Essential Skills …

Choosing the Best Preset for Live Transcoding

When choosing a preset for VOD transcoding, it almost always makes sense to use the …

There are no codec comparisons. There are only codec implementation comparisons.

I was reminded of this recently as I prepared for a talk on AV1 readiness …

Leave a Reply

Your email address will not be published. Required fields are marked *