Skip to content
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

Frame accurate seeking in HLS #6649

Closed
fredrikj opened this issue Aug 26, 2024 · 4 comments
Closed

Frame accurate seeking in HLS #6649

fredrikj opened this issue Aug 26, 2024 · 4 comments

Comments

@fredrikj
Copy link
Contributor

fredrikj commented Aug 26, 2024

My HLS streams (transcoded from MP4 files with AWS MediaConvert) always get a time offset of 0.213 seconds. This causes time update events and seeking to be off by this much time. Is it an inevitable deficiency of HLS to not be frame accurate, or does HLS.js have a way to solve this?

@fredrikj fredrikj added Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. Question labels Aug 26, 2024
@robwalch
Copy link
Collaborator

robwalch commented Aug 26, 2024

This is usually the result of audio priming or video composition time pushing frame rendering times on the HTMLVideoElements timeline out a bit.

does HLS.js have a way to solve this?

On Hls.Events.BUFFER_APPENDED get the different between the start of the video buffer and the fragment start time of the first appended segment with video:

let tOffset = 0;
const getAppendedOffset = (eventName, { frag }) => {
  if (frag.type === 'main' && frag.sn !== 'initSegment' && frag.elementaryStreams.video) {
    const { start, startDTS, startPTS, maxStartPTS, elementaryStreams } = frag;
    tOffset = elementaryStreams.video.startPTS - start;
    hls.off(Hls.Events.BUFFER_APPENDED, getAppendedOffset);
    console.log('video timestamp offset:', tOffset, { start, startDTS, startPTS, maxStartPTS, elementaryStreams });
  }
}
hls.on(Hls.Events.BUFFER_APPENDED, getAppendedOffset);

@robwalch robwalch removed the Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. label Aug 26, 2024
@fredrikj
Copy link
Contributor Author

Thank you! That solves my issue. Seems to me that this information deserves a place in the documentation, such as in
https://github.com/video-dev/hls.js/tree/master?tab=readme-ov-file#using-hlsjs

@robwalch
Copy link
Collaborator

Thank you for the suggestion @fredrikj. Would you submit a PR adding that documentation?

@robwalch
Copy link
Collaborator

robwalch commented Oct 2, 2024

Marking as closed with #6658. Thank you @fredrikj 😃

@robwalch robwalch closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants