#!/bin/sh # Origins: # http://diveintohtml5.org/video.html # http://camendesign.com/code/video_for_everybody # http://www.streaminglearningcenter.com/articles/so-you-want-to-get-to-know-h264.html # Possible flashplayers: # http://www.internetmarketingnotes.com/2010/07/free-embeddable-flash-video-flv-players-for-commercial-use/ # TODO: offer to skip rendering again if an output file exist already # TODO: support --width and --height (resolving the other part from input/forced aspect ratio) # TODO: support --formats (comma-separated, to allow e.g. excluding webm even if supported) # TODO: add --speech option, using mono, lower audio rate, and (when solved how) speex set -e PRG=$(basename "$0") showhelp() { cat < EOF } exit1() { response="${1:+Error: }${1:-Internal error!}" echo >&2 "$response" exit 1 } # defaults bitrate=768k h264profile=baseline # parse cmdline options TEMP="`getopt -s sh -o hs:a:b:p:t: -l help,size:,aspect:,bitrate:,profile:,h264profile,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;; -a|--aspect) aspect="$2"; shift 2;; -b|--bitrate) bitrate="$2"; shift 2;; -p|--profile) profile="$2"; shift 2;; --h264profile) h264profile="$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 # input filename (mandatory) infile="$1" [ -e "$infile" ] || exit1 "Input file missing!" filebase=$(echo "$infile" | perl -pe 's/\.[^.]*//') # fallback graphics title title=${title:-$filebase} # TODO: Check and fail if all needed tools are not available # TODO: When verified beneficial, add option real_time=-2 opts="${profile:+-profile $profile}" args=" ${bitrate:+b=${bitrate}} ${size:+s=$size} ${aspect:+aspect=$aspect}" args_audio="ac=2 ar=44100 ab=96k" # bail out (before any expensive tasks) if logfiles exists [ ! -f x264-*.log* ] || exit1 "logfiles already exist. Remove them (or wait for that other process using them to complete) and try again." ## Theora/Vorbis/Ogg melt $opts -consumer avformat:"$filebase.ogg" f=ogg vcodec=libtheora $args acodec=libvorbis aq=25 $args_audio "$@" ## H.264/AAC/MP4 melt $opts -consumer avformat:/dev/null f=mp4 properties=x264-medium-$h264profile $args pass=1 an=1 fastfirstpass=1 "$@" melt $opts -consumer avformat:"$filebase.mp4" properties=x264-medium-$h264profile $args pass=2 acodec=libvo_aacenc $args_audio "$@" mv "$filebase.mp4" "$filebase.mp4"~ qt-faststart "$filebase.mp4"~ "$filebase.mp4" [ -f "$filebase.mp4" ] && rm "$filebase.mp4"~ || exit1 "failed to optimize with qt-faststart." ## VP8/Vorbis/WebM # TODO: use two-pass when supported by melt melt $opts -consumer avformat:"$filebase.webm" properties=webm $args $args_audio "$@" ## JPEG preview ffmpegthumbnailer -s0 -i "$filebase.mp4" -o "$filebase.jpg" # resolve width and height from preview image size=$(jpeginfo "$filebase.jpg" | perl -ane 'print "$F[1]x$F[3]"') width=$(echo "$size" | perl -Fx -ane 'print $F[0]') height=$(echo "$size" | perl -Fx -ane 'print $F[1]') heightplus=${height:+$(($height+4))} # TODO: resolve flash player to use [ -z "$flashplayer" ] || flash=yes cat >"$filebase.html" < ${webm:+ }${flash:+ } ${flash:+ } Download Video: open format Ogg, ${webm:+open format WebM,} closed Format MP4. EOF
Download Video: open format Ogg, ${webm:+open format WebM,} closed Format MP4.