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

Support download bundles #5615

Open
levz opened this issue Mar 10, 2019 · 3 comments
Open

Support download bundles #5615

levz opened this issue Mar 10, 2019 · 3 comments
Assignees

Comments

@levz
Copy link

levz commented Mar 10, 2019

[REQUIRED] Searched documentation and issues

Searched for info:

[REQUIRED] Question

This is a hacky question, but is there a way to add SRT file as subtitles track in ManifestParser? (without using MergeSource)

I have HLS content + subtitles for it stored as a separate SRT file on the server. I would like to download HLS content with subtitles using download service as desribed here:
https://medium.com/google-exoplayer/downloading-streams-6d259eec7f95

General download works fine, but I cannot tell DownloadService to download SRT file because it is not a track (can't create StreamKey for it) until I merge it in using MergedMediaSource.

As a workaround I created a custom ManifestParser and custom HlsDownloadAction and HlsDownloader classes using custom ManifestParser. (This part works - I can download HLS successfully).
Then in manifest parser I try to create subtitles track artificially with:

private HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, String baseUri) throws IOException {
    ... 

    // adding my custom track here
    subtitles.add(new HlsMasterPlaylist.HlsUrl(textTrack.getUrl(), buildTextFormat(textTrack.getLocale())));

    return new HlsMasterPlaylist(baseUri, tags, variants, audios, subtitles, muxedAudioFormat,
        muxedCaptionFormats, false, Collections.EMPTY_MAP); 
}

This creates the track, but it does not work, because it expects url of the manifest and I provide url for SRT file. I have tried to intercept the request for this url and provide a "hand made" HlsPlaylist:

 @Override
  public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    Queue<String> extraLines = new ArrayDeque<>();
    String line;
    try {
      // catch request for SRT file and provide artificial response
      if (uri.toString().toLowerCase().endsWith(".srt")){
          return mimicSubtitlesPlaylist(uri);
      }
     ...
}
...
private HlsMediaPlaylist mimicSubtitlesPlaylist(Uri uri){

      List<Segment> segments = new ArrayList<>();
      segments.add(new Segment(
              uri.toString(),
              0,
              -1
      ));

      return new HlsMediaPlaylist(
              0,
              uri.toString(),
              new ArrayList<String>(),
              0,
              0,
              false,
              0,
              0,
              1,
              Long.MAX_VALUE,
              false,
              false,
              false,
              null,
              segments);
  }

But this also fails (it hangs forever on buffering when I try to enable this track with selection override).

I'm quite sure that there is a way to add SRT file as a track, but got somewhat lost in codes.
Could you give me some clues how to get there?

@AquilesCanta
Copy link
Contributor

I'd suggest downloading them independently, using ProgressiveDownloader for the subtitle file, and HlsDownloader for the HLS stream. Then locally, use a merging media source, as per usual.

I cannot think of a proper way of treating SRT subtitles as part of an HLS media source. It's worth mentioning that SRT subtitles are not supported by the HLS specification. I'll assign @erdemguven in case anything I said doesn't make sense. Hope this answers your question.

@levz
Copy link
Author

levz commented Mar 12, 2019

Thanks for looking into this.

I'd suggest downloading them independently, using ProgressiveDownloader for the subtitle file, and HlsDownloader for the HLS stream. Then locally, use a merging media source, as per usual.

This is something I hope I could avoid - this will create 2 download tasks for the same download content and it will be confusing for the end user.

I cannot think of a proper way of treating SRT subtitles as part of an HLS media source. It's worth mentioning that SRT subtitles are not supported by the HLS specification. I'll assign @erdemguven in case anything I said doesn't make sense. Hope this answers your question.

Yes, but is there a way maybe to treat SRT subtitles as something else - can I put some tags and/or settings to Segment object that I create manually, so that Exoplayer creates a simple sample source out of provided url and merges it in automatically?

@erdemguven
Copy link
Contributor

it will be confusing for the end user.

Perhaps you can hide srt downloads from user. Or you can just directly download srt file using CacheUtil.cache method without using DownloadManager.

Yes, but is there a way maybe to treat SRT subtitles as something else - can I put some tags and/or settings to Segment object that I create manually, so that Exoplayer creates a simple sample source out of provided url and merges it in automatically?

Merge SRT to HLS playlist? Exoplayer don't support rewriting playlist so even if you change the in memory state of it, it won't be persisted. Also as @AquilesCanta pointed HLS doesn't support SRT.

The ideal solution would be adding support for download bundles so I will change this to a feature request but I can't promise it will be implemented.

@erdemguven erdemguven changed the title How to download HLS stream and SRT subtitles file altogather? Support download bundles Apr 15, 2019
@tonihei tonihei assigned ojw28 and unassigned erdemguven Aug 21, 2019
@ojw28 ojw28 assigned marcbaechinger and unassigned ojw28 Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants