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

Switching audio tracks is not working properly #6962

Closed
5 tasks done
gjanblaszczyk opened this issue Jan 18, 2025 · 4 comments · May be fixed by #6963
Closed
5 tasks done

Switching audio tracks is not working properly #6962

gjanblaszczyk opened this issue Jan 18, 2025 · 4 comments · May be fixed by #6963
Labels
Bug Confirmed Bug report confirmed or reproduced. Suggested-Workaround
Milestone

Comments

@gjanblaszczyk
Copy link
Contributor

gjanblaszczyk commented Jan 18, 2025

What version of Hls.js are you using?

1.5.19

What browser (including version) are you using?

Chrome 132.0.6834.83

What OS (including version) are you using?

Windows 10, Mac OS X, Ubuntu 22.04

Test stream

https://hlsjs.video-dev.org/demo/?src=https%3A%2F%2Fqcdn.screen9.com%2Fmedia%2Fm%2FH%2FmHZBquU3eCmLzwO3vXq0Vg_auto_hls.ssl.m3u8%3Fauth%3DPGeCUq3_tpmkQlOOdC3ALUPdIvQ21OPGUDvSbUe2jOyHo1jn2fTXw0vOyynaj02hYzdamtkti3LZt69sXFpjjw&demoConfig=eyJlbmFibGVTdHJlYW1pbmciOnRydWUsImF1dG9SZWNvdmVyRXJyb3IiOnRydWUsInN0b3BPblN0YWxsIjpmYWxzZSwiZHVtcGZNUDQiOmZhbHNlLCJsZXZlbENhcHBpbmciOi0xLCJsaW1pdE1ldHJpY3MiOi0xfQ==

Configuration

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

Additional player setup steps

No response

Checklist

Steps to reproduce

  1. Go to https://hlsjs.video-dev.org/demo/?src=https%3A%2F%2Fqcdn.screen9.com%2Fmedia%2Fm%2FH%2FmHZBquU3eCmLzwO3vXq0Vg_auto_hls.ssl.m3u8%3Fauth%3DPGeCUq3_tpmkQlOOdC3ALUPdIvQ21OPGUDvSbUe2jOyHo1jn2fTXw0vOyynaj02hYzdamtkti3LZt69sXFpjjw&demoConfig=eyJlbmFibGVTdHJlYW1pbmciOnRydWUsImF1dG9SZWNvdmVyRXJyb3IiOnRydWUsInN0b3BPblN0YWxsIjpmYWxzZSwiZHVtcGZNUDQiOmZhbHNlLCJsZXZlbENhcHBpbmciOi0xLCJsaW1pdE1ldHJpY3MiOi0xfQ==
  2. Start the video and enable sound if it is muted. You should hear the default audio track without audio description.
  3. Go to the Audio Tracks tab and switch the audio track to the second one in the list. This track should include audio description. The narrator's voice should play from the 1st to the 13th second.
  4. Then, switch the audio track back to the first one (without audio description) and rewind the playback to the first second to listen to the track.

Expected behaviour

Throughout the entire length of the video, you should hear the original audio track without any narrator comments from the audio description.

What actually happened?

When the audio track is switched to the audio description track between 0-5 seconds of the video, then after switching back to the original track and replaying the video from the beginning, you will hear the narrator's voice from the audio description track until the 5th second. After the 5th second, the correct original audio track will play.

If the switch to the audio description track occurs between 5-10 seconds, then after switching back to the original track, you will hear the original track from 0 to 5 seconds and from 10 seconds to the end of the video. However, between 5-10 seconds, the narrator's voice from the audio description track will still play.

In general, strange behavior occurs when switching between audio tracks multiple times. I tested this video on other players, and audio track switching worked without issues, so I believe this is unlikely to be a problem with the HLS playlist itself but who knows...

I would appreciate any suggestions and would be happy to provide additional information if needed.

Console output

Console output looks normal except for this warning that sometimes occurs: 
`transmuxer-interface.ts:394 [warn] > MPEG-TS PMT found at 5828 after unknown PID '256'. Backtracking to sync byte @0 to parse all TS packets.`

Chrome media internals output

@gjanblaszczyk gjanblaszczyk added Bug Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Jan 18, 2025
@robwalch
Copy link
Collaborator

robwalch commented Jan 18, 2025

The buffered audio is not being flushed because both audio tracks share the same name and language.

You could workaround the issue by changing the name of the media tag with CHARACTERISTICS="public.accessibility.describes-video" to something like "Svenska (audio description)"

Tracks with different characteristics are not identical so hls.js should flush the buffered audio on track change. Thank you for reporting this bug. I'll come up with a fix and patch the latest stable release.

@robwalch robwalch added Confirmed Bug report confirmed or reproduced. and removed Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Jan 18, 2025
@robwalch robwalch modified the milestones: 1.6.0, 1.5.20 Jan 18, 2025
@robwalch
Copy link
Collaborator

robwalch commented Jan 18, 2025

private flushAudioIfNeeded(switchingTrack: MediaPlaylist) {
const { media, bufferedTrack } = this;
const bufferedAttributes = bufferedTrack?.attrs;
const switchAttributes = switchingTrack.attrs;
if (
media &&
bufferedAttributes &&
(bufferedAttributes.CHANNELS !== switchAttributes.CHANNELS ||
bufferedTrack.name !== switchingTrack.name ||
bufferedTrack.lang !== switchingTrack.lang)

There are helper functions like mediaAttributesIdentical and matchesOption which would be better suited to handle this conditional.

@robwalch
Copy link
Collaborator

Here's the fix in main #6963. After merging we can cherry pick it into patch/v1.5.x and cut release v1.5.20.

@gjanblaszczyk
Copy link
Contributor Author

Thank you so much, @robwalch , for checking and solving the issue. You make my day! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed Bug report confirmed or reproduced. Suggested-Workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants