-
Notifications
You must be signed in to change notification settings - Fork 605
Add support for Vobsub subtitles #1979
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
Conversation
Thanks for the contribution! In order to merge this we need a (very) small test video containing at least one vobsub subtitle that we can use to write a playback test to verify everything works (and continues to work as we change things in future). This asset needs to be suitably licensed for submission to this repo. The I had a quick look around and didn't find an easy way to synthesise vobsub subtitles. Please can you take a look into this. Once you have the small asset with a vobsub track added to this PR, you can probably just add the file to the list of assets in |
Hello and thanks for your reply! While searching for a better sample file or how to build one I just saw that ffmpeg can convert other image-based subtitle formats to Vobsub/DVDsub. And since Exoplayer does support PGS and DVBsub subtitles, which are image-based, I thought I'd just use one of your sample files for those and convert them to Vobsub. But I can't find a sample file with PGS or DVBsub subtitles in the repository or in the old ExoPlayer repository. Is that correct, or am I missing something? If I could get one of the files you used for those subtitle formats, I can easily create one with Vobsub subtitles. P.S.: It appears that the Vobsub format ffmpeg outputs is a bit weird in that it doesn't contain the "size:..." line in the embedded IDX file. Never seen that before. My code needs that to be able to calculate the relative positions required by Cue.Builder(). At least I didn't see a way how a subtitle parser could get access to the viewport size. But the output of ffmpeg can easily be fixed by adding the "size:..." line by hand (mkvextract, an editor, and mkvmerge). |
That's correct, we don't have test assets for these subtitle formats either, and this introduces a maintenance burden when we want to make changes (because we have less confidence that this logic will still work) - which is why I'm afraid we now require test assets for new subtitle formats. Some quick searching suggests that tsMuxer might be able to convert from SRT to an image-based format, which maybe ffmpeg could then convert to vobsub? I haven't tried this (or ever used this tool). Or if there's a way to just mux arbitrary images in as subtitles, you could use some of our existing test images (there are other formats too). |
Hello again (and a happy new year), thanks for pointing me at tsmuxer. This worked. I took the existing |
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
public void parseIdx(String idx) { | ||
for (String line : idx.trim().split("\\r?\\n")) { | ||
if (line.startsWith("palette: ")) { | ||
String[] values = line.substring(9).split(","); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Util.split
to avoid the weird behaviour of the single-arg variant of String.split
related: https://github.com/google/guava/wiki/StringsExplained#splitter
Same elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a few changes as part of preparing this for internal review, but also found a couple of questions I want your input on (see individual comments). I'm happy to make any resulting code changes, so feel free to just reply in the comments.
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
/** | ||
* Parse run-length encoded data into the {@code bitmapData} array. The | ||
* subtitle bitmap is encoded in two blocks of interlaced lines, {@code y} | ||
* gives the index of the starting line (0 or 1). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if y
is always zero or one, what about making it a boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should have written the comment better: the function is called with y being 0 or 1, basically telling it whether it will decode the even or odd lines. Inside the function it will then increase y in the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha - I've made the parameter a boolean and made the y
arithmetic an implementation detail inside the method.
libraries/extractor/src/main/java/androidx/media3/extractor/text/vobsub/VobsubParser.java
Outdated
Show resolved
Hide resolved
Thanks for adding this test file - that's great you got
Did you get the test running successfully with this file? |
I had uploaded the sample file to https://www.w9y.de/sample.mkv, added that to the Hm, weird. How does one run those tests? |
Correction: If I pull the latest version with your changes, the demo player doesn't display the subtitle... Debugging... It's this line: It should be: Because we have to subtract the two bytes we just read ;-) Fixed in the repository now. |
And before I forget this again: from that conversion with tsmuxer I still have to sample file with PGS subtitles. Since this PR is about Vobsub/DVDsub I'm reluctant to add it here. You can get it here, if you're interested to finally have sample file with PGS: https://www.w9y.de/sample-with-pgs.mkv. Exoplayer can play this file. And while I was at it, I also used ffmpeg to convert the subtitles to DVBsub: https://www.w9y.de/sample-with-dvbsub.mkv. The interesting bit about this one is that Exoplayer (demo app) can't play the file, but |
Amazing, thanks! I've added this to
Oops, thanks for spotting and fixing that. I wasn't clear in my original comment but the test timed out both with and without my additional changes (and still times out with the latest fix too). It times out waiting for the player state to get to I tried playing the file in the demo app (thanks for the suggestion), it also doesn't ever stop - the UI says the file is
And
Is it possible there was some time unit conversion problem when you were extracting and re-muxing? [1]
|
Oops. Indeed, ffmpeg messed up the track duration when converting PGS to Vobsub. I've just pushed the fixed version into the repository. This also made me look at the DVBsub example again (see the URL above, the one Exoplayer couldn't play). That was messed up even more and the URL now points to the fixed version. Exoplayer still can't play it, though. |
That's great, thanks for fixing the file - I've used this in the test and it now completes successfully. |
…th the INFLATE_HEADER
Transformed from `sample_with_srt.mkv` and provided in #1979 (comment) PiperOrigin-RevId: 714955725
Hello,
this add support for Vobsub subtitles.
An example file can be found here: https://www.w9y.de/sample.mkv
This is based on this file: https://samples.ffmpeg.org/sub/largeres_vobsub.mkv
The only difference is that I used "mkvmerge -o sample.mkv largeres_vobsub.mkv" to copy the tracks into a new MKV file because the original uses ContentCompAlgo == 0, which is not supported by Exoplayer.