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

Store external text tracks alongside main content #2016

Open
danmo opened this issue Jul 1, 2019 · 5 comments
Open

Store external text tracks alongside main content #2016

danmo opened this issue Jul 1, 2019 · 5 comments
Labels
component: captions/subtitles The issue involves captions or subtitles component: offline The issue involves the offline storage system of Shaka Player flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this priority: P3 Useful but not urgent type: enhancement New feature or request
Milestone

Comments

@danmo
Copy link

danmo commented Jul 1, 2019

Hi, Is it possible to store/download subtitle files using the Offline Storage api?

Right now I'm persisting the videos but not the .vtt files.

@danmo danmo added the type: question A question from the community label Jul 1, 2019
@joeyparrish
Copy link
Member

Yes, absolutely. The Storage API will allow you to choose which tracks (including text tracks) to store offline. There is a configurable callback (offline.trackSelectionCallback) which is called with a list of tracks and returns a subset of the ones to store. If you don't configure it, the default callback will choose the highest SD resolution, the audio language which matches the user preferences, and all text tracks (because they are cheap).

@danmo
Copy link
Author

danmo commented Jul 2, 2019

In my case, I'm using external text tracks and adding them through the addTextTrack method. Any possibility on persisting external tracks?

@joeyparrish
Copy link
Member

Ah, I see! No, we don't have that today, but I will add it to our backlog as an enhancement.

@joeyparrish joeyparrish changed the title Store subtitle .vtt files with the Offline Storage api Jul 2, 2019
@joeyparrish joeyparrish added type: enhancement New feature or request and removed type: question A question from the community labels Jul 2, 2019
@shaka-bot shaka-bot added this to the Backlog milestone Jul 2, 2019
@danmo
Copy link
Author

danmo commented Jul 3, 2019

cool, for anyone who might be bumping into this here's my solution:

  • downloaded the subtitles programmatically right before the offline .store call
  • saved the local file path into the storage metadata
  • because the player requires http transport (not file) for subtitle ingestion I'm serving the subtitle through a local server http://localhost:[port]/captions
  • delete the local file on storage removal
@ismena ismena added the component: captions/subtitles The issue involves captions or subtitles label Aug 1, 2019
@joeyparrish joeyparrish modified the milestones: Backlog, Backlog 2 Jan 28, 2020
@joeyparrish joeyparrish added priority: P3 Useful but not urgent component: offline The issue involves the offline storage system of Shaka Player labels Sep 29, 2021
@loicraux
Copy link
Contributor

loicraux commented Oct 6, 2023

cool, for anyone who might be bumping into this here's my solution:

  • downloaded the subtitles programmatically right before the offline .store call
  • saved the local file path into the storage metadata
  • because the player requires http transport (not file) for subtitle ingestion I'm serving the subtitle through a local server http://localhost:[port]/captions
  • delete the local file on storage removal

Again, for anyone bumping into this, another solution that does not require a local http server to serve the text track files with http protocol :

  1. Do download the subtitles files contents programmatically right before the call to offlineStorage.store
  2. Add to the appMetadata of the stored content an array of TextTrack data (the text contents of the text track) & metadata (the data needed to make calls to addTextTrackAsync later on at playback time)
  3. At playback time, since the player requires an http URL to load the subtitles, you can create such an url like this :
const { textTracks } = appMetadata;
const addedTextTracks = await Promise.all(
    textTracks.map(({ data, language, kind, mime, label }: TextTrackDefinition) => {
        const blob = new Blob([data], { type: mime });
        const url = URL.createObjectURL(blob);
        return player.addTextTrackAsync(url, language, kind, mime, undefined, label);
    })
);
// eslint-disable-next-line no-console
console.log(`Added ${addedTextTracks.length} text tracks`);
if (addedTextTracks.length > 0) {
    player.selectTextTrack(addedTextTracks[0]);
    player.setTextTrackVisibility(true);
}
@avelad avelad added the flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: captions/subtitles The issue involves captions or subtitles component: offline The issue involves the offline storage system of Shaka Player flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this priority: P3 Useful but not urgent type: enhancement New feature or request
6 participants