bash script calling mplayer
i am writing a script to convert wma's to mp3's. its based off a kdeapp i found.
it uses mplayer and lame. this is what i want to do: find /mnt/rebel-dat/music/ -type f -name '*.wma' -exec wmatomp3 {} \; which is cool. but i would like it in a more programable form like this: =================================================================== #!/bin/sh find /mnt/rebel-dat/music/New\ Rock/u2/ -type f -name '*.wma' | while read WMA do DIR=`dirname "$WMA"` # extract path to file FILE=`basename "$WMA"` # keep just the name of the file #do some logging wavfile=${WMA%wma}wav mp3file=${WMA%wma}mp3 mplayer -ao pcm -aofile "$wavfile" "$WMA" lame "$wavfile" "$mp3file" rm "$wavfile" "$WMA" =================================================================== this doesnt work. when the mplayer line is executed mplayer freaks out gets weird. i cant figure out why. for reference the wmatomp3 is this: =================================================================== #!/bin/bash wmafile=$1 wavfile=$(echo $wmafile | sed -e s/wma/wav/) mp3file=$(echo $wmafile | sed -e s/wma/mp3/) if [ -e "$mp3file" ] then echo "$mp3file exists" else echo "$wmafile" >> "$LOG" mplayer -ao pcm -aofile "$wavfile" "$wmafile" lame "$wavfile" "$mp3file" rm "$wavfile" fi =================================================================== |
Your script looks programmatically sound to me
Only thing I noticed was that the wmatomp3 script is using: #!/bin/bash Whereas your script is using: #!/bin//sh also you don't seem to be testing for the wav or mp3 files already existing... |
Why don't you just put a function in your ~/.bashrc like :
Code:
convertMyDir() { convertMyDir /path/to/dir |
"Why don't you just put a function in your ~/.bashrc like :"
--becuase i want to do some logging and create more features, such as mp3/ogg conversion settings. "Your script looks programmatically sound to me" --- i agree but when run it mplayer gives me a "no bind for key blah" |
Try replace your:
mplayer -ao pcm -aofile "$wavfile" "$wmafile" with: echo "mplayer -ao pcm -aofile $wavfile $wmafile" And see if $wavfile and $wmafile are correct |
yes they are correct.
if i replace the mplayer command with ls "$wmafile" then i get the corect listing. when i do use the mplayer command i get this: ===================================START===================================== MPlayer 1.0pre3-3.2.2 (C) 2000-2003 MPlayer Team CPU: Intel Pentium 4/Xeon/Celeron Northwood 2394 MHz (Family: 8, Stepping: 7) Detected cache-line size is 64 bytes CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1 Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2 Reading config file /usr/local/etc/mplayer/mplayer.conf: No such file or directory Reading config file /root/.mplayer/config Reading /root/.mplayer/codecs.conf: Can't open '/root/.mplayer/codecs.conf': No such file or directory Reading /usr/local/etc/mplayer/codecs.conf: Can't open '/usr/local/etc/mplayer/codecs.conf': No such file or di rectory Using built-in default codecs.conf. font: can't open file: /root/.mplayer/font/font.desc Font /usr/local/share/mplayer/font/font.desc loaded successfully! (206 chars) Using Linux hardware RTC timing (1024Hz). Can't open input config file /root/.mplayer/input.conf: No such file or directory Can't open input config file /usr/local/etc/mplayer/input.conf: No such file or directory Falling back on default (hardcoded) input config Playing /mnt/rebel-dat/music/Jazz/The Motet/Live/01 w.o.w. drums.wma. ASF file format detected. ============ ASF Stream group == START === object size = 32 stream count=[0x1][1] stream id=[0x1][1] max bitrate=[0x1f67f][128639] ============ ASF Stream group == END === Clip info: name: w.o.w. drums author: The Motet ========================================================================== Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders AUDIO: 44100 Hz, 2 ch, 16 bit (0x10), ratio: 16002->176400 (128.0 kbit) Selected audio codec: [ffwmav2] afm:ffmpeg (DivX audio v2 (ffmpeg)) ========================================================================== Checking audio filter chain for 44100Hz/2ch/16bit -> 44100Hz/2ch/16bit... AF_pre: af format: 2 bps, 2 ch, 44100 hz, little endian signed int AF_pre: 44100Hz 2ch Signed 16-bit (Little-Endian) AO: [oss] 44100Hz 2ch Signed 16-bit (Little-Endian) (2 bps) Building audio filter chain for 44100Hz/2ch/16bit -> 44100Hz/2ch/16bit... Video: no video Starting playback... No bind found for key b No bind found for key J A: 0.4 0.0% 0% No bind found for key M No bind found for key L A: 0.8 0.6% 0% A: 1.2 0.6% 0% No bind found for key . No bind found for key b No bind found for key J A: 1.6 0.6% 0% No bind found for key M No bind found for key L A: 2.0 0.5% 0% No bind found for key . .----------------continues . No bind found for key M No bind found for key L A: 8.8 0.7% 0% ===== PAUSE ===== Exiting... (Quit) -dat/music/Jazz/The Motet/Live/10 belly.wma does not exits then from here no it is messed up. the names are all missing pieces. the only thing i can think of is that its a bug in mplayer?? |
Better script
I wrote this script a few days ago. Works flawlessly for me. Gives you plenty of options such as scanning entire computer, scanning current directory and subdirectories, or just current directory. Hope you enjoy.
#!/bin/sh dialog --title "WmaToMp3" --msgbox "Welcome to Wma to Mp3 Converter!!" 9 28 dialog --msgbox "Lets take a minute to setup some options..." 9 28 dialog --title "Pick One" --menu "Step one: Where would like for me to search for files?" 10 60 3 1 "Entire Computer" 2 "Current Directory and all subdirectories" 3 "Current Directory Only" 2>_1.txt DIR_OPT=$(cat _1.txt) dialog --title "Pick One" --menu "Step two: What would like for me to convert them to?" 10 60 2 1 "Mp3" 2 "Leave as wav" 2>_1.txt CONVERT_OPT=$(cat _1.txt) if [ $CONVERT_OPT = 1 ]; then dialog --title "Pick One" --menu "Step three: What bitrate would you like to use?" 10 60 4 1 "64 - Poor" 2 "128 - Better" 3 "192 - Recommended" 4 "320 - Insane" 2>_1.txt BIT_OPT=$(cat _1.txt) fi dialog --title "Pick One" --yesno "Step four: Would You like for me to remove the wma files after converting?" 10 40 DEL_OPT=$? dialog --title "Converting" --infobox "Converting... This usually takes a while. Just put on another pot of coffee." 10 60 if [ $BIT_OPT = 1 ]; then BIT_OPT=64 elif [ $BIT_OPT = 2 ]; then BIT_OPT=128 elif [ $BIT_OPT = 3 ]; then BIT_OPT=192 elif [ $BIT_OPT = 4 ]; then BIT_OPT=320 fi if [ $DIR_OPT = 1 ]; then find / -name *.wma > wmalist.dat elif [ $DIR_OPT = 2 ]; then find . -name *.wma > wmalist.dat elif [ $DIR_OPT = 3 ]; then ls *.wma > wmalist.dat fi cat wmalist.dat | sed -e "s/ /##/g" > wmalist rm -rf wmalist.dat for i in $(cat wmalist) do total=$((total+1)) i=$(echo $i | sed -e "s/##/ /g") ##Begin audiodump mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader ''"$i"'' > audiodump.dat; if [ $CONVERT_OPT = 2 ]; then NEWNAME=`echo "$i.wav" | sed -e "s/.wma//g"` mv "audiodump.wav" ''"$NEWNAME"'' elif [ $CONVERT_OPT = 1 ]; then ##Get song information title=$(sort audiodump.dat | grep " name: " | sed -e "s/ name: //g") name=$(sort audiodump.dat | grep " author: " | sed -e "s/ author: //g") rm audiodump.dat ##Begin Encoding lame -v -b $BIT_OPT -q 0 --tt "$title" --ta "$name" audiodump.wav ''"$i.mp3"''; rm audiodump.wav; NEWNAME=`echo "$i.mp3" | sed -e "s/.wma//g"`; mv "$i.mp3" ''"$NEWNAME"''; fi ##Remove file if opted if [ $DEL_OPT = 0 ]; then rm -f ''"$i"'' fi done dialog --title "All Done!!" --msgbox "I have finished converting all $total of your wma files. Enjoy!!" 10 60 ##Clean up rm _1.txt rm wmalist exit 0 |
wow, thanks. your scipt is awsome. i really appreciate it.
|
Above script
It just deletes everything for me, So on the first try might want to have a backup :)
|
This script didn't work for me. I'm using MEPIS 3.3 . . the script ran, got the list of questions and everything, but there was no .mp3 output (nor wave). Got some errors that I could read fast enough to actually see.
Does this require a specific lib or something? |
No, it shouldn't require any libs. Do you have the latest bash? When you execute `mplayer` does it give you any errors? How about `lame` It will only give you errors and not work properly if bash isn't the latest or mplayer and/or lame doesn't work correctly.
|
For some reason I can't get this script to work I put it into my /usr/bin dir and I have the latest versions of bash, mplayer, and lame when I run the script I get an
Code:
: Bad Interpreter: No Such File or Directory |
Quote:
|
Alrighty man I will check that out tonight when I get home. Thanks for the advice it is prob the move from win to linux because I copied it off my work comptuer which is win. thanks
|
All times are GMT -5. The time now is 05:37 PM. |