pythonvideo-streaminghtml5-videohttp-live-streaminglive-streaming

HLS live stream server


I am planning to write my own live stream server in python using the HLS protocol for a small project.

My idea is to use Amazon S3 for storage and have the python server just output the m3u8 file.

This is all straightforward, now to the problem: I want to stream live video from a camera over an unreliable network and if there is a congestion the player could end up with completing playing of the last file referenced in the m3u8 file. Can i in some way mark the stream as a live stream having the player try again reloading the m3u8 for a specific time looking for a next segment or how should live streaming using HLS be handled? Maybe live streaming over HLS is not supported?


Solution

  • This is explictly allowed in the HLS spec as a "live Playlist". There are a few things you need to be aware of, but notably, from section 6.2.1:

    The server MUST NOT change the Media Playlist file, except to:

    o Append lines to it (Section 6.2.1).

    And if we take a look at Section 4.3.3.4:

    The EXT-X-ENDLIST tag indicates that no more Media Segments will be added to the Media Playlist file. It MAY occur anywhere in the Media Playlist file.

    In other words, if a playlist does not include the #EXT-X-ENDLIST tag, it's expected that the player will keep loading the playlist from whatever source it originally loaded it from with some frequency, looking for the server to append segments to the playlist.

    Most players will do this taking into account current network conditions so they have a chance to get new segments before the playback is caught up. If the server needs to interrupt the segments, or otherwise introduce a gap, it has the responsibility to introduce a #EXT-X-DISCONTINUITY-SEQUENCE tag.

    Apple provides a more concrete example of a Live Playlist on their developer website.