2

I'm looking to create a m3u8 file that points to other m3u8 files based on bandwidth, something like this

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:4
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=500000,RESOLUTION=480x270
480x270.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000,RESOLUTION=640x360
640x360.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2000000,RESOLUTION=1280x720
1280x720.m3u8
#EXT-X-ENDLIST

I was hoping to be able to do this using ffmpeg but I can't seem to find any information on doing it that way. This may be the wrong way to do it so if anyone can point me in the right direction that would be greatly appreciated.

aergistal
  • 29,947
  • 5
  • 70
  • 92
amcneil
  • 21
  • 1
  • 3

1 Answers1

4

Update January 2018

You can now create master playlists directly with FFmpeg using master_pl_name and var_stream_map. See the documentation.


You cannot create a HLS master playlist directly with FFmpeg (yet). You can encode the same source for multiple bitrates and get each variant playlist, but you'll have to provide the master yourself.

Of course, the resulting streams have to be aligned so you either:

  • use a fixed GOP size (-g <size> -sc_threshold 0, x264 --keyint <size> --min-keyint <size> --scenecut -1)

  • if applicable, do 2-pass encoding using the same first pass statfile for each second pass. This works better if you use generate the statfile for a rendition in the middle of the required bitrates since there will be some loss of precision.

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • Thank you for your response. I'm currently using this line to create the different files. ffmpeg -i i.mp4 -filter:v -c:a aac -strict experimental -ac 2 -b:a 64k -ar 44100 -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 21 -b:v 400K -r 12 -g 36 -f hls -hls_time 9 -s 480x270 ts/480x270.m3u8 and then I change the size to 640 x 360 or 1280 x 720. The playlist seems to be working but are you saying I'll need to do another step beforew i'm able to use them? – amcneil May 11 '15 at 20:05
  • 1
    You have to write the master playlist yourself and reference the ffmpeg generated playlists. You're using the fixed GOP solution (`-g 36`) and you should add `-sc_threshold 0`. But your command doesn't look correct, since you're changing just the resolution but you leave the same bitrate for all renditions ( `-b:v 400K`) and the level will also be different based on resolution. You want multi-bitrate media for adaptive streaming. – aergistal May 12 '15 at 08:23
  • Oh I'm sorry about that, I was just being lazy and should have pasted the three different ffmpeg commands. I'm changing the bitrate on each of the different encodes. Thanks again for all your help and the link to that great write up! – amcneil May 12 '15 at 14:42