Need only one loop, so grouping stuff together should work. Untested example so YMMV(VM):
Code:
#!/bin/sh
# For testing, else comment out:
set -evx
[ $# -ne 0 ] && set -n
# Since all children inherit we'll apply nice value to self:
nice -n 15 $$
# Functions make it easier to group stuff you call more often or only under certain conditions
showError() { kdialog --error "Error during "$1", exiting."; exit 1; }
showOKAndRemove() { kdialog --yesno "All OK. Delete "$1"?" 2>/dev/null; case "$?" in 0) rm -f "$1";; *) ;; esac; }
# Group options so you only have to change in one easy accessable place or place in a config file and source it:
MPLAYER_OPTS0='-quiet -vo null -vc dummy'
MPLAYER_OPTS1='-ao pcm:waveheader:file='
LAME_OPTS='-V5 -m m --vbr-new --resample 32000'
MENCODER_OPTS0='-idx -ovc xvid -xvidencopts me_quality=6:fixed_quant=3:vhq=2:bf_threshold=1:max_bframes=1:hq_ac:\
chroma_me:chroma_opt:max_key_int erval=100:bvhq=1:min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:\
min_bquant=1:max_bquant=31:no qpel:nogmc:trellis:nopacked:closed_gop:nocartoon:quant_type=mpeg -nosound -ofps 29.970'
MENCODER_OPTS1='-idx -ovc copy -oac copy'
find . type f -iname \*.wmv | while read INPUT; do
OUTPUT="${INPUT%.wmv}"
# Outputname with underscores instead of spaces uncomment this:
#OUTPUT="${OUTPUT// /_}"
# Since 'find' fins stuff we only need to break on wacky INPUT name
if [ ! -f "${INPUT}" ]; then
showError "finding file ${INPUT}"
fi
rm -f "${INPUT}.wav" || showError "removing wav file"
mkfifo "${INPUT}.wav" || showError "mkfifo"
mplayer $MPLAYER_OPTS "$INPUT" $MPLAYER_OPTS1"${INPUT}.wav" || showError "wav creation"
lame $LAME_OPTS "${INPUT}.wav" "${OUTPUT}.mp3" || showError "creating mp3"
rm -f "${INPUT}.wav" || showError "removing wav file"
mencoder $MENCODER_OPTS0 "${INPUT}" -o "${OUTPUT}.avi" || showError "video encoding"
mencoder $MENCODER_OPTS1 "${OUTPUT}.avi" -audiofile "${OUTPUT}.mp3" -o "${OUTPUT}.avi" || showError "muxing"
showOKAndRemove "${INPUT}"
done
exit 0