1

I'm using FFmpeg to generate streaming files for a single resolution initially. Here is how my playlist and master-playlist looks like.

master.m3u8

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2305600,RESOLUTION=852x480,CODECS="avc1.640034,mp4a.40.2"
stream_480p.m3u8

stream_480p.m3u8

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:EVENT
#EXTINF:10.000000,
stream_480p0.ts
#EXTINF:10.000000,
stream_480p1.ts
#EXT-X-ENDLIST

later, if I add another stream, say 720p. I want my master.m3u8 to include that stream and serve the clients. How to achieve this? Are there any existing commands in FFmpeg that I can use here? or create the master.m3u8 programmatically?

3
  • ffmpeg can only create playlists as a fresh set - which includes master and renditions. Will have to do it programmatically.
    – Gyan
    Commented Apr 25, 2023 at 4:12
  • @Gyan I'm trying to do it now, but not able to figure out how to get the exact values for the BANDWIDTH and CODECS params, which I have to put in the master.m3u8. Do you know of any docs to get those values and create the master.m3u8 programmatically? Commented Apr 25, 2023 at 6:50
  • 1
    Use ffmpeg to create a fresh set of playlists and use the values printed there.
    – Gyan
    Commented Apr 26, 2023 at 4:02

1 Answer 1

1

Here is how I programmatically created the master playlist, reading from 2 different master playlists using python.

        streams = list()

        # read from 1st master playlist
        primary_master_playlist = open("master_1.m3u8", "r")
        while True:
            line = primary_master_playlist.readline()
            if not line:
                break
            elif line.lower().startswith("#ext-x-stream-inf"):
                streams.append(line + primary_master_playlist.readline() + "\n")

        # read from 2nd master playlist
        secondary_master_playlist = open("master_2.m3u8", "r")
        while True:
            line = secondary_master_playlist.readline()
            if not line:
                break
            elif line.lower().startswith("#ext-x-stream-inf"):
                streams.append(line + secondary_master_playlist.readline() + "\n")

        # write to final master playlist
        final_master_playlist = open("master.m3u8", "w")
        final_master_playlist.write("#EXTM3U\n")
        final_master_playlist.write("#EXT-X-VERSION:3\n")

        for stream in streams:
            final_master_playlist.write(stream)
        final_master_playlist.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.