Search code examples
iosiphoneffmpegvideo-streaminghttp-live-streaming

How to make HLS start from the begining


I need some help with HLS streaming, I'm trying to create a playlist for streaming,

I'm using ffmpeg to generate the files and the .m3u8 files. And for playing i'm using a web page with videojs player

The idea is to simulate a live streaming using files already created.

The problem is that in some version of iphone works and in another does not work. The problem is that when I start play the video in the Safari browser of my phone it freezes for a while and then download and play the last segment.

for example if the video is split in 4 differents .ts files. It starts playing from the 4th .ts file and then stop.

The problem is that I have 2 iphone mobile phone, one of them works perfectly but the other one not

The not working cell phone is a iphone 6 (version 9.2.1)

Here is my m3u8 file. Note that I'm using the #EXT-X-PLAYLIST-TYPE:EVENT and I remove the #EXT-X-ENDLIST from the botton. So it should be played as an live streaming.

It works for another phones, it begins from the 0 second when I set the #EXT-X-START:TIME-OFFSET=0

but in this version (9.2.1) the video freezes and then jumps to the last segment (webinar-3.ts) plays that segment and finally stop.

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:NO
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-START:TIME-OFFSET=0
#EXT-X-TARGETDURATION:6
#EXTINF:5.046444,
webinar-0.ts
#EXTINF:5,
webinar-1.ts
#EXTINF:5,
webinar-2.ts
#EXTINF:5,
webinar-3.ts

Have anybody got an idea of what i'm doing wrong or how to get a m3u8 config that works for this iphone version?


Solution

  • From section 6.3.3 of the HLS specification:

    If the EXT-X-ENDLIST tag is not present and the client intends to play the media normally, the client SHOULD NOT choose a segment which starts less than three target durations from the end of the Playlist file.

    In your case, this means the player will start playing from webinar-3.ts. As there are no more segments in the playlist, the video will then stop. In other words, the behaviour you are seeing is correct.

    The EXT-X-START tag, which allows you to specify the starting point of a video, was introduced in version 6 of the protocol (not version 4) so you should change the value of the EXT-X-VERSION tag in your playlist accordingly.

    If you want to start playback from the beginning of the video (and the event isn't live) why not just create a VOD playlist? Add all the segments to the playlist, remove the EXT-X-PLAYLIST-TYPE tag (or set it to VOD), then add the EXT-X-ENDLIST tag to the end of the playlist.