LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash Loops multiplex A/V (http://www.linuxquestions.org/questions/linux-general-1/bash-loops-multiplex-a-v-623126/)

lpn1160 02-22-2008 03:31 PM

Bash Loops multiplex A/V
 
I have a shell script I'm using to convert a large batch of those dreaded .wmv files.
here's my script which works perfect,

for i in *.wmv ; do
j=${i%.wmv}
if [ -f "$i" ]; then
rm -f "$i.wav"
mkfifo "$i.wav"
nice -n 15 mplayer -quiet -vo null -vc dummy "$i" -ao pcm:waveheader:file="$i.wav" &
nice -n 15 lame -V5 -m m --vbr-new --resample 32000 "$i.wav" "$j.mp3"
rm -f "$i.wav"
fi
done

for i in *.wmv ; do
j=${i%.wmv}

nice -n 15 /usr/bin/mencoder -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 "$i" -o "$j.avi"
done

echo $?

if [ $? == 0 ] ; then kdialog --msgbox "encoding successfull" ; then rm -f *.wmv
elif
[ $? == 1 ] ; then kdialog --error "sorry there were errors" ; exit
fi
The problem is I can't seem to find the proper way to get mencoder to multiplex the .avi with the .mp3. I've tried ten different ways,like if there's 10 .avi & 10 .mp3 how can I have mencoder match up the proper video and audio?? I know on 1 by 1 basis is simple enough

"mencoder -idx -ovc copy -oac copy video.avi -audiofile audio.mp3 -o samename.AVI"
I've read tutorials and googled and such but this one is stumping me.
any help is appreciated

Thank you all so kind!!

unSpawn 02-23-2008 07:01 AM

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



All times are GMT -5. The time now is 04:09 AM.