#!/bin/sh # Encode a movie as divx/mp3 to fit on a CD [ -z "$1" ] && echo "example: `basename $0` all dvd:// -dvd-device " && exit 1 trap 'echo "encoding interrupted" ; exit 1' SIGINT COMMAND=$1 shift # includes input options OPTS=$@ # We're using 3 phase encoding. The first pass will do only audio, # which enables a good estimate of the necessary bitrate to fit on a # CD. The output of mencoder is saved to the file 'recommended'. AUDIO_OPTS="-oac mp3lame -lameopts vbr=3" audio () { rm -f frameno.avi mencoder \ -ovc frameno \ $AUDIO_OPTS \ -o frameno.avi \ -quiet \ $OPTS >recommended } # The 'recommended' file generated in the first pass is grepped for # the bitrate to use. The result is written to the file 'bitrate'. bitrate () { cat recommended \ | grep '^Recommended video bitrate for 700MB' \ | awk '{print $7}' >bitrate } # Perform multipass video encoding using the bitrate determined from # the first (audio) pass. This is no longer using the audio stream # from frameno.avi, since that seems to be deprecated (gives sync problems) _video () { mencoder \ $AUDIO_OPTS \ -ovc lavc \ -mc 0 \ -lavcopts vcodec=mpeg4:$1:aspect=16/9:vbitrate=`cat bitrate` \ -quiet \ -o movie.avi \ $OPTS } # The first pass writes the statistics file. See man page for vpass. video1 () { _video vpass=1:turbo } # The second pass reads it. video2 () { _video vpass=2 } # Perform all passes. all () { audio bitrate video1 video2 } $COMMAND