<p>Here is how I programmatically created the master playlist, reading from 2 different master playlists using python.</p>
<pre><code>        streams = list()

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

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

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

        for stream in streams:
            final_master_playlist.write(stream)
        final_master_playlist.close()
</code></pre>

CC BY-SA 4.0
2023-04-26T18:27:17.077Z
2023-04-26T18:27:17.077Z
Appu Mistri
<p>I'm using FFmpeg to generate streaming files for a single resolution initially. Here is how my playlist and master-playlist looks like.</p>
<p><strong>master.m3u8</strong></p>
<pre><code>#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2305600,RESOLUTION=852x480,CODECS=&quot;avc1.640034,mp4a.40.2&quot;
stream_480p.m3u8
</code></pre>
<p><strong>stream_480p.m3u8</strong></p>
<pre><code>#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
</code></pre>
<p>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?</p>

CC BY-SA 4.0
2023-04-25T04:12:09.620Z
ffmpeg can only create playlists as a fresh set - which includes master and renditions. Will have to do it programmatically.
Gyan
CC BY-SA 4.0
2023-04-25T06:50:11.703Z
@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?
Appu Mistri
CC BY-SA 4.0
2023-04-26T04:02:18.957Z
Use ffmpeg to create a fresh set of playlists and use the values printed there.
Gyan
<ffmpeg><hls>
How do I create an master HLS playlist using existing .m3u8 playlists
Appu Mistri
# How do I create an master HLS playlist using existing .m3u8 playlists

(Asked by: username_0 on 2023-04-24)

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?

**Tags:** ffmpeg, hls

> **Comments:**
> **username_1**: ffmpeg can only create playlists as a fresh set - which includes master and renditions. Will have to do it programmatically.  
> **username_0**: @username_1 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?  
> **username_1**: Use ffmpeg to create a fresh set of playlists and use the values printed there.  

---

## 1 answers

### Answer by username_0 on 2023-04-26. Score: 1 | Accepted answer

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()


---

