#!/bin/bash
#nathan jahnke <njahnke@gmail.com>

wine 'P:\bat\avs2wav.exe' "$1.avs" - | wine 'c:\program files\anrichan\neroaacenc.exe' -br 64000 -lc -if - -of "$1a.mp4"
 
wine 'C:\Program Files\anrichan\x264.exe' --pass 1 --bitrate 512 --vbv-maxrate 768 --stats "$1.stats" --no-cabac --analyse none --qpmin 17 --threads 2 --thread-input --progress --no-psnr --no-ssim --output NUL "$1.avs" 

wine 'C:\Program Files\anrichan\x264.exe' --pass 2 --bitrate 512 --vbv-maxrate 768 --direct auto --level 1.3 --stats "$1.stats" --mixed-refs --no-cabac --bime --weightb --subme 6 --trellis 2 --analyse all --me umh --qpmin 17 --threads 2 --thread-input --progress --no-psnr --output "$1v.mp4" "$1.avs" 

wine 'C:\Program Files\anrichan\MP4Box.exe' -new -add "$1v.mp4" -add "$1a.mp4" "$1.mp4"

if [ -n "$2" ] ; then
	if [ $2 eq 1 ] ; then
		rm "$1v.mp4" "$1a.mp4" "$1.stats"
	fi
fi

exit 0
