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.47k stars 2.55k forks source link

Missing audio in first segment #5132

Open tvinko opened 1 year ago

tvinko commented 1 year ago

What version of Hls.js are you using?

v1.2.9

What browser (including version) are you using?

Chrome, Safari , FF

What OS (including version) are you using?

MacOS Ventura 13.1

Test stream

Configuration

{
  "debug": true,
  "enableWorker": true,
  "lowLatencyMode": true,
  "backBufferLength": 90
}

Additional player setup steps

No response

Checklist

Steps to reproduce

  1. open the link
  2. at 9s console displays Playback stalling at @9.505881 due to low buffer ({"len":0.09411899999999918,"start":0,"end":9.6}) message
  3. video freezes at this point

Expected behaviour

Video plays normally

What actually happened?

Click on Recover media-error button does some trick to recover the video from proceeding from this point.

If I try to recover from media error automatically I have to add setTimeout, otherwise the recovering is ignored

hls.on(Hls.Events.ERROR, function (event, data) { if (data.type == Hls.ErrorTypes.MEDIA_ERROR) { setTimeout(function () { hls.recoverMediaError(); }, 10); } });

There are some reported issues about buffer stall errors, but I didn't find any solution how to find out why playback stalls in the first place. Can be seen from the logs if problem is in encoding or somewhere else?

Is there any elegant solution that can be done in Hls.Events.ERROR event (besides one from documentation)?

Console output

[Log] Live reload enabled. (new.html, line 921)
[Log] [log] > (hls.js, line 26312)
[Log] [log] > – "stopLoad" (hls.js, line 17823)

Chrome media internals output

No response

robwalch commented 1 year ago
hls.js:2999 [log] > [stream-controller]: PARSING->PARSED
hls.js:2284 [log] > [stream-controller]: Buffered main sn: 0 of level 1 [0.000,4.800]
hls.js:2999 [log] > [stream-controller]: PARSED->IDLE
hls.js:2380 [log] > [stream-controller]: Loading fragment 1 cc: 0 of [0-1447] level: 1, target: 4.8
hls.js:2999 [log] > [stream-controller]: IDLE->FRAG_LOADING
hls.js:11211 [log] > manifest codec:undefined, ADTS type:2, samplingIndex:3
hls.js:11361 [log] > parsed codec:mp4a.40.5, rate:48000, channels:2
hls.js:2999 [log] > [stream-controller]: FRAG_LOADING->PARSING
hls.js:2180 [log] > [stream-controller]: Loaded fragment 1 of level 1
hls.js:13632 [log] > [transmuxer.ts]: Flushed fragment 1 of level 1
hls.js:2999 [log] > [stream-controller]: PARSING->PARSED

Looks like there is an issue processing the append of the second segments (sn 1). After PARSING->PARSED we expect to see Buffered main sn: 1 of level 1 [0.000,9.534] but it never comes so buffering stalls.

robwalch commented 1 year ago

The HLS stream provided is missing the CODECS attributes on both variants (#EXT-X-STREAM-INF:). The player must therefor use the segments to determine if the stream has audio and/or video. the first segment has only video, so the player instantiates MSE with only a video buffer. The second segment has audio and video, the player then never is able to append audio because it did not create a buffer for it and the stream stalls.

While we could reset the source buffers on this kind of change, this is not a supported feature of the player. Well-formed HLS streams should signal all codecs present in their variant playlists for players to properly initialize the required buffers.

tvinko commented 1 year ago

thanks @robwalch, we have access to encoding process so we'll include CODECS attributes

robwalch commented 1 year ago

👍 you still may encounter issues with video missing from the buffer on start. It might be worth dropping that segment or figuring out why it only contains audio.

micohasanen commented 1 year ago

Just stumbled upon this error myself, got a bufferStalledError on the first second of the playlist. Interesting find: everything works perfectly on version 1.2.1. Cloudflare Stream VOD playlist. Is there anything new on this error if one has no access to the encoding process?

robwalch commented 1 year ago

Hi @micohasanen, please file a new issue and include a sample stream, logs, steps to reproduce, and any relevant regression information.

sdutwsl commented 2 weeks ago

Same error still existed, I played one stream that worked normally with mpv, but always stuck or failed with hls.js.

hls log: hls_console.log

mpv log: mpvlog.log

hope it will be helpful.

robwalch commented 2 weeks ago

Hi @sdutwsl, please file a new issue and include a sample stream, the logs, steps to reproduce, and any relevant regression information.

A buffer stall can occur because of network conditions or a number of issues with authoring or delivery of the asset. Your logs show several issues related to live refresh and segmenting unrelated to this issue which is specific to a segment with missing media track data.

robwalch commented 2 weeks ago

Related issues labeled https://github.com/video-dev/hls.js/labels/sourcebuffer-track-mismatch: