-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EXT-X-DATERANGE metadata synchronisation vs video stream in presence of frequent EXT-X-DISCONTINUITYs #6203
Comments
In HLS.js, DATERANGE tags are mapped to cues on the TextTrack timeline using playlist time (EXTINF durations). The drift occurs when media parsed and the parsed media duration differs from the duration in the playlist without the total program duration matching up once summed up. This is the case in your sample. The demo page "Timeline" tab shows the parsed segment duration slightly over 1.02s each vs the You can access DateRange data directly in HLS.js using A fix for this metadata TextTrack specific issue still requires cue timing to be updated after media is parsed (on LEVEL_PTS_UPDATED) in the id3-track-controller. We can look into a fix for this in the next release. Even after the update I would recommend using the aforementioned |
Marking as enhancement. This is not a regression. DateRange TextTrack cues are mapped to playlist time not the video track or parsed media, as of v1.5.x. When the playlist times differ this much from the parsed media (on every segment, not just discontinuity) I think it is fair to consider this a stream issue. To support Interstitials in v1.6, precise mapping of DateRanges to the playback timeline is crucial, so we can afford to compensate for these kind of discrepancies, and explore sliding cue start times (if we cannot adjust them after creating then we'll need to remove and add cues) at a usable interval. |
FYI - The DateRanges in your playlist are invalid and while this should result in them being ignored, Apple HLS clients error and will not play the sample provided. ID and date attributes are expected to be provided as quoted-string values (...bonksound.studio/hls/playlist.m3u8 is missing quotes around ID and START-DATE values and errors rather than plays in Safari and Apple HLS clients). Ex: #EXT-X-DATERANGE:ID=4.16016,START-DATE=2024-02-05T00:00:16.016000,DURATION=4.004,X-CUE=" " should be: #EXT-X-DATERANGE:ID="4.16016",START-DATE="2024-02-05T00:00:16.016000",DURATION=4.004,X-CUE=" " HLS.js is not strict about quoted-string format attribute values missing quotes. In #6213 I've added some validation logic that logs warning in to the console when missing quotes are encountered. |
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Hi @robwalch, Thank you for looking into this.
|
@Instadrum, I just added 0c5ca21 to #6213 which updates cue start and end times on PTS update. Let me know if this works for you: Just confirmed that Safari does not shift cues to align with media this way, so you'll want to make sure your Playlist EXTINF durations align with presentation time in Apple HLS clients (or relative to Safari's I don't think it hurts for HLS.js to make these adjustments as it may push the timeline out based on audio priming delays, overlaps not allowed in MSE, and other presentation time oddities the library has picked up on the way. This change will ensure we keep cues aligned with the libraries interface for DateRange and Program-Date-Time mapping and |
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Hi @robwalch, Thanks you, the test branch works as expected on our test stream. We will indeed have to find a solution for Safari. There actually is a silent audio track in our test stream (as we do have audio in our streams in production), and audio and video tracks do not end at the same moment prior to discontinuity, or do not start at the same moment right after, due to the way our compiled stream is built. I guess this issue can now be closed. Thanks a lot again for your help! |
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203
* DateRange parsing and validation enhancements for Interstitials Warn on invalid quoted-attribute attributes (missing quotes) Related to #6203 * Shift DateRange metadata Cue times when media timeline is shifted Fixes #6203 * Map DATERANGE tags to Segments with starting program date time * DATERANGE tags after the last PDT tag that start at or after that tag should be anchored to that tag * Handle DateRange mapping with Delta Playlist updates Error (but parse and merge) multiple EXT-X-SKIP tags
What version of Hls.js are you using?
1.5.4
What browser (including version) are you using?
Chromium 120.0.6099.71 (Official Build)
What OS (including version) are you using?
Linux Mint 21.2 Victoria (64-bit)
Test stream
https://hlsjs.video-dev.org/demo/?src=https%3A%2F%2Fbonksound.studio%2Fhls%2Fplaylist.m3u8&demoConfig=eyJlbmFibGVTdHJlYW1pbmciOnRydWUsImF1dG9SZWNvdmVyRXJyb3IiOnRydWUsInN0b3BPblN0YWxsIjpmYWxzZSwiZHVtcGZNUDQiOmZhbHNlLCJsZXZlbENhcHBpbmciOi0xLCJsaW1pdE1ldHJpY3MiOi0xfQ==
Configuration
Additional player setup steps
This is not a playback issue: please do not expect any errors on the demo stream page.
The issue is related to the metadata track vs video track synchronization. To observe it we need (1) a playlist constructed in a special way (details follow and the test sample is provided), and (2) a little tooling, consisting in setting up a
cuechange
listener as follows:Additional details
(Apologies for the verbosity of what follows.)
The test stream consists of several pieces of content, of a few MPEG-TS fragments each. There is a timestamp discontinuity between the subsequent pieces, so
EXT-X-DISCONTINUITY
tag is inserted in the playlist.For test purposes,
Despite its synthetic appearance, this test stream actually comes from real data we work on. We replaced its content but we kept timestamps and stream durations unchanged.
In our application, we need to be able to identify which piece is being played when the user interacts with other elements in the page. As discussed here, there are several possibilities to solve that.
currentTime
and map it to a position in the playlist. Such an estimate diverges quickly, likely because of a variable delay added in the playback time domain every time a discontinuity is encountered.EXT-X-PROGRAM-DATE-TIME
after every discontinuity and then useplayingDate
property of the corresponding HLS instance to grab the "absolute" playback time instead of using the driftingcurrenTime
. Similarly, we may listen toFRAG_CHANGED
events and get directly the name of the fragment being played. While this works well, we do not see a way to get this working with native iOS HLS implementation, sinceplayingDate
andFRAG_CHANGED
API are specific to HLS.js.For this reason we try to push this approach a bit further. After every discontinuity and its associated
EXT-X-PROGRAM-DATE-TIME
we put aEXT-X-DATERANGE
tag, to make a metadata record appearing in atextTrack
. The date-range record has its start time matching to the PDT, a duration roughly matching the length of a particular piece, and an ID attribute carrying the piece ID. So our playlist is built of repeated sections as follows:We then can use the common browser API to listen to
cuechange
events on thattextTrack
to identify which video piece is being played. Since this is not specific to HLS.js, in theory we can expect this to work with the native HLS implementation in iOS as well. As far asEXT-X-PROGRAM-DATE-TIME
is correctly inferred, andEXT-X-DATERANGE
have the same start time as the PDT tags, we should be able to get thetextTrack
in sync with the video despite all the discontinuities.The piece of JavaScript above allows to listen to these events and display the video piece ID in the browser console. We can then check whether the obtained ID matches the actual content being played.
So the issue is that those
cuechange
events actually come out of sync.A few final notes
EXT-X-PROGRAM-DATE-TIME
alone allows to identify the video piece being played usingplayingDate
API without any drift, for a 12h long playlist.Checklist
Steps to reproduce
cuechange
event listener as described in the additional player setup steps.An instrumented demo is available here.
Expected behaviour
The number printed in the browser console matches the number in the video frame, e.g., the text metadata track is in-sync with the video track.
What actually happened?
All good at the beginning, but after ~1 min there is a noticeable delay between the number in the console and the number in the video frame, of about a second (the latter is delayed with respect to the former). It does not keep increasing indefinitely though, and seems to be related to
maxBufferLength
, i.e., increasing the latter makes the delay worse.Console output
Chrome media internals output
No response
The text was updated successfully, but these errors were encountered: