subtitle_tonemap icon indicating copy to clipboard operation
subtitle_tonemap copied to clipboard

Issue about using BDSup2Sub

Open MonoS opened this issue 2 years ago • 9 comments

Hi quietvoid, i want to inform you that in the past i had quite some problem using BDSup2Sub resulting in cropped output, wrong colors/shade and missing subpic, that is one of the reason why i developed SupMover. I was also thinking about if it could be a good idea to change the luminance/color value at a palette level instead at the image level so that the functionality of your tool would be a less lossy transformation, from what i can read from your code (i'm not experienced in rust) it seems you lower the color of all the RGB channel by the specified percentage, or with a fixed color, and save it, am i right? Just for information PGS/Sup subtitle use a YCbCrA palette (from SubtitleEdit's code it seems that the matrix is determined from the video) in tv level (16-235/240) so do you think we could achieve the same effect multiplying the value from the Y channel in every paletted color with a percentage and then clamping to 16-235 range? Do you think we should take into account the Alpha value?

MonoS avatar Jan 22 '23 20:01 MonoS

I'm aware that BDSup2Sub has limitations, it's just the only option I found at the time that could be easily exported/imported as images. I've yet to find a complete library which allows this with a simple API.

quietvoid avatar Jan 22 '23 20:01 quietvoid

If my idea about modifying the palette make sense i can make a dll for you, but from what i can see from your code you are more that capable of doing that by yourself, but if you need help with the sup file structure i've just uploaded a kaitai descriptor in my repo.

MonoS avatar Jan 22 '23 21:01 MonoS

I had looked at other existing projects that dealt with subs and never really understood how this color change would be done. https://github.com/cubicibo/SUPer https://github.com/wswartzendruber/pgs-tools

I just need to look more into this.

quietvoid avatar Jan 22 '23 21:01 quietvoid

Hi, last day i've implemented this functionality inside my application, you can see the commit here https://github.com/MonoS/SupMover/commit/079f7383b2742ebacf2e9af4b28d6b525bd5d64b I didn't implement --fixed and --color functionality as i don't understand how they should work with the YCbCrA palette.

MonoS avatar Jul 23 '23 19:07 MonoS

I didn't implement --fixed and --color functionality as i don't understand how they should work with the YCbCrA palette.

Assuming the matrix is fixed, you could always round trip to RGB, set color and convert back to YCbCr.

quietvoid avatar Jul 23 '23 19:07 quietvoid

hey quietvoid, I'm having lots of issues with BDSup2Sup (primarily because I'm on Mac), have you seen this rust solution for exporting images: https://github.com/robjtede/sup-decode

Julianwan avatar Sep 06 '23 19:09 Julianwan

hey quietvoid, I'm having lots of issues with BDSup2Sup (primarily because I'm on Mac), have you seen this rust solution for exporting images: https://github.com/robjtede/sup-decode

I'm not sure if the actual issue is the images exporting or also the re-importing into a SUP file. If someone has problematic files, I can look into it.

quietvoid avatar Sep 06 '23 22:09 quietvoid

hey quietvoid... the issue was me. I kept receiving the error "BDSup2Sub should be in the same directory as this executable." on the release build. Turns out I was putting the .jar in the wrong spot, and also using the wrong jar (I was using a Mac BDSup2Sup; but actually using the windows BDSup2Sup.jar is what worked.

FWIW, here's how I solved my issue:

I built a release of subtitle_tonemap and installed it to my path using cargo.

I edited main.rs to print out where the code expected BDSup2Sup512.jar was searching.

// Make sure jar file exists in the same directory
    let mut java_jar = env::current_exe()?;
    java_jar.pop();
    java_jar.push("BDSup2Sub512.jar");
    println!("Searching for java jar at {:?}", java_jar);
    if !java_jar.exists() {
        let current_dir: PathBuf = env::current_dir()?;
        println!("Java jar file does not exist in {:?}", current_dir);
        return Ok(());
    }

Realized I needed to add the BDSup2Sup512.jar to /Users/{username}/.cargo/bin/BDSup2Sub512.jar

Got a few imagex errors using the Mac .jar, swapped it with a windows .jar and poof, everything worked.

So for Mac users, this may be helpful. And in general printing the path something is searching is helpful for newb users when using external dependencies.

Apologies for being vague above with my Mac bdsup2sup issues and it appears everything works fine now.

Thank you for making this!

Julianwan avatar Sep 07 '23 17:09 Julianwan

Easy fix...use the new beta version of BDSup2Sub and export the subtitle as it will have no warnings or issues.

Open the new exported SUP in the old version and you will see there are no more warnings.

Now you can tone map the subtitle without issues.

angelgraves13 avatar Oct 14 '24 05:10 angelgraves13