- #!/bin/bash
- # This shell script will process & encode a single video file, and output 3
- # seperate files in the following formats: WebM, Ogg Theora, & h.264 for
- # streaming via an HTML5 player.
- #
- # You'll need ffmpeg, ffmpeg2theora, & HandbrakeCLI installed to run this
- # script. ffmpeg and ffmpeg2theora can be installed via Homebrew on a Mac.
- # If you're using Ubuntu, use the PPA at
- # https://launchpad.net/~jon-severinsson/+archive/ffmpeg
- # for newer versions of ffmpeg and libvpx (WebM codec).
- #
- # For the HandbrakeCLI, please visit the Handbrake website at
- # http://www.handbrake.fr
- #
- # Command line arguments taken from:
- # http://diveintohtml5.info/video.html#example
- #
- # Modifications made for resolution and quality where needed.
- INPUT_FILE=$1
- FILENAME=${INPUT_FILE%%.*}
- VIDEO_WIDTH="960"
- VIDEO_HEIGHT="540"
- VIDEO_DIM=$VIDEO_WIDTH"x"$VIDEO_HEIGHT
- if [ -z "$INPUT_FILE" ]; then
- echo "Usage: encode4codecasts.sh FILENAME"
- echo "You need to pass a video to process. Exiting"
- exit
- fi
- echo "Converting to Ogg/Theora"
- echo "RUNNING: ffmpeg2theora --videoquality 7 --width $VIDEO_WIDTH --output $FILENAME.ogv $INPUT_FILE"
- ffmpeg2theora --videoquality 7 --width $VIDEO_WIDTH --output $FILENAME.ogv $INPUT_FILE
- echo "Converting to h.264"
- echo "RUNNING: HandBrakeCLI --preset "iPhone 4" --width $VIDEO_WIDTH --two-pass --turbo --optimize --input $INPUT_FILE --output $FILENAME.mp4"
- HandBrakeCLI --preset "iPhone 4" --width $VIDEO_WIDTH --two-pass --turbo --optimize --input $INPUT_FILE --output $FILENAME.mp4
- echo "Converting to WebM"
- echo "RUNNING: ffmpeg -pass 1 -passlogfile $INPUT_FILE -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i $INPUT_FILE -vcodec libvpx -b 204800 -s $VIDEO_DIM -an -f webm -y NUL"
- ffmpeg -pass 1 -passlogfile $INPUT_FILE -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i $INPUT_FILE -vcodec libvpx -b:v 204800 -s $VIDEO_DIM -an -f webm -y $FILENAME.webm
- echo "WebM - First pass complete"
- echo "WebM - Starting second pass"
- echo "RUNNING: ffmpeg -pass 2 -passlogfile $INPUT_FILE -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i $INPUT_FILE -vcodec libvpx -b 204800 -s $VIDEO_DIM -acodec libvorbis -ac 2 -y $FILENAME.webm"
- ffmpeg -pass 2 -passlogfile $INPUT_FILE -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i $INPUT_FILE -vcodec libvpx -b:v 204800 -s $VIDEO_DIM -acodec libvorbis -ac 2 -y $FILENAME.webm
- echo "DONE"