Skip to content

Instantly share code, notes, and snippets.

@dajoho
Created March 7, 2013 13:52
Show Gist options
  • Save dajoho/5108188 to your computer and use it in GitHub Desktop.
Save dajoho/5108188 to your computer and use it in GitHub Desktop.
Shellscript to create HTML5 <video> MP4/OGV/WEBM/FLV/JPG versions of any video. The size, bitrate, cropping and sharpening can all be defined at the top of the script. Requirements: ffmpeg with libx264/libvpx/libtheora codecs (can be installed via homebrew). And flvtool2 (sudo gem install flvtool2).
#!/bin/bash
FILTERS="-filter:v crop=504:374:6:4,unsharp=5:5:1.0:5:5:0.0";
RESIZE="512x384";
VIDEO_BITRATE="1024k";
AUDIO_BITRATE="64k";
############################################################
for f in "$@"
do
/usr/local/bin/ffmpeg -ss 00:00:02.01 -i "$f" -y -f image2 -vcodec mjpeg -vframes 1 $FILTERS -s $RESIZE "$f.jpg";
/usr/local/bin/ffmpeg -y -i "$f" -b:v $VIDEO_BITRATE -b:a $AUDIO_BITRATE -vcodec libx264 -g 30 $FILTERS -s $RESIZE "$f.mp4";
/usr/local/bin/ffmpeg -y -i "$f" -b:v $VIDEO_BITRATE -b:a $AUDIO_BITRATE -vcodec libvpx -acodec libvorbis -g 30 $FILTERS -s $RESIZE "$f.webm";
/usr/local/bin/ffmpeg -y -i "$f" -b:v $VIDEO_BITRATE -b:a $AUDIO_BITRATE -vcodec libtheora -acodec libvorbis -g 30 $FILTERS -s $RESIZE "$f.ogv";
/usr/local/bin/ffmpeg -y -i "$f" -b:v $VIDEO_BITRATE -b:a $AUDIO_BITRATE -f flv -g 30 $FILTERS -s $RESIZE "$f.flv";
/usr/bin/flvtool2 -UP "$f.flv";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment