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.79k stars 2.57k forks source link

Irregular fmp4 fragment durations with "progressive" setting #6764

Open mcassagnes opened 1 week ago

mcassagnes commented 1 week ago

What do you want to do with Hls.js?

Hi, given a HLS VOD with fragmented mp4s (6s fragments, 2s chunks) using byterange requests, I'm wondering why the loaded fragments are of different durations when using the fetch-loader vs xhr-loader.

Given this stream: https://hlsjs.video-dev.org/demo/?src=https%3A%2F%2Fd3bao5x7qmqzgm.cloudfront.net%2Fchunked%2Fmaster.m3u8&demoConfig=eyJlbmFibGVTdHJlYW1pbmciOnRydWUsImF1dG9SZWNvdmVyRXJyb3IiOnRydWUsInN0b3BPblN0YWxsIjpmYWxzZSwiZHVtcGZNUDQiOmZhbHNlLCJsZXZlbENhcHBpbmciOi0xLCJsaW1pdE1ldHJpY3MiOi0xfQ==

Example with xhr-loader showing consistent ~6s fragments for audio and video in the Timeline:

{
  "debug": true,
  "enableWorker": true,
  "backBufferLength": 90,
  "progressive": false
}
Screenshot 2024-10-09 at 9 36 24 PM

Example with fetch-loader showing fragments of varying durations in the Timeline:

{
  "debug": true,
  "enableWorker": true,
  "backBufferLength": 90,
  "progressive": true
}
Screenshot 2024-10-09 at 9 37 28 PM

The reason I am interested in using fetch-loader is to reduce startup time by allowing playback as soon as a chunk is downloaded rather than a full fragment. Is there a less experimental way to achieve this that you recommend?

Thank you

What have you tried so far?

I wanted to try next:

robwalch commented 1 day ago

I'm guessing this is an issue with parseSegmentIndex or getDuration in mp4-tools and/or the progressive pipeline expecting only one moof in each segment such that it can always get the complete duration of a segment on first usable chunk.

HLS.js updates the parsed playlist model to reflect the duration of parsed media. We don't want to change that, but we do want to represent the duration of segments correctly whether or not they are loaded and parsed in "progressive" mode.

Let me know if this specific bug is something you'd be willing to debug further and provide a fix for. If so I can help root-cause to point you in the right direction.