videojs / http-streaming

HLS, DASH, and future HTTP streaming protocols library for video.js
https://videojs-http-streaming.netlify.app/
Other
2.53k stars 425 forks source link

Videojs miscalculates segments start/end for some .m3u8 streams #1554

Open Dexmaster opened 4 days ago

Dexmaster commented 4 days ago

Description: Processing audio from some .m3u8 stream places every segment at start of playback. (even if there are 3-4 segments)

Longer description: If you check Buffered Ranges: Duration and startOfSegment for audio2/2 you will see the issue. (also I believe SegmentLoader[main] >,timinginfo: audio - start/end is also wrong)

Another observation, for this case segmentInfo.segment.syncInfo has all the correct info, the broken info is segmentInfo.startOfSegment...

From logs when it tries to play segment:

48k/**audio 0/2**.aac
segment [0/2] segment start/end [undefined => undefined] startOfSegment [0] duration [5.294] timeline [0] selected by [getMediaInfoForTime (currentTime 0)] playlist [0-**redacted**]
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,trackinfo update,{"hasAudio":true,"hasVideo":false}
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,Adding audioBuffer with codec mp4a.40.5 to mediaSource
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,timinginfo: audio - start - 0
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,timinginfo: audio - end - 5.294666666666667
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,Appending segment 0's 32603 bytes to audioBuffer
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,WAITING -> APPENDING
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,received "updateend" event for audio Source Buffer: ,Buffered Ranges: 
0 --> 5.294149. Duration (5.294149)

VIDEOJS:,DEBUG:,VHS:,SyncController >,time mapping for timeline 0: [time: 0] [mapping: 0]
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,APPENDING -> READY
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,Appended segment [0/2] segment start/end [0 => 5.294666666666667] startOfSegment [0] duration [5.294] timeline [0] selected by [getMediaInfoForTime (currentTime 0)] playlist [0-**redacted**]
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,READY -> WAITING
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,Requesting
48k/**audio 1/2**.aac
segment [1/2] segment start/end [undefined => undefined] startOfSegment [5.294666666666667] duration [10.031] timeline [0] selected by [mediaIndex/partIndex increment] playlist [0-**redacted**]
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,timinginfo: audio - start - 0
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,timinginfo: audio - end - 10.032
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,Appending segment 1's 60629 bytes to audioBuffer
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,WAITING -> APPENDING
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,received "updateend" event for audio Source Buffer: ,Buffered Ranges: 
0 --> 10.03102. Duration (10.03102)

VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,APPENDING -> READY
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,Appended segment [1/2] segment start/end [0 => 10.032] startOfSegment [5.294666666666667] duration [10.031] timeline [0] selected by [mediaIndex/partIndex increment] playlist [0-**redacted**]
VIDEOJS:,DEBUG:,VHS:,PlaylistSelector >,choosing {"id":"0-**redacted**","bandwidth":47000,"codecs":"mp4a.40.5"} using bandwidthBestRep with options,{"bandwidth":12094527,"width":640,"height":264,"limitRenditionByPlayerDimensions":true,"audioOnly":true}
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,READY -> WAITING
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,Requesting
48k/**audio 2/2**.aac
segment [2/2] segment start/end [undefined => undefined] startOfSegment [10.032] duration [9.984] timeline [0] selected by [mediaIndex/partIndex increment] playlist [0-**redacted**]
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,timinginfo: audio - start - 0
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,timinginfo: audio - end - 9.985555555555555
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,Appending segment 2's 60107 bytes to audioBuffer
VIDEOJS:,DEBUG:,VHS:,SegmentLoader[main] >,WAITING -> APPENDING
VIDEOJS:,DEBUG:,VHS:,SourceUpdater >,received "updateend" event for audio Source Buffer: ,Buffered Ranges: 
0 --> 10.03102. Duration (10.03102)

Reduced test case: Here

Steps to reproduce: Click play in test case and check sound/network/debug Audio Buffered is length of the biggest audio chunk in .m3u8 (it buffers all audio chunks on top of each other at the start)

P.S. Stream works well on hls.js demo but I would prefer to use it with video.js as I setup 5 different station options on my Home Assistant stream page and not all of them are hls.

Errors: No errors in console.

What version of Video.js are you using? Reproducible in all versions from 7.0.0 to 8.20.0 (tested at least 8 different versions in each)

What browser(s) including version(s) does this occur with? Chrome, Firefox, Edge

What OS(es) and version(s) does this occur with? Win 10 and 11, Android?

Other observations: Stream works perfectly well in hls.js demo and VLC.

welcome[bot] commented 4 days ago

👋 Thanks for opening your first issue here! 👋

If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

Dexmaster commented 4 days ago

Another observation, for now I have a fix for myself so no hurry.

To fix it I rolled back video.js to v7 and using latest hls.js as a plugin. e.g. video.js 7.21.6 + hls 1.5.17 + this plugin source + small modification to plugin code to just exctract main and plugin source.

It works with everything I needed.

If anyone will need example tell me I can create a demo.