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

HLS Downloader Does Not Support Init Maps (Save Does Not Work) #400

Open
ac3d912 opened this issue Feb 11, 2025 · 2 comments
Open

HLS Downloader Does Not Support Init Maps (Save Does Not Work) #400

ac3d912 opened this issue Feb 11, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@ac3d912
Copy link

ac3d912 commented Feb 11, 2025

Describe the bug
The indication for the bug is when the video downloads to 100%; however, when the user clicks "save" nothing happens. This is due to ffmpeg failing to parse the video files. There is no error checking around the return value.

A simplistic solution can be applied to indexdb-fs.ts:

    await this.ffmpeg.deleteFile(`${this.fileName}.ts`);
    if (result == 0) {
      const data = await this.ffmpeg.readFile(`${this.fileName}.mp4`);
      return new Blob([data], { type: "video/mp4" });
    } else {
      console.error("Error converting, returning ts file");
      return blob;
    }

However, the underlying problem (at least in my case) is the missing mp4 init file, which is what caused the ffmpeg failure.

HLS Downloader does not process the "map" information returned from m3u8-parser which is from the EXT-X-MAP entry.

This information can be gained from within m3u8-parser.ts by accessing segment.map.uri, by saving that information to the Fragment it can be further propagated through the system to be downloaded and prepended to the m4s files (https://stackoverflow.com/questions/69574227/how-to-merge-init-mp4-m4s-files). However, each fragment can be associated with a different init (I've seen chunks of around 75 fragments associated with one init, then it has a new one). So each fragment needs to be associated with an init... e.g. via Record<string, Fragment>.

Likely the workflow needs to be something like...

  1. Create buckets for each init+fragments associated to that init
  2. Download the init into the bucket
  3. Download all Fragments for that init into the same bucket starting at index 1
  4. Repeat for all inits
  5. Run ffmpeg as it is on each of the buckets. This will produce a fully complete mp4 file for each bucket.
  6. Run ffmpeg again to compile all of the individual bucket mp4s into a single mp4.
  7. Save file

To Reproduce
Try to download an HLS video that uses EXT-X-MAPs

Expected behavior
The file to download, convert, and save.

Desktop (please complete the following information):

  • OS: Windows
  • Browser Firefox
  • Version 134

Additional context
I have some rough code changes which partially work, but I don't have a ton of experience with React, RxJS, or Typescript... my solution is pretty terrible.

@ac3d912 ac3d912 added the bug Something isn't working label Feb 11, 2025
@fanfanli1988
Copy link

I faced the same issue, thx for your analyze with this problem, waiting for the best solution to fix it.

@ac3d912 ac3d912 changed the title HLS Downloader Does Not Support Init Maps HLS Downloader Does Not Support Init Maps (Save Does Not Work) Feb 12, 2025
@Zugidor
Copy link

Zugidor commented Mar 16, 2025

Hey, thanks for this descriptive issue, think you could publish a fork with whatever fix you have? It's been a while and doesn't seem to be much interest from the repo owner in updating the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants