Skip to content

Instantly share code, notes, and snippets.

@archydragon
Last active April 25, 2016 11:01
Show Gist options
  • Save archydragon/0ec709799faad92d974e to your computer and use it in GitHub Desktop.
Save archydragon/0ec709799faad92d974e to your computer and use it in GitHub Desktop.
WebM cutter
#!/bin/bash
usage() {
echo "WebM cutter and uploader."
echo "Usage: $0 <source> <start time> <length> [-subs]"
echo "Example: $0 video.mkv 00:10:15 00:00:30"
exit 1
}
if [ $# -eq 0 ]; then usage; fi
FONTDIR=$HOME/.fonts
TMPFILE=/tmp/`date +%s`.webm
PASSLOG=/tmp/pass1
PASSTMP=/tmp/pass1.webm
FFMPEGOPTS="-q:a 0 -ss $2 -t $3 -vpre libvpx-720p -ac 2 -codec:a libvorbis -ab 128k \
-strict -2 -map 0:0 -map 0:1 -passlogfile $PASSLOG"
if [[ $4 = "-subs" ]];
then
mkdir -p $FONTDIR
ffmpeg -dump_attachment:t "" -i "$1"
mv -vf *.ttf *.TTF *.otf *.OTF $FONTDIR
ffmpeg -i "$1" /tmp/subs.ass
ffmpeg -i "$1" $FFMPEGOPTS -vf "ass=/tmp/subs.ass" -pass 1 $PASSTMP
ffmpeg -i "$1" $FFMPEGOPTS -vf "ass=/tmp/subs.ass" -pass 2 $TMPFILE
rm -f /tmp/subs.ass
else
ffmpeg -i "$1" $FFMPEGOPTS -pass 1 $PASSTMP
ffmpeg -i "$1" $FFMPEGOPTS -pass 2 $TMPFILE
fi
rm -vf $PASSLOG
rm -vf $PASSTMP
echo "Encoded file saved to $TMPFILE"
# abyss $TMPFILE # may uncomment this line and replace with your uploader command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment