rendered paste body#! /bin/bash# This bash script has been created by Diego Massanti# You are free and welcome to do whatever you want with it.# www.massanti.com# Modified by Raphael August 2008usage(){cat << EOFusage: $0 -f <file to encode> [-w <integer>] -b <integer> [-q][-k]* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** h264 video with he-aac audio encoding script by Diego Massanti. ** January 2008, Made in Argentina. ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *OPTIONS: -h Show this message -f Path to the file to encode < REQUIRED -w Resize video to fit inside this width while keeping the aspect ratio < OPTIONAL -b Desired video bitrate < REQUIRED -q Better quality encoding using 2 passes (slower) < OPTIONAL -k Do not delete (keep) temporary files < OPTIONALEOF}set -xaudiobitrate=48000framerate=12platform=""uname=`uname`if [ $uname == "Darwin" ]; then ## 99% of chances that this is a Mac platform="Mac"else platform="Linux"fiwidth=""bitrate=deltemp=FALSEquality=FALSEfilename=rsize=""while getopts ":f:w:b:qkv" OPTION; do case $OPTION in w ) width=$OPTARG;; f ) filename=$OPTARG;; b ) bitrate=$OPTARG;; k ) deltemp=FALSE;; q ) quality=TRUE;; h ) usage;; \? ) usage exit 1;; * ) echo $usage exit 1;; esacdoneif [ "$1" == "" ]; then usage exit 0fiif [ "$filename" == "" ]; then echo echo you MUST supply a file to encode!, use the -f parameter. i.e: -f mymovie.avi echo usage exit 1fiif [ "$bitrate" == "" ]; then echo echo you MUST specify a target bitrate!, use the -b parameter. i.e: -b 512 echo usage exit 1fiif [ "$width" != "" ]; then rsize="scale=$width:-3" rsizemsg="fit into $width pixels wide"else rsize="" rsizemsg="Movie is not being resized."fi#MOVIE_FPS=`midentify "$filename" | grep FPS | cut -d = -f 2`MOVIE_FPS=12#clearecho "* Encoding: $filename"echo "* Resizing to: $rsizemsg."echo "* Total Bitrate: $bitrate kbps."let "caudiobitrate = $audiobitrate / 1000"let "bitrate = $bitrate - $caudiobitrate"echo "* Video Bitrate: $bitrate kbps."echo "* Audio Bitrate: $caudiobitrate kbps."echo "* Platform: $platform."# Encoding phase starts here...# Encoding Video...echo "* * * Starting video encoding pass 1... * * *"mencoder "$filename" -o "${filename%.*}_temp.264" -passlogfile "${filename%.*}"_temp.log -vf yadif -vf $rsize -ovc x264 -x264encopts bitrate=$bitrate:subq=1:partitions=none:bframes=16:b_pyramid:threads=auto:pass=1 -of rawvideo -nosound -ofps $framerate#mencoder "$filename" -o "${filename%.*}_temp.264" -passlogfile "${filename%.*}"_temp.log -vf yadif -vf $rsize -ovc x264 -x264encopts bitrate=$bitrate:subq=4:bframes=2:b_pyramid:weight_b:nr=3000:threads=auto:pass=1 -of rawvideo -nosound -ofps $framerateif [ "$quality" == "TRUE" ]; thenecho "* * * Starting video encoding pass 2... * * *"mencoder "$filename" -o "${filename%.*}_temp.264" -passlogfile "${filename%.*}"_temp.log -vf yadif -vf $rsize -ovc x264 -x264encopts bitrate=$bitrate:subq=4:bframes=16:b_pyramid:weight_b:nr=3000:threads=auto:pass=2:8x8dct -of rawvideo -nosound -ofps $frameratefi# Extracting audio to a 48khz WAV file.echo "* * * Extracting Audio... * * *"#mplayer "$filename" -ao pcm:fast:file="${filename%.*}_temp.wav" -vc null -vo nullmplayer "$filename" -ao pcm:fast:file="${filename%.*}_temp.wav" -vc dummy -vo null# Encoding Audio to HE-AAC plus fileecho "* * * Encoding Audio... * * *"if [ "$platform" == "Mac" ]; thenenhAacPlusEnc "${filename%.*}_temp.wav" "${filename%.*}_temp.aac" $audiobitrate selseneroAacEnc -q 0.3 -he -if ${filename%.*}_temp.wav -of ${filename%.*}_temp.mp4fi# Muxingecho "* * * Generating final MP4 container... * * *"MP4Box -add "${filename%.*}_temp.264#video:fps=$MOVIE_FPS" "${filename%.*}.mp4"if [ "$platform" == "Mac" ]; thenMP4Box -add "${filename%.*}_temp.aac" "${filename%.*}.mp4"elseMP4Box -add "${filename%.*}_temp.mp4#audio" "${filename%.*}.mp4"fi# MetaData and interleavingname=${filename%.*}album="Some Album"author="Some Author"comment="Professionally encoded using ffmpeg, x264 and GPAC Utilies"created="2007"MP4Box -inter 500 -itags album="$album":artist="$author":comment="$comment":created="$created":name="$name" -lang English "${filename%.*}".mp4# Clean up temporary files...if [ $deltemp == "TRUE" ]; then echo "* * * Removing temporary files... * * *" rm "${filename%.*}"_temp*fi