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

New Lessons on Streaming Monetization Added to Streaming Media 101

The Streaming Learning Center is pleased to announce the addition of four new lessons on …

Streaming Summer Bootcamp Session 2: Producing H.264

Announcing session 2 of Streaming Summer Bootcamp: Learn to Produce H.264 Video. Thu, Jul 11, …

Simplify Your Workflow: Command-Line Variables in FFmpeg Batch Files

Creating batch files with variables is one of the more efficient ways to run FFmpeg. …

Leave a Reply

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