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

Manifest with different subtitle track order than existing video TextTracks breaks caption display and selection #4571

Closed
5 tasks done
SivanA-Kaltura opened this issue Feb 20, 2022 · 6 comments · Fixed by #5880
Labels
Milestone

Comments

@SivanA-Kaltura
Copy link
Contributor

What version of Hls.js are you using?

1.1.5

What browser (including version) are you using?

Chrome 98.0.4758.102 (x86_64)

What OS (including version) are you using?

macOS Big Sur

Test stream

https://codepen.io/sivana-kaltura/pen/oNoqwba

Configuration

{
  debug:true
}

Additional player setup steps

No response

Checklist

  • The issue observed is not already reported by searching on Github under https:/video-dev/hls.js/issues
  • The issue occurs in the stable client (latest release) on https://hls-js.netlify.com/demo and not just on my page
  • The issue occurs in the latest client (main branch) on https://hls-js-dev.netlify.com/demo and not just on my page
  • The stream has correct Access-Control-Allow-Origin headers (CORS)
  • There are no network errors such as 404s in the browser console when trying to play the stream

Steps to reproduce

  1. Play first video
  2. Go to 1:00 and verify that english captions are showing
  3. Click on change media
  4. Play second video
  5. Go to 2:00 and verify that english captions are not showing

Expected behaviour

English captions are showing in both videos.

What actually happened?

English captions are not showing in second video.

Some additional information after debugging:
In manifest 1, english is at index 0 and swedish is at index 1
In manifest 2, german is at index 0 and english is at index 1

  1. After changing media, subtitle-track-controller sets video element.textTracks[0].mode="disabled" (english)
    and video element.textTracks[1].mode="showing" (swedish)
  2. subtitle-stream-controller sets currentTrackId = 1
  3. When timeline-controller receives a cue for level 1, it checks
    this.textTracks[1].mode and because its "disabled", no cues are appended

Console output

It's over the max length limit :(

Chrome media internals output

No response

@SivanA-Kaltura SivanA-Kaltura added Bug Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Feb 20, 2022
@mtoczko
Copy link
Collaborator

mtoczko commented Feb 20, 2022

Hi @SivanA-Kaltura
This will help you solve the problem

hls.js/demo/main.js

Lines 340 to 376 in 492a103

onDemoConfigChanged(true);
console.log('Using Hls.js config:', hlsConfig);
self.hls = hls = new Hls(hlsConfig);
logStatus('Loading manifest and attaching video element...');
const expiredTracks = [].filter.call(
video.textTracks,
(track) => track.kind !== 'metadata'
);
if (expiredTracks.length) {
const kinds = expiredTracks
.map((track) => track.kind)
.filter((kind, index, self) => self.indexOf(kind) === index);
logStatus(
`Replacing video element to remove ${kinds.join(' and ')} text tracks`
);
const videoWithExpiredTextTracks = video;
video = videoWithExpiredTextTracks.cloneNode(false);
video.removeAttribute('src');
video.volume = videoWithExpiredTextTracks.volume;
video.muted = videoWithExpiredTextTracks.muted;
videoWithExpiredTextTracks.parentNode.insertBefore(
video,
videoWithExpiredTextTracks
);
videoWithExpiredTextTracks.parentNode.removeChild(
videoWithExpiredTextTracks
);
}
addChartEventListeners(hls);
addVideoEventListeners(video);
hls.loadSource(url);
hls.autoLevelCapping = levelCapping;
hls.attachMedia(video);

@SivanA-Kaltura
Copy link
Contributor Author

SivanA-Kaltura commented Feb 21, 2022

Thanks @mtoczko.
This can be a workaround, however it can introduce a different set of problems, depending on the page a player in hosted on. In most cases it's also not required if the order of the subtitle tracks did not change.

Since hls.js reuses text tracks in timeline-controller, this could be resolved by mapping a video element track index to a manifest track index, or by allowing track selection by name/label and not by index, but it's a design decision whether to fix or to leave as a limitation.

@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 Jul 14, 2022
@robwalch
Copy link
Collaborator

robwalch commented Jan 5, 2023

Tested this against v1.2.9 and found another issue. The first HLS produces an English TextTrack of kind "captions" but the second HLS expects one of kind "subtitles". This may be a regression introduced after this issue was reported, made to match the track kind values produced by Safari.

Please have a look at how the change in this branch changes the outcome: https:/video-dev/hls.js/compare/bugfix/texttrack-reuse-mixed-kind.

HLS.js will respond to TextTrack state changes so that track selection can be performed in the DOM or on the HTMLMediaElement. The state of reused tracks or a change made in setup may be overriding the default HLS subtitles for a new player instance > loadSource.

If video element reuse and native TextTrack rendering and selection is something you need, please consider contributing a fix. If not, the renderTextTracksNatively configuration options disables HLS.js's use of TextTracks completely so that applications can handle subtitles and captions themselves.

@giladna
Copy link
Contributor

giladna commented Mar 30, 2023

@robwalch do you think this issue will have a fix in upcoming versions?

@robwalch
Copy link
Collaborator

do you think this issue will have a fix in upcoming versions?

Would Kaltura be willing to contribute a fix?

@robwalch
Copy link
Collaborator

robwalch commented Apr 4, 2023

Hi @giladna and @SivanA-Kaltura,

#5371 is a start. The default media option is selected after calling hls.loadSource again on the same player instance with the same video element even when the index of that option is different than the it was in the previous stream. It looks like there were just a couple flags preventing default track selection from happening when using a single instance to load multiple sources. I think with the latest release if you used a new player instance for each asset this would not be an issue.

Sorry I spoke too soon. The issue with default track selection is just the tip of the iceberg.

@robwalch robwalch modified the milestones: 1.4.0, 1.5.0 Apr 4, 2023
robwalch added a commit that referenced this issue Apr 4, 2023
…abling and find match when indexes do not align

#4571
@robwalch robwalch changed the title Manifest files with a different order of subtitles break caption display Manifest with different subtitle track order than existing video TextTracks breaks caption display and selection Apr 7, 2023
robwalch added a commit that referenced this issue Apr 7, 2023
robwalch added a commit that referenced this issue Apr 7, 2023
…abling and find match when indexes do not align

#4571
robwalch added a commit that referenced this issue Jun 28, 2023
robwalch added a commit that referenced this issue Jun 28, 2023
…abling and find match when indexes do not align

#4571
robwalch added a commit that referenced this issue Sep 1, 2023
…enabling and find match when indexes do not align

- Reset default subtitle track selection on manifest loading and do not disable on detach
Fixes #4571
robwalch added a commit that referenced this issue Sep 1, 2023
…enabling and find match when indexes do not align

- Reset default subtitle track selection on manifest loading and do not disable on detach
Fixes #4571
robwalch added a commit that referenced this issue Sep 12, 2023
…enabling and find match when indexes do not align

- Reset default subtitle track selection on manifest loading and do not disable on detach
Fixes #4571
robwalch added a commit that referenced this issue Oct 5, 2023
…ons TextTrack rather than subtitleTrack index

Resolves #4571
robwalch added a commit that referenced this issue Oct 5, 2023
…ons TextTrack rather than subtitleTrack index

Resolves #4571
robwalch added a commit that referenced this issue Oct 10, 2023
…ed TextTracks (#5880)

* Use subtitle track name and language to find and match subtitle/captions TextTrack rather than subtitleTrack index
Resolves #4571

* Fix regression in dev where AUDIO_TRACKS_UPDATED is re-dispatched with zero tracks
Allow selection of audioTrack on AUDIO_TRACKS_UPDATED (overriding default selection - Resolves #5831)
Cleanup selection of subtitleTrack on SUBTITLE_TRACKS_UPDATED (overriding default selection)

* Fix TextTrack use with ASSOC-LANGUAGE
Match the initial default/forced/autoselect choice made when playing HLS in Safari
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants