#!/bin/bash
#
#
# Requires: zenity, mencoder, dvdauthor, awk, dvd+rw-mediainfo, growisofs
#
#
IFS=$'\n'
TEMP_DIR='converted'
if [ "$1" == "" ]; then
zenity --error --text="No files were specified"
exit
fi
zenity --question --text='Are the files intelaced?' --cancel-label='Yes' --ok-label='No'
if [ $? -eq 1 ]; then
DEINTERLACE=1
fi
for FILE in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
FOLDER="${FILE%/*}"'/'
FFILE="${FILE##*/}"
mkdir "$FOLDER$TEMP_DIR"
#zenity --info --text='nice -n 19 mencoder '"$OPTION_DEINTERLACE"' '"$FILE"' -ovc x264 -x264encopts pass=1:turbo=1:nr=500
snr -oac mp3lame -lameopts cbr:br=128 -ofps 30000/1001 -o /dev/null'
if [ $DEINTERLACE -eq 1 ]; then
nice -n 19 mencoder "$FILE" -ovc x264 -x264encopts pass=1:turbo=1:nr=500
snr -vf pp=md -oac mp3lame -lameopts cbr:br=128 -ofps 30000/1001 -o /dev/null 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/," ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Position :\\t"$1"\\nFrame :\\t"$2"\\nPercentage :\\t"$3"%\\nFrame Rate :\\t"$4"\\nTime Remaining :\\t"$6; fflush();}' | nice -n 19 zenity --progress --auto-kill --auto-close --title="Converting ${FILE##*/} (Pass 1 of 2)" --width=450
nice -n 19 mencoder "$FILE" -ovc x264 -x264encopts pass=2:nr=500
snr:bitrate=900 -vf pp=md -oac mp3lame -lameopts cbr:br=128 -ofps 30000/1001 -o "$foLDER$TEMP_DIR/${FFILE%.*}.avi" 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/," ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Position :\\t"$1"\\nFrame :\\t"$2"\\nPercentage :\\t"$3"%\\nFrame Rate :\\t"$4"\\nTime Remaining :\\t"$6; fflush();}' | nice -n 19 zenity --progress --auto-kill --auto-close --title="Converting ${FFILE} (Pass 2 of 2)" --width=450
else
nice -n 19 mencoder "$FILE" -ovc x264 -x264encopts pass=1:turbo=1:nr=500
snr -oac mp3lame -lameopts cbr:br=128 -ofps 30000/1001 -o /dev/null 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/," ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Position :\\t"$1"\\nFrame :\\t"$2"\\nPercentage :\\t"$3"%\\nFrame Rate :\\t"$4"\\nTime Remaining :\\t"$6; fflush();}' | nice -n 19 zenity --progress --auto-kill --auto-close --title="Converting ${FILE##*/} (Pass 1 of 2)" --width=450
nice -n 19 mencoder "$FILE" -ovc x264 -x264encopts pass=2:nr=500
snr:bitrate=900 -oac mp3lame -lameopts cbr:br=128 -ofps 30000/1001 -o "$foLDER$TEMP_DIR/${FFILE%.*}.avi" 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/," ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Position :\\t"$1"\\nFrame :\\t"$2"\\nPercentage :\\t"$3"%\\nFrame Rate :\\t"$4"\\nTime Remaining :\\t"$6; fflush();}' | nice -n 19 zenity --progress --auto-kill --auto-close --title="Converting ${FFILE} (Pass 2 of 2)" --width=450
fi
rm divx2pass.log divx2pass.log.mbtree
done