#!/bin/bash # Andrew's Super Special Video Encoder Script LOLOLOL # From MythTV to mkv (x264 and ogggggg vorbissss) # Some stuff borrowed from a cool script I found on mythtv-users mailing list # Public Domain / I can't be bothered to license :P # http://andrewgee.org # andrew@andrewgee.org IC="\033[0;31m" NC="\033[0m" echo -e $IC"Andrew's Super Special Video Encoder Script (ASSVES)"$NC echo -e $IC"---"$NC m2vfile=${1} mp2file=${2} bpp=0.15 #Or ${3} aq=3 #Or ${4} videofilters=${5} op=`echo ${1} | sed s/.m2v//` #Check to see if bpp has been over-ridden if [ "${3}" != "" ]; then bpp="${3}" fi #Check to see if audio quality has been over-ridden if [ "${4}" != "" ]; then aq=${4} fi #Check for m2v and mp2 files if [ \! -e "${2}" ] || [ \! -e "${1}" ]; then echo -e $IC"** m2v or mp2 files DO NOT EXIST"$NC exit fi echo -e $IC"AUDIO Processing --------------------------------------------------------"$NC #Check to see if the ogg is already there if [ \! -e "${op}".ogg ]; then echo -e $IC"* Decoding Audio to WAV"$NC mplayer "${2}" -vc null -vo null -ao pcm:fast:file="${op}.wav" > /dev/null 2>/dev/null echo -e $IC"* Normalising Audio"$NC normalize-audio "${op}".wav echo -e $IC"* Reencoding audio to OGG Vorbis"$NC oggenc -q ${aq} -o "${op}".ogg "${op}".wav echo -e $IC"* Removing temporary WAVs"$NC rm "${op}".wav else echo -e $IC"** Ogg file already there. Remove ${op}.ogg to reencode"$NC fi echo -e $IC"VIDEO Processing --------------------------------------------------------"$NC #get original video information echo -e $IC"* Finding crop information, size, and framerate"$NC if [ "${5}" == "" ]; then mplayer -ac ac3, -frames 900 -vo null -ao null -vf cropdetect "${1}" 2>/dev/null > "${op}".stats.txt else mplayer -ac ac3, -frames 900 -vo null -ao null -vf ${5},cropdetect "${1}" 2>/dev/null > "${op}".stats.txt fi crop=`grep '[CROP]' "${op}".stats.txt | tail -1 | sed "s/.*crop=/crop=/;s/).*//"` x=`echo $crop | sed "s/crop=//;s/\(.*\):\(.*\):\(.*\):\(.*\)/\1/"` y=`echo $crop | sed "s/crop=//;s/\(.*\):\(.*\):\(.*\):\(.*\)/\2/"` ##VIDEO: MPEG2 720x576 (aspect 3) 25.000 fps 15000.0 kbps (1875.0 kbyte/s) fr=`grep ' fps ' "${op}".stats.txt | tail -1 | sed "s/ fps .*//;s/\.000//;s/.* (aspect .) //"` rm "${op}".stats.txt echo -e $IC"* Calculating bitrate"$NC bitrate=$(echo "scale=4; ${x} * ${y} * ${fr} * ${bpp}" | bc | cut -d . -f 1) echo -e $IC"* Video Settings: ${x}x${y} ${fr} fps ${bitrate} bps"$NC echo if [ \! -e "${op}.1p.log" ]; then echo -e $IC"* First Pass Video Encode..."$NC mencoder -passlogfile "${op}.1p.log" -vf yadif,${crop},harddup -ofps ${fr} -ovc x264 -x264encopts bitrate=${bitrate}:pass=1:turbo=2:keyint=250:bframes=3:direct_pred=auto:subq=5:frameref=3:b_pyramid:weight_b:threads=2 -oac copy -o /dev/null "${1}" else echo -e $IC"** Skipping first pass - log already exists"$NC fi echo if [ \! -e "${op}".264 ]; then echo -e $IC"* Second Pass Video Encode..."$NC mencoder -passlogfile "${op}.1p.log" -vf yadif,${crop},harddup -ofps ${fr} -ovc x264 -x264encopts bitrate=${bitrate}:pass=2:turbo=2:keyint=250:bframes=3:direct_pred=auto:frameref=3:me=umh:partitions=all:b_pyramid:weight_b:threads=2 -oac copy -of rawvideo -o "${op}".264 "${1}" else echo -e $IC"** Skipping second pass - video encode already exists"$NC fi echo ###Multiplex echo -e $IC"MULTIPLEXING ------------------------------------------------------------"$NC if [ \! -e "${op}".mkv ]; then echo -e $IC"Multiplexing to mkv format"$NC mkvmerge -o "${op}".mkv "${op}".264 "${op}".ogg else echo -e $IC"Skipping muxing. mkv file already exists"$NC fi echo echo -e $IC"SCRIPT COMPLETE"$NC