Skip to content

Instantly share code, notes, and snippets.

@rodneyrehm
Forked from yellowled/ffmpeg-html5
Created December 6, 2011 20:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rodneyrehm/1439768 to your computer and use it in GitHub Desktop.
Save rodneyrehm/1439768 to your computer and use it in GitHub Desktop.
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg.
#!/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
@yellowled
Copy link

Just for the record: on my Ubuntu 11.10, it needs #!/usr/bin/env bash instead of #!/bin/sh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment