#!/bin/bash
# 2013-01-19 07:33:38+00:00 category5.tv
# set the source extension (eg. avi, flv, mp4, etc)
SOURCETYPE=avi
echo
echo Video file converter script based on Category5.TV\'s method.
echo Slapped together by Robbie Ferguson for the guys over at www.ubuntupodcast.net
echo Version 1.2
echo
echo Please note: this is an extremely CPU-intensive script.
echo Not recommended for anything less than a dual-core system.
echo
echo To install: sudo apt-get install ffmpeg ffmpeg2theora imagemagick
echo To run: $0 filename
echo Don\'t specify extension\; must match SOURCETYPE \(currently $SOURCETYPE\)
echo You can change this by editing $0
echo
if [ -z "$1" ]; then
exit 1;
else
# make mp3
# because we love to appease the masses
echo Creating MP3 file from $1.$SOURCETYPE
echo
ffmpeg -acodec mp3 -vn -ab 112k -i $1.$SOURCETYPE $1.mp3 &
# make ogv
# because we love to support open source!
# Specify the source bitrate here
# (if playback seems fast or slow, set value to match source video)
FPS=29.97
# specify video quality 1-10
VIDQUALITY=5
# specify video bitrate 1-16778
VIDBITRATE=500
# specify audio quality -2-10
AUDQUALITY=8
# specify audio bitrate
AUDBITRATE=112
# choose deinterlacer (lb, li, ci, md, fd) - see 'ffmpeg2 --pp help' for details
DEINTERLACER=lb
echo Creating OGV file from $1.$SOURCETYPE
echo
ffmpeg2theora -F $FPS -v $VIDQUALITY --optimize -V $VIDBITRATE --pp $DEINTERLACER --deinterlace -a $AUDQUALITY -A $AUDBITRATE -o $1.ogv $1.$SOURCETYPE &
# make screenshots
# First, extract 1fps to PNG files. Then save those into an accelerated video file. Then, extract images at 1fps from the accelerated file.
# There might be a better way to do this, but it is pretty zippy, and gets the job done.
# This results in approximately 150 pictures of a one-hour video.
# I output in 640, 320 and 200 widths. The 200 is what we use for web site thumbs, 320 is for RSS, and 640 is for archive.
echo Creating screen grabs from $1.$SOURCETYPE
echo
mkdir $1_640
ffmpeg -i $1.$SOURCETYPE -s 640x480 -r 1 -f image2 $1_640/%05d.png
ffmpeg -i $1_640/%05d.png -b 512 -qscale .1 $1_640/$1_accel.avi
rm $1_640/*.png
ffmpeg -i $1_640/$1_accel.avi -an -r 1 -y $1_640/$1_%d.jpg
rm $1_640/$1_accel.avi
mkdir $1_320
mkdir $1_200
cp $1_640/* $1_320/
cp $1_640/* $1_200/
mogrify -resize 320 $1_320/*.jpg
mogrify -resize 200 $1_200/*.jpg
# create a distributable zip archive of the thumbnail images
# because we like to share...
zip thumbs_$1.zip $1_640/* $1_320/* $1_200/*
fi
syntax highlighted by Code2HTML, v. 0.9.1