#!/bin/sh # Origins: # http://diveintohtml5.org/video.html # http://camendesign.com/code/video_for_everybody # Possible flashplayers: # http://www.internetmarketingnotes.com/2010/07/free-embeddable-flash-video-flv-players-for-commercial-use/ set -e PRG=$(basename "$0") showhelp() { cat <&2 "$response" exit 1 } # parse cmdline options TEMP="`getopt -s sh -o hs:p:t: -l help,size:,profile:,title: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error." eval set -- "$TEMP" while true ; do case "$1" in -h|--help) showhelp; exit;; -s|--size) size="$2"; shift 2;; -p|--profile) profile="$2"; shift 2;; -t|--title) title="$2"; shift 2;; --) shift; break;; *) exit1 "Internal error resolving options.";; esac done if [ $# -eq 0 ]; then showhelp exit1 "Too few parameters!" fi if [ $# -gt 1 ]; then showhelp exit1 "Too many parameters!" fi # input filename (mandatory) infile="$1"; shift [ -e "$infile" ] || exit1 "Input file missing!" filebase=$(echo "$infile" | perl -pe 's/\.[^.]*//') # output size in WIDTHxHEIGHT (mandatory) # TODO: Make optional with input size as default # TODO: Make each half of size optional with default resolved from input aspect ratio [ -n "$size" ] || exit1 "Unknown output size!" width=$(echo "$size" | perl -pe 's/x[^x]*//') height=$(echo "$size" | perl -pe 's/[^x]*x//') heightplus=${height:+$(($height+4))} # fallback profile profile=${profile:-lo} case "$profile" in lo) bitrateKB=200 bitrateB=204800 aspect=4:3 ;; lowide) bitrateKB=200 bitrateB=204800 aspect=16:9 ;; hi) bitrateKB=600 bitrateB=614400 aspect=4:3 ;; hiwide) bitrateKB=600 bitrateB=614400 aspect=16:9 ;; esac # fallback graphics title title=${title:-$filebase} # TODO: Check and fail if all needed tools are not available ## Theora/Vorbis/Ogg ffmpeg2theora --videobitrate "$bitrateKB" --max_size "$size" --aspect "$aspect" --output "$filebase.ogv" "$infile" ## H.264/AAC/MP4 HandBrakeCLI --preset "iPhone & iPod Touch" --vb "$bitrateKB" ${width:+--maxWidth "$width"} ${height:+--maxHeight "$height"} --two-pass --turbo --optimize --input "$infile" --output "$filebase.mp4" ## VP8/Vorbis/WebM ! ffmpeg -codecs | grep -iw vp8 || webm=yes # FIXME: check and fail if logfiles exist already [ -z "$webm" ] || ffmpeg -pass 1 -passlogfile "$infile" -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i "$infile" -vcodec libvpx -b "$bitrateB" -s "$size" -aspect "$aspect" -an -f webm -y NUL [ -z "$webm" ] || ffmpeg -pass 2 -passlogfile "$infile" -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i "$infile" -vcodec libvpx -b "$bitrateB" -s "$size" -aspect "$aspect" -acodec libvorbis -ac 2 -y "$filebase.webm" rm "$infile"-*.log ## JPEG preview ffmpegthumbnailer -s0 -i "$filebase.ogv" -o "$filebase.jpg" # TODO: resolve flash player to use [ -z "$flashplayer" ] || flash=yes cat >"$filebase.html" <

Download Video: open format Ogg, ${webm:+open format WebM,} closed Format MP4.

EOF