Subtitle Shifting Script

Discussion of advanced MakeMKV functionality, expert mode, conversion profiles
Post Reply
Hittsy
Posts: 10
Joined: Mon Jun 09, 2025 4:08 am

Subtitle Shifting Script

Post by Hittsy »

Have you ever seen subtitles within the viewing window, i.e. above the letterboxing?

Have you ever wanted to see something behind your subtitles, but the morons who mastered the film decided they needed to be placed in front of your content?

Are you irritated at *.SRT subtitles from the fine folks at opensubtitles.org not matching your rips perfectly?*

THE FUTURE IS NOW!

Code: Select all

#!/bin/bash
echo "boop"

read -p "Enter filename:" filename
echo $filename

pizza=$(flatpak run org.bunkus.mkvtoolnix-gui mkvmerge -i "./$filename")
echo $pizza

searchstring="subtitles"
rest=${pizza#*$searchstring}
value_i_got=$(( ${#pizza} - ${#rest} - ${#searchstring} ))
#echo "Yeeehaw"
echo "Index of the word 'subtitles': $value_i_got"
value_over_ten_check=${pizza:($value_i_got-4):1}
if [[ $value_over_ten_check =~ ^[0-9]+$ ]]; then
  echo "Is at or above 10!"
  value_i_want=${pizza:($value_i_got-4):1}${pizza:($value_i_got-3):1}
else
  echo "Is less than 10."
  value_i_want=${pizza:($value_i_got-3):1}
fi
echo "The number before 'subtitles': $value_i_want"

flatpak run org.bunkus.mkvtoolnix-gui mkvextract "./$filename" tracks $value_i_want:ready.sup

java -jar BDSup2Sub.jar -O 2.35,0 -o fixed.sup ready.sup

flatpak run org.bunkus.mkvtoolnix-gui mkvmerge -o "./fixed-$filename" --track-order 1:0 -s !$value_i_want $filename --language 0:eng fixed.sup

rm ready.sup
rm fixed.sup
Through many sleepless nights, I have created the above script. This will automatically yank the first PGS subtitle track out of your *.MKV file, move it to the bottom of the screen, and repackage it. All you have to do is save it as a script, and run it with the command
./name_of_file.sh
in the directory you keep your *.MKV file.

Considerations:
  • This is a bash script which can only be run on a linux system.
  • You must have mkvtoolnix installed, via flatpak. No native installs.
  • You need to have BDSUP2SUB.jar in the same directory that the script and *.MKV file is located.
  • For the above to work, you also should install Java.
  • This can only handle one file at a time. You may need to pace yourself as you handle the subtitles in your massive media collection.
  • You must understand that the subtitle track will be tagged as an English track upon remuxing back into your video file.
  • As I am physically incapable of doing anything to improve this script. Please accept in your heart of hearts, that it will not get any better.
  • The script will output "boop" upon execution. This is extremely important.
F.A.Q.
Q: Why is the variable named pizza?
A: Good question.

Q: What if the name of my *.MKV file is too long to easily type, or has weird characters that break the script somehow?
A: Rename your file before and after processing with SSS to handle it.

Q: Why Linux & why the flatpak version of MKVToolnix?
A: That's what I had installed on my system at the time.

Q: Why do you use flatpak?
A: Because I'm primarily irritated at Cannonical/Ubuntu for introducing yet another package manager and repo, when I want a universal package.

Q: Can you please let it do this to all the subtitles in a video file?
A: No.

Q: Can you please make it handle or queue multiple videos at a time?
A: God no.

Q: Did you know that MKVmerge -J gives you the output in...
A: Yes. But I didn't want to make more spaghetti parsing it, or import some library.

Q: Why did you make this?
A: I seemed to be the only person in the world that hated seeing subtitles on top of my videos, after filmmakers clumsily generate an amazing amount of unused space on my display within which they could be relocated to. I then realized I might not be alone, and figured the world should be enlightened by my coding prowess at making a shell script.

Q: Why did you really make this?
A: I wanted some attention to this thing that bothers me. I really think it should be handled by players like Plex or Jellyfin, or MakeMKV directly. Since nobody can figure that out however, we're doing things the hard(coded) way.

*I do actually really appreciate the work that the fine folks do at opensubtitles.org, especially in the name of accessibility.
Post Reply