#!/bin/bash
#nathan jahnke <njahnke@gmail.com>

if [ $# != 2 ] ; then echo "usage: $0 hq_avs_basename number_of_cpus" ; exit 1 ; fi

for thefile in `ls -1 "${1}"*` ; do  #must not be spaces in the filepaths

mv -v "${thefile}" "${thefile}.sumibak"

i=1 ; while [ $i -le ${2} ] ; do

thefilebase=`echo -n "${thefile}" | sed 's/\.avs$//'`
cp -v "${thefile}.sumibak" "${thefilebase}_${i}.avs"

echo 'sumichan_chop=(last.framecount/'${2}')' >> "${thefilebase}_${i}.avs"

case ${i} in
${2}) echo 'trim((sumichan_chop*'`expr ${i} - 1`')+1,0)' >>  "${thefilebase}_${i}.avs"
echo 'avisource("'"${thefilebase}_${i}.avi"'")
ConvertToYV12()' >> "${thefile}";;
*) echo 'trim((sumichan_chop*'`expr ${i} - 1`')+1,sumichan_chop*'${i}')' >> "${thefilebase}_${i}.avs"
echo 'avisource("'"${thefilebase}_${i}.avi"'")++\' >> "${thefile}";;
esac

echo 'call P:\bat\nmf.bat '"${thefilebase}"'_'${i} >> "${1}_${i}.bat"

i=$[ $i + 1 ]
done
done
exit 0
