LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2005, 12:17 PM   #1
afrodocter
Member
 
Registered: Sep 2003
Distribution: slackware 9.1
Posts: 110

Rep: Reputation: 15
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
===================================================================
 
Old 02-04-2005, 12:35 PM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
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...
 
Old 02-04-2005, 12:37 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Why don't you just put a function in your ~/.bashrc like :
Code:
convertMyDir() {
    find $1 -type f -name '*.wma' -exec wmatomp3 {} \;
}
so you can call it with :
convertMyDir /path/to/dir
 
Old 02-07-2005, 11:35 AM   #4
afrodocter
Member
 
Registered: Sep 2003
Distribution: slackware 9.1
Posts: 110

Original Poster
Rep: Reputation: 15
"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"
 
Old 02-07-2005, 03:11 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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
 
Old 02-10-2005, 08:23 PM   #6
afrodocter
Member
 
Registered: Sep 2003
Distribution: slackware 9.1
Posts: 110

Original Poster
Rep: Reputation: 15
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??
 
Old 02-15-2005, 02:00 PM   #7
sleepkreep
LQ Newbie
 
Registered: Feb 2005
Location: Murfreesboro, TN
Distribution: Kubuntu 5.04
Posts: 4

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

Last edited by sleepkreep; 02-15-2005 at 02:10 PM.
 
Old 03-01-2005, 12:22 PM   #8
afrodocter
Member
 
Registered: Sep 2003
Distribution: slackware 9.1
Posts: 110

Original Poster
Rep: Reputation: 15
wow, thanks. your scipt is awsome. i really appreciate it.
 
Old 07-11-2005, 01:00 PM   #9
xHades101x
LQ Newbie
 
Registered: Oct 2003
Location: UT
Distribution: SuSE 8.2 Pro
Posts: 9

Rep: Reputation: 0
Above script

It just deletes everything for me, So on the first try might want to have a backup
 
Old 08-03-2005, 09:40 PM   #10
LysanderFound
LQ Newbie
 
Registered: Aug 2005
Posts: 1

Rep: Reputation: 0
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?
 
Old 08-19-2005, 09:44 PM   #11
sleepkreep
LQ Newbie
 
Registered: Feb 2005
Location: Murfreesboro, TN
Distribution: Kubuntu 5.04
Posts: 4

Rep: Reputation: 0
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.
 
Old 08-21-2005, 09:05 PM   #12
MrJester
LQ Newbie
 
Registered: Aug 2005
Location: Norfolk, VA
Posts: 7

Rep: Reputation: 0
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
Any Ideas on the problems
 
Old 08-22-2005, 03:18 PM   #13
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
Quote:
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 (snip)
Yeah, this happens when there are non-printable characters before the shebang at the top of the script. Sometimes this happens with cutting and pasting, or moving from windows to unix text formats. Try looking at it in a hex editor (emacs hexl-mode works great) and make sure there's nothing before the #!.
 
Old 08-23-2005, 10:41 AM   #14
MrJester
LQ Newbie
 
Registered: Aug 2005
Location: Norfolk, VA
Posts: 7

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


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Who-is-calling-Who (bash programming) kaone Programming 2 09-19-2005 10:31 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
calling mplayer -identify via php script? bai_design Programming 8 01-27-2005 01:37 PM
Calling all bash fans.... jong357 Slackware 2 03-16-2004 07:52 PM
c++ calling bash? adam_boz Programming 4 10-23-2002 12:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:22 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
Open Source Consulting | Domain Registration