Skip to content

Instantly share code, notes, and snippets.

@jazlopez
Created May 27, 2020 00:32
Show Gist options
  • Save jazlopez/44d636962c15c7c4cddc7233387d7f9c to your computer and use it in GitHub Desktop.
Save jazlopez/44d636962c15c7c4cddc7233387d7f9c to your computer and use it in GitHub Desktop.
Bash function to convert subrip subtitle srt files to advanced sub station alpha subtitle file
# ----------------------------------------------------
# srt to ass script converter
#
# Usage: srt2ass $SRT_FILE
#
# It will convert srt file into a default subs.ass
#
# If you want to override font size (16)
#
# srt2ass $SRT_FILE [FONT_SIZE]
#
# [FONT_SIZE] should be positive numeric value
#
#. Author: Jaziel Lopez <[email protected]>
# ----------------------------------------------------
function srt2ass() {
local DESTINATION="subs.ass"
local SOURCE="$1"
local FONT_SIZE="$2"
if [ -f "$SOURCE" ]; then
if [ ! -s "$SOURCE" ]; then
echo "$SOURCE is an empty file ... bye now"
return 1
fi
if [ -z $FONT_SIZE ]; then
FONT_SIZE=16
fi
if [[ ! "$FONT_SIZE" =~ ^[0-9]+$ ]]; then
echo "$FONT_SIZE is not a valid number .. bye now"
return 1
fi
ffmpeg -i $SOURCE $DESTINATION
vim -c "%s/Arial,16/Arial,$FONT_SIZE/" -c "wq" "$DESTINATION"
EXIT_CODE_VIM=$?
if [[ $EXIT_CODE_VIM == 0 ]]; then
echo "srt to ass file type conversion completed."
echo "see generated file: $DESTINATION"
fi
return $EXIT_CODE_VIM
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment