Skip to content

Instantly share code, notes, and snippets.

@kehh
Forked from rodneyrehm/html5-video.sh
Last active August 29, 2015 14:07
Show Gist options
  • Save kehh/ac429acc7a9183f1560f to your computer and use it in GitHub Desktop.
Save kehh/ac429acc7a9183f1560f to your computer and use it in GitHub Desktop.
#!/bin/sh
# configure stuff
width=640
height=320
size=$width"x"$height
# show help
if [[ "$1" == "" || "$1" == "-h" || "$1" == "--help" ]]; then
echo "USAGE: ";
echo "$(basename $0) [wmo] video.avi";
echo " w: WebM";
echo " m: MP4";
echo " o: OGG";
exit 1;
fi
# parameters are optional, make all targets if none specified
if [ "$2" = "" ]; then
f=$1;
p="wmo";
else
f=$2;
p=$1;
fi
# file name mangling
dir=$(dirname $f)
file=$(basename $f)
name=${file%.*}
extension=${file##*.}
# abort if file doesn't exist
if [ ! -e $f ]; then echo "File $f not found"; exit 1; fi
if [[ "$p" == *w* ]]; then
# webm
ffmpeg -i $f -f webm -vcodec libvpx -acodec libvorbis -ab 128000 -crf 22 -s $size "$dir/$name.webm"
fi
if [[ "$p" == *m* ]]; then
# mp4
ffmpeg -i $f -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -vpre slow -f mp4 -crf 22 -s $size "$dir/$name.mp4"
fi
if [[ "$p" == *o* ]]; then
# ogg (if you want to support older Firefox)
ffmpeg2theora $f -o "$dir/$name.ogv" -x $width -y $height --videoquality 5 --audioquality 0 --frontend
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment