LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 02-22-2008, 03:31 PM   #1
lpn1160
Member
 
Registered: May 2004
Location: USA
Distribution: pclinuxos
Posts: 37

Rep: Reputation: 15
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!!
 
Old 02-23-2008, 07:01 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,743
Blog Entries: 54

Rep: Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972Reputation: 2972
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash, LS, For loops, and whitespaces in directories jhrbek Programming 27 09-22-2010 06:17 AM
Bash Loops UnitedWeFall Programming 8 08-21-2007 07:33 AM
bash scripting and loops phoeniks Programming 5 01-24-2005 05:00 PM
bash, loops and spaces in filenames shy Programming 5 11-08-2004 08:43 AM
bash - while + until loops grouping? trees Linux - General 2 02-19-2004 03:29 PM


All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration