mkv-extract icon indicating copy to clipboard operation
mkv-extract copied to clipboard

Extract PGS subtitle ?

Open igorcesarcode opened this issue 1 year ago • 8 comments

Would it be possible to extract PGS subtitles?

igorcesarcode avatar Aug 12 '24 14:08 igorcesarcode

I just need to add a PGS demuxer, that's the easy part, but at the moment ffmpeg.js building is not working, that's the hard part. More info here: https://github.com/qgustavor/mkv-extract/issues/40

But, to summarize, IIRC, the build script I used to build FFmpeg into WASM seems to be loading the last build of it and compiling it using Emscripten, but FFmpeg changed in a way it requires multi-threading support, which WASM can provide only if a specific HTTP header is provided in the same. So there are four options:

  • Wait until GitHub allows setting this HTTP header (which is what I have been doing)
  • Use a Service Worker to add this header (which adds extra complexity to the application)
  • Host this tool elsewhere that allows enabling this header
  • Downgrade FFmpeg to a version which still works without multi-threading

qgustavor avatar Aug 12 '24 15:08 qgustavor

If you need help compiling on Linux, I can help you.

I also have a Mac if you need it.

I just need some instructions for that.

Regarding hosting, I believe you could solve it using https://railway.app or https://vercel.com

igorcesarcode avatar Aug 12 '24 16:08 igorcesarcode

I managed to build it GitHub Actions. I will check Railway, I think that's better for me avoid using Vercel since I'm already using it for other project.

qgustavor avatar Aug 12 '24 16:08 qgustavor

There is no free plan for Railway, just a free trial, and I'm not willing to pay for hosting for this project. Since I'm already using Vercel on a free plan for other project I prefer not having two projects there (I don't remember if their TOS allow it, but even if it allows, better to avoid). I checked other free hosting I used to use, but they made their free plan worse, thus is unlikely that they will ever allow adding such header.

I guess the best option for the moment is adding a service worker: use Workbox to generate the service worker and force a reload after the first SW worker install (or show an error message if the SW wasn't installed for some reason). The good thing: the website will work offline. The bad thing: seems it's not easy to add headers using Workbox.

qgustavor avatar Aug 13 '24 13:08 qgustavor

Using Workbox seems too complicated for this use-case. Not that Workbox is complicated, I use it a lot and it's great, but I could not find many clear and easy to understand tutorials for the injectManifest mode, which would be required in this case. I will just use coi-serviceworker instead.

Edit: I need to remember to include this in the code as extracting PGS into .sup files is not handled automatically by the existing code: https://stackoverflow.com/a/72415890

qgustavor avatar Aug 15 '24 20:08 qgustavor

I tried building ffmpeg.js but something is not working. I will check it later, I spent more time than I should have spent. If someone wants to tackle this problem, I see two potential solutions:

  1. Start with davedoesdev/ffmpeg.js, check if it's compiling as described in the README, then change the Makefile to generate the MKVE build with just muxers following this example.
  2. Start with qgustavor/ffmpeg.js and find out why the code isn't compiling. The last change I made is trying to downgrade ffmpeg to v6 since it was the version davedoesdev wrote the patches for.
  3. Start on davedoesdev/ffmpeg.js on ffmpeg v5 build, which doesn't need threading so it doesn't need the service worker, and change the Makefile to include the MKVE build. The only issue is, it being an old ffmpeg version, it might have bugs. And I recall having found a bug in FFmpeg related to .ass file extraction not so longer ago (but it's really rare to happen).

qgustavor avatar Aug 17 '24 21:08 qgustavor

I tried 3: I could not compile ffmpeg.js even without changing anything from the original repository because of changes in Emscripten. I tried moving mine Makefile into it (and changing ffmpeg-mkve into ffmpeg-dash to avoid having to deal with git submodules) as I have fixed those new Emscripten changes in it, but, then I found that "dvd" and "vob" aren't valid muxers in ffmpeg. Removing those progressed building further, but in the end it still failed in much as the same way as before: it only generates ffprobe.o and it fails as it can't find ffmpeg.o. Maybe that's caused by other breaking change on Emscripten. IDK.

qgustavor avatar Aug 19 '24 14:08 qgustavor

I tried 1: @davedoesdev unchanged code isn't compiling using latest emscripten. I tried downgrading emscripten to 3.1.49, 3.1.48, 3.1.47 and 3.1.46, which were released close to the time of his last commit, but compiling with them failed. I ran make clean every time, so previous runs would not cause issues. Which is weird, I remember properly compiling that code when working on #40 and only giving up because of the issue on GitHub Pages. I'm using WSL and cloning the original repository without doing any changes, using the build without Docker instructions (which allow me to downgrade Emscripten and not install Docker).

Running make is failing with "building:ERROR: Closure compiler run failed ending with:

building:ERROR: Closure compiler run failed:

building:ERROR: /tmp/emscripten_temp__h9brqid/ffmpeg-webm.jso4.js:42:4095: ERROR - [JSC_UNDEFINED_VARIABLE] variable __ffmpegjs_return is undeclared"

qgustavor avatar Aug 21 '24 15:08 qgustavor