-
-
Save ajdungan/a3c71e4c87fbea51ded8d3aba56b135a to your computer and use it in GitHub Desktop.
A simple script to beautify and improve readability of .ass subtitles and converting subtitles .srt <=> .ass {\\bord3} - ASS subtitles outline width {\\blur14} - blur ratio (to create smooth transition between movie and subtitles)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
COMMAND=$1 | |
case "$COMMAND" in | |
ass-outline) | |
# Add outline to all ASS subtitles in current directory | |
for file in *.ass; do | |
echo "$COMMAND: Processing $file" | |
perl -pe 's/(^Dialogue: ([^{]*?,){9})(?=[^{])/\1\{\\bord3}\{\\blur14}/g' <"$file" >temp | |
mv temp "$file" | |
done | |
echo "$COMMAND: Finalizing" | |
sed -E 's/^(Style: sp_.+),[0-9]+,([0-9]+\r?)$/\1,0,\2/g' -i ./*.ass | |
sed -E 's/^(Style: Default.+),[0-9]+,([0-9]+\r?)$/\1,0,\2/g' -i ./*.ass | |
;; | |
ass-to-srt) | |
# Convert all ASS subtitles in current directory to SRT (use to fix broken subtitles or prepare subtitles for tablet) | |
for file in *.ass; do | |
echo "$COMMAND: Processing $file" | |
ffmpeg -i "$file" "$(basename "$file" ass)srt" | |
done | |
;; | |
srt-to-ass) | |
# Convert all SRT subtitles in current directory to ASS (use before $0 ass-outline) | |
for file in *.srt; do | |
echo "$COMMAND: Processing $file" | |
ffmpeg -i "$file" "$(basename "$file" srt)ass" | |
done | |
;; | |
*) | |
echo "Usage: $(basename "$0") {command}" | |
echo " Commands:" | |
echo " ass-outline: Add outline to all ASS subtitles in current directory" | |
echo " ass-to-srt: Convert all ASS subtitles in current directory to SRT (use to fix broken subtitles or prepare subtitles for MiPad4)" | |
echo " srt-to-ass: Convert all SRT subtitles in current directory to ASS (use before $(basename "$0") ass-outline)" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment