Created
May 10, 2013 12:28
-
-
Save dokterbob/5554116 to your computer and use it in GitHub Desktop.
Script for encoding web video with FFMPEG.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script transcodes a single MP4 video to WebM and Theora and | |
# creates a still for the video after 2 seconds | |
# Inspiration: http://johndyer.name/ffmpeg-settings-for-html5-codecs-h264mp4-theoraogg-vp8webm/ | |
INFILE=$1 | |
FORMAT=$2 | |
BASENAME="${INFILE%.*}" | |
VIDEO_BITRATE="1500k" | |
AUDIO_BITRATE="160000" | |
if ! [[ -r $INFILE ]]; then | |
echo "Input file '$INFILE' not readable. Exiting." | |
echo "Usage: $0 <filename> <mp4|webm|theora|still>" | |
exit -1 | |
fi | |
# MP4/AAC | |
if [[ $FORMAT == 'mp4' ]]; then | |
ffmpeg -i $INFILE \ | |
-vcodec libx264 -vpre slow -vpre baseline -b:v $VIDEO_BITRATE \ | |
-b:a $AUDIO_BITRATE \ | |
-g 30 $BASENAME.mp4 | |
exit 0 | |
fi | |
# WebM | |
if [[ $FORMAT == 'webm' ]]; then | |
echo 'Encoding WebM' | |
ffmpeg -i $INFILE \ | |
-vcodec libvpx -b:v $VIDEO_BITRATE \ | |
-acodec libvorbis -b:a $AUDIO_BITRATE \ | |
-f webm -g 30 $BASENAME.webm | |
exit 0 | |
fi | |
# Theora | |
if [[ $FORMAT == 'theora' ]]; then | |
echo 'Encoding Theora' | |
ffmpeg -i $INFILE \ | |
-vcodec libtheora -b:v $VIDEO_BITRATE \ | |
-acodec libvorbis -b:a $AUDIO_BITRATE \ | |
-g 30 $BASENAME.ogv | |
exit 0 | |
fi | |
# Grabbing a still | |
if [[ $FORMAT == 'still' ]]; then | |
echo 'Grabbing a still' | |
ffmpeg -i $INFILE \ | |
-ss 00:02 -vframes 1 -r 1 \ | |
-f image2 $BASENAME.jpg | |
exit 0 | |
fi | |
echo 'Unknown format specifed.' | |
echo "Usage: $0 <filename> <mp4|webm|theora|still>" | |
exit -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment