video-dev / hls.js

HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
https://hlsjs.video-dev.org/demo
Other
14.81k stars 2.57k forks source link

Is there a way to ignore Fragment(video=xyz) order when playing files with different base urls? #4993

Closed dannyseismic closed 1 year ago

dannyseismic commented 1 year ago

What do you want to do with Hls.js?

I don't know if this is a bug, or if there's some critical piece of metadata I'm missing...

I want to assemble a playlist of various HLS fragments. This seems to work as long as the fragments are put together in increasing video=xyz order, but it seems to fail if that order ever stays the same or decreases.

This fails to load the second video (2 different videos video1 and video2 starting with the same offset)

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:11
#EXTINF:10.416666,no-desc
https://media.somewhere.com/video1/QualityLevels(123)/Fragments(video=0,format=m3u8-aapl)
#EXTINF:10.427083,no-desc
https://media.somewhere.com/video2/QualityLevels(123)/Fragments(video=0,format=m3u8-aapl)
#EXT-X-ENDLIST

Both videos segments play fine as long as they are the only one in the file.

This works (Same video1, but video2 has a higher fragment number)

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:11
#EXTINF:10.416666,no-desc
https://media.somewhere.com/video1/QualityLevels(123)/Fragments(video=0,format=m3u8-aapl)
#EXTINF:10.427083,no-desc
https://media.somewhere.com/video2/QualityLevels(123)/Fragments(video=10000000,format=m3u8-aapl)
#EXT-X-ENDLIST

What have you tried so far?

I tried looking to see if there is some sort of additional metadata I need to put to change the base URL (and I don't see anything). I tried putting the videos in the m3u8 file in different orders to see what would happen.

I am using hls.js through react-player, but I also tried https://hls-js.netlify.app/demo player with the same results.

When the initial file loads, the correct number of total seconds for the video flashes on the status bar, but then it seems to discount the 2nd file in the list and changes the total number of seconds.

robwalch commented 1 year ago

Hi @dannyseismic,

The URL is not relevant in this case. What matters is that segments have contiguous media samples and timestamps. For an HLS player to play through segments that are not contiguous (e.g. not ordered segments of the same mp4 or transport stream) they need to marked in the playlist with a #EXT-X-DISCONTINUITY tag:

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:11
#EXTINF:10.416666,no-desc
https://media.somewhere.com/video1/QualityLevels(123)/Fragments(video=0,format=m3u8-aapl)
#EXT-X-DISCONTINUITY
#EXTINF:10.427083,no-desc
https://media.somewhere.com/video2/QualityLevels(123)/Fragments(video=0,format=m3u8-aapl)
#EXT-X-ENDLIST

Any time you insert segments in a playlist that were not segmented that way, you must signal a discontinuity with this tag. If you are dealing with fmp4 segments than you also need to be careful to include the initialization segments as well (EXT-X-MAP).