Skip to content

Instantly share code, notes, and snippets.

@KurumiSerori
Created July 3, 2018 08:14
Show Gist options
  • Save KurumiSerori/6f8aa41a0a9893e1dba90ea906f4af4d to your computer and use it in GitHub Desktop.
Save KurumiSerori/6f8aa41a0a9893e1dba90ea906f4af4d to your computer and use it in GitHub Desktop.
Burn subtitle into a video utilizing ffmpeg
#!/bin/sh
#echo $#
if [ $# -ne 2 -a $# -ne 3 ]; then
echo "Usage: $0 video_file subtitle_file [output, out.mp4 by default]"
echo "e.g., $0 video.mp4 sub.ass"
exit 1
fi
OUTFILE=$3
if [ $# -eq 2 ]; then
OUTFILE=out.mp4
fi
#echo $OUTFILE
echo "ffmpeg -i '$1' -vf subtitles='$2' '$OUTFILE'?"
read
OBASE=`basename "$OUTFILE"`
ODIR=`dirname "$OUTFILE"`
FBASE=`basename "$1"`
FDIR=`dirname "$1"`
SAMESOURCEFLAG=0
if [ "$OUTFILE" == "$1" ]; then
#if [ "$ODIR/$OBASE" == "$FDIR/$FBASE" ]; then
mkdir .burn
OUTFILE="$ODIR/.burn/$OBASE"
#echo $OUTFILE
#read
SAMESOURCEFLAG=1
fi
/usr/local/bin/ffmpeg -i "$1" -vf subtitles="$2" "$OUTFILE"
FFMPEGRETURN=$?
echo
echo "ffmpeg returns $FFMPEGRETURN."
if [ $FFMPEGRETURN -ne 0 ]; then
rm -rf .burn
fi
if [ $FFMPEGRETURN -eq 0 -a $SAMESOURCEFLAG -eq 1 ]; then
ORIGINALSIZE=`stat -f "%z" "$1"`
OUTPUTSIZE=`stat -f "%z" "$OUTFILE"`
echo "Original: $ORIGINALSIZE bytes."
echo "Output: $OUTPUTSIZE bytes."
# read -r -p "Overwrite input file ? [y/N] " keyboardInput
# case $keyboardInput in
# y|Y ) mv "$OUTFILE" ./ ;;
# * ) echo "Aborted." ;;
# esac
mv "$OUTFILE" ./
rm -rf .burn
fi
#notifyterminalDone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment