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@example.com. I’ll publish everything I can get working and will give credit where credit is due.