Tuesday, April 12, 2016

HLS 'EVENT' playlists failing to start in players

Leave a Comment

I have HLS playlists that look like this:

#EXTM3U #EXT-X-VERSION:3 #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:10 #EXT-X-ALLOW-CACHE:NO #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:9.97667, https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence0.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence1.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence2.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence3.ts 

They are of EVENT type, meaning, chunks are appended as they become available, and when all chunks are there, an #EXT-X-ENDLIST tag is appended at the end.

So when all chunks are uploaded, we end up with a playlist that looks something like:

#EXTM3U #EXT-X-VERSION:3 #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:10 #EXT-X-ALLOW-CACHE:NO #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence0.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence1.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence2.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence3.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence4.ts #EXTINF:9.97667,   https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence5.ts #EXT-X-ENDLIST 

We are seeing odd behaviour in all our clients. If you open the m3u8 playlist in iOS and Safari when the first chunk (or even after say, 3 chunks) are uploaded, the player will start playing the video as it should. Occasionally it will stop however, and be unable to resume. More often than not, it won't even begin playing.

Fully formed playlists (i.e. with an #EXT-X-ENDLIST tag) play perfectly. It's just when the playlist is partially done.

We have tried a variety of players: Quicktime, Safari, iOS, VLC, Flowplayer etc. All have a variety of issues, but this is the most pressing.

Any insight into where to look in solving this problem would be greatly appreciated.

Edit: We have tried HLS.js and it plays perfectly. Such a nice user experience too

Edit 2: To reproduce, I recommend having some sort of local HTTP server (I use python -m SimpleHTTPServer serving up a playlist above. Then literally append the files to the playlist to simulate the uploading of files, and watch the players break.

Edit 3: Okay, I have built a simple testing tool to observe the behaviour. https://github.com/dbousamra/m3u8-example Run node app.js and then try and open http://localhost:3001/playlist.m3u8 in Safari or whatever player you want. It should play fine, as it is a complete playlist.**

If however, you add a query param ?start=<some unix timestamp>, it will simulate appending of events, 1 chunk every 6 seconds, from that timestamp, until all chunks are done, at which point it will append an #EXT-X-ENDLIST line.

Example URL: http://localhost:3001/playlist.m3u8?start=1460092250872

Edit 5: I've got it up on Heroku now: http://guarded-mesa-71212.herokuapp.com/playlist.m3u8?start=

3 Answers

Answers 1

Here is what happened:

#EXTM3U #EXT-X-VERSION:6 #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:11 #EXT-X-ALLOW-CACHE:NO #EXT-X-MEDIA-SEQUENCE:0 

if you return the above file, safari will not request the next file at all, the playing just dead.

#EXTM3U #EXT-X-VERSION:6 #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:11 #EXT-X-ALLOW-CACHE:NO #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:9.999367, https://cammy-bucket-staging-sydney.s3.amazonaws.com/9fc1a264af66e8acb04953bc6634fb6e.ts 

if you return the above, safari will request next file around 11/2 seconds, playing will not start at this point.

#EXTM3U #EXT-X-VERSION:6 #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:11 #EXT-X-ALLOW-CACHE:NO #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:9.999367, https://cammy-bucket-staging-sydney.s3.amazonaws.com/9fc1a264af66e8acb04953bc6634fb6e.ts #EXTINF:9.968911, https://cammy-bucket-staging-sydney.s3.amazonaws.com/3e52720b320379de8afc940c3d1b7d34.ts 

if you return the above, safari will start playing because the available media 9.999367+9.968911 is great than EXT-X-TARGETDURATION, and you will see another request around 9.999367+9.968911+11/2, it's all about timing!

Answers 2

The #EXT-X-DISCONTINUITY tag is used to indicate changes in file format, encoding parameters, number of tracks, and so on. If the segments in the playlist are identical in regard to these things, you can remove the #EXT-X-DISCONTINUITY tags from the playlist - you don't need them.

Some clients may not be compatible with version 6 of the protocol. You don't appear to be using any version 6 specific features so try setting the version number to 3 to see if that helps.

Answers 3

try something like this

Simple Media Playlist file

   #EXTM3U    #EXT-X-VERSION:3    #EXT-X-TARGETDURATION:5220    #EXTINF:5219.2,    http://media.example.com/entire.ts    #EXT-X-ENDLIST 

Sliding Window Media Playlist, using HTTPS

 #EXTM3U    #EXT-X-VERSION:3    #EXT-X-TARGETDURATION:8    #EXT-X-MEDIA-SEQUENCE:2680     #EXTINF:7.975,    https://priv.example.com/fileSequence2680.ts    #EXTINF:7.941,    https://priv.example.com/fileSequence2681.ts    #EXTINF:7.975,    https://priv.example.com/fileSequence2682.ts 

Playlist file with encrypted media segments

#EXTM3U    #EXT-X-VERSION:3    #EXT-X-MEDIA-SEQUENCE:7794    #EXT-X-TARGETDURATION:15     #EXT-X-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=52"     #EXTINF:2.833,    http://media.example.com/fileSequence52-A.ts    #EXTINF:15.0,    http://media.example.com/fileSequence52-B.ts    #EXTINF:13.333,    http://media.example.com/fileSequence52-C.ts     #EXT-X-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=53"     #EXTINF:15.0,    http://media.example.com/fileSequence53-A.ts 

Master Playlist file

#EXTM3U    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1280000    http://example.com/low.m3u8    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2560000    http://example.com/mid.m3u8    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7680000    http://example.com/hi.m3u8    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=65000,CODECS="mp4a.40.5"    http://example.com/audio-only.m3u8 

Master Playlist with I-Frames In this example, the PROGRAM-ID attributes have been left out:

#EXTM3U    #EXT-X-STREAM-INF:BANDWIDTH=1280000    low/audio-video.m3u8    #EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=86000,URI="low/iframe.m3u8"    #EXT-X-STREAM-INF:BANDWIDTH=2560000    mid/audio-video.m3u8    #EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=150000,URI="mid/iframe.m3u8"    #EXT-X-STREAM-INF:BANDWIDTH=7680000    hi/audio-video.m3u8    #EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=550000,URI="hi/iframe.m3u8"    #EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS="mp4a.40.5"    audio-only.m3u8 

Master Playlist with Alternative audio In this example, the PROGRAM-ID attributes have been left out. The CODECS attributes have been condensed for space. A '\' is used to indicate that the tag continues on the following line with whitespace removed:

   #EXTM3U    #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="English", \       DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="en", \       URI="main/english-audio.m3u8"    #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Deutsch", \       DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="de", \       URI="main/german-audio.m3u8"    #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Commentary", \       DEFAULT=NO,AUTOSELECT=NO,URI="commentary/audio-only.m3u8"    #EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS="...",AUDIO="aac"    low/video-only.m3u8    #EXT-X-STREAM-INF:BANDWIDTH=2560000,CODECS="...",AUDIO="aac"    mid/video-only.m3u8    #EXT-X-STREAM-INF:BANDWIDTH=7680000,CODECS="...",AUDIO="aac"    hi/video-only.m3u8    #EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS="mp4a.40.5",AUDIO="aac"    main/english-audio.m3u8 

Master Playlist with Alternative video

#EXTM3U    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="low",NAME="Main", \       DEFAULT=YES,URI="low/main/audio-video.m3u8"    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="low",NAME="Centerfield", \       DEFAULT=NO,URI="low/centerfield/audio-video.m3u8"    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="low",NAME="Dugout", \       DEFAULT=NO,URI="low/dugout/audio-video.m3u8"     #EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS="...",VIDEO="low"    low/main/audio-video.m3u8     #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="mid",NAME="Main", \       DEFAULT=YES,URI="mid/main/audio-video.m3u8"    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="mid",NAME="Centerfield", \       DEFAULT=NO,URI="mid/centerfield/audio-video.m3u8"    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="mid",NAME="Dugout", \       DEFAULT=NO,URI="mid/dugout/audio-video.m3u8"     #EXT-X-STREAM-INF:BANDWIDTH=2560000,CODECS="...",VIDEO="mid"    mid/main/audio-video.m3u8     #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="hi",NAME="Main", \       DEFAULT=YES,URI="hi/main/audio-video.m3u8"    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="hi",NAME="Centerfield", \       DEFAULT=NO,URI="hi/centerfield/audio-video.m3u8"    #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="hi",NAME="Dugout", \       DEFAULT=NO,URI="hi/dugout/audio-video.m3u8"     #EXT-X-STREAM-INF:BANDWIDTH=7680000,CODECS="...",VIDEO="hi"    hi/main/audio-video.m3u8     #EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS="mp4a.40.5"    main/audio-only.m3u8 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment