How many Sequence should a live stream m3u8 have?

1.1k Views Asked by At

The client has multiple short videos available via his rest API, he wants to generate an m3u8 from them which behaves like a live stream.

I wrote a PHP script, it continuously loops through the available videos, adds them to the m3u8, and deletes the oldest streams from the file, such that the end-user can't go back in the stream nor go forward that much, just like a live stream. The file always gets autogenerated every minute, it's always overwritten and the resulting m3u8 is uploaded to the S3 bucket.

This is what the m3u8 looks like currently

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:20
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10.0,
https://example.com/video/uv10774862h/774862h_w254909923_0.ts
#EXT-X-DISCONTINUITY
#EXTINF:18.76,
https://example.com/video/uv10774862h/774862h_w254909923_1.ts
#EXT-X-DISCONTINUITY
#EXTINF:11.28,
https://example.com/video/uv10774862h/774862h_w254909923_2.ts
#EXT-X-DISCONTINUITY
#EXTINF:3.96,
https://example.com/video/uv10774862h/774862h_w254909923_3.ts

The problem is that the video player gets stuck at a random segment during the video stream. Sometimes in the middle or 3 seconds before the end of the last stream.

  1. Should there be multiple MEDIA-SEQUENCE in a live m3u8?
  2. Is TARGETDURATION needed? I prefer if the video player can guess the target duration so that I don't have to keep track of it.
  3. Should anything be added to the m3u8 so the video player doesn't get stuck while buffering? Is the template I'm using correct for a live stream?
2

There are 2 best solutions below

0
Brad On

The problem is that the video player gets stuck at a random segment during the video stream. Sometimes in the middle or 3 seconds before the end of the last stream.

You need to add the following line to the end of your playlist when the stream is finished:

#EXT-X-ENDLIST

The file always gets autogenerated every minute, it's always overwritten and the resulting m3u8 is uploaded to the S3 bucket.

Be sure to leave some of the old segments as well. Not all players are going to be in the same place. You don't want one to drop because they couldn't get a segment that was removed from the playlist.

Should there be multiple MEDIA-SEQUENCE in a live m3u8?

No. See also: https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/event_playlist_construction

Is TARGETDURATION needed?

No, it isn't required.

0
Ole Ul On

1: Should there be multiple MEDIA-SEQUENCE in a live m3u8? When you adds a new .ts media file to the m3u8, and deletes the oldest streams from the file at that time you should increment the MEDIA-SEQUENCE by 1.

  1. Is TARGETDURATION needed? I prefer if the video player can guess the target duration so that I don't have to keep track of it. TARGETDURATION Specifies the maximum media-file duration. It's not mandatory but should be used for best practice.
  2. If you implement step 1 it should not buffer in Live streaming. It's looks ok for live streaming.