LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 04-15-2006, 01:20 AM   #1
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 60
Help with a little script using LAME


I have a bunch of .mp3 files I want to convert to monaural. I found an old thread here that lined out how to set up a loop for LAME to process all the files in a directory, and modified it to make the changes I needed. This is it:
Code:
for song in tmp/*.mp3; do lame -m m -b 160 $song; done
It works beautifully except that it writes the new files out with an additional .mp3 at the end so all the songs are named title.mp3.mp3. I assume it's doing this to protect the original files named title.mp3

How can I have it drop the outfiles into a different directory so that name change won't be neccessary?
 
Old 04-15-2006, 02:34 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
well the lame manpage states you can provide an in file and and out file, so just provide names including paths there, e.g. old/blah.mp3 and new/blah.mp3 and that'll take care of what you need. tools like basename and dirname can be really useful for removing directories and extensions from filename strings too.
 
Old 04-15-2006, 10:31 AM   #3
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Original Poster
Rep: Reputation: 60
Quote:
...so just provide names including paths
I tried ... Believe me, I tried.

My shell scripting knowledge is sparse indeed, but in the case of this little jewel, it appears to me that infile is supplied by the variable 'song', and outfile by '$song'.

I tried several forms adding directory instructions to $song ("/$song", "home/$song", /home/"$song", etc) , but none worked.

If I can't get it to work in the script, I'll check out your file renaming tools. That was going to be my next area of investigation. This little script works so beautifully, tho ... I'd like to get it to finish the job.
 
Old 04-15-2006, 01:50 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
well you should say what "none worked" really means... what happened on each attempt?

in your example above your file list is "tmp/a.mp3, tmp/b.mp3" etc... so if you try to use "home/$song" you'll be trying to write to "home/tmp/a.mp3" etc, and of course all these are going to be relative to the current directory.
 
Old 04-15-2006, 02:43 PM   #5
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Original Poster
Rep: Reputation: 60
OK. That gave me enough information to solve the problem.

In my ~/tmp directory where the original files are, I created another directory also named ~tmp/. This child directory MUST have the same name as the mother directory. (I hope that terminology is correct.) I then changed the code to
Code:
for song in tmp/*.mp3; do lame -m m -b 160 "$song" "tmp/$song"; done
What a beautiful thing!
 
Old 04-16-2006, 12:36 PM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by rickh
... it appears to me that infile is supplied by the variable 'song', and outfile by '$song'. ...
In your original form of the script, infile was supplied by '$song' & outfile was not supplied at all. The 'song' in 'for song in tmp/*.mp3;' was setting the values to be used by the variable. 'song' & '$song' are the same variable, 'song' is its name & '$song' is its value -- it's a bash thing.


Quote:
Originally Posted by rickh
... This child directory MUST have the same name as the mother directory. ...
I think you will find any proper path will do in constructing the outfile suppied to LAME (or any other app.). I believe this would also work:
Code:
mkdir ~/mono_mp3s
for song in tmp/*.mp3 
do lame -m m -b 160 "$song" "~/mono_mp3s/$song"
done
BTW, do you cd to ~/tmp when you run the script?
 
Old 04-16-2006, 01:12 PM   #7
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Original Poster
Rep: Reputation: 60
Quote:
BTW, do you cd to ~/tmp when you run the script?
No. I cd to the directory that contains /tmp/. Thanks for the further instruction. I know a number of people who can use this function. Do you think I can make it work from a Windows command prompt?
 
Old 04-17-2006, 08:19 AM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by rickh
... Do you think I can make it work from a Windows command prompt?
Maybe. -- I think it's not so much getting the script to run, but getting LAME to run. The script itself is simple enough that it could probably be rewritten as a Win .cmd file (i.e. 2k/XP script).

Sorry I can't help you w/ the getting LAME to run part -- since May of last year all the computers I own run only GNU/Linux.

If you don't mind my asking, why do you want to run this from a Win prompt?
 
Old 04-17-2006, 10:16 AM   #9
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Original Poster
Rep: Reputation: 60
LAME is also available for Windows. I don't want to run it there, but most of the people I know use Windows. This sort of function is a good introduction to Open-source.

Also I looked over your script, and I don't think it will work unless I actually cd into the directory where the original files are. If I did that would I remove the 'in' from the initial line?
 
Old 04-17-2006, 03:21 PM   #10
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 231Reputation: 231Reputation: 231
My bad, that script (of mine) is terrible, well sloppy anyway.

I think this is right, or at least better:
Code:
## initialize the following w/ the appropriate dirs
ORIG=<~/location/of/stereo/mp3s>
MONO=<~/location/to/put/mono/mp3s>

for SONG in $ORIG/*.mp3 
do lame -m m -b 160 $SONG $MONO/`basename $SONG` 
done

Quote:
If I did that would I remove the 'in' from the initial line?
NO! -- the 'in' is part of the 'for ... in ... do' syntax. See the bash man page, do a search on "do list" rather than "for" to get to the right section.
 
Old 09-06-2006, 02:07 PM   #11
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Original Poster
Rep: Reputation: 60
Everyone else can ignore this ...

It seems like I'm constantly coming up with the need to go back and review instructions I've received regarding the manipulation of .mp3 files using lame in a script, renaming mp3s, etc. As time goes by, I have a harder and harder time finding the pertinent threads ... so this is a little helper just for me.

Identify Duplicate Files by Filname
'ls' .. or something to identify filenames that have a (space)(numeral) pattern
Script to change file names with incremental counter.

Last edited by rickh; 09-06-2006 at 02:10 PM.
 
  


Reply

Tags
automatic, rename


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ALAC & Lame Script Soulful93 Programming 6 04-15-2009 08:24 PM
Script: lame stumbles on spaces in filename browny_amiga Linux - General 5 05-14-2008 09:14 AM
darkice with lame support can't find lame h2gofast Debian 4 03-17-2006 12:20 PM
Bash script for LAME LocoMojo Linux - Newbie 6 01-09-2005 07:41 PM
Lame doralsoral Linux - Software 4 09-09-2003 12:54 AM


All times are GMT -5. The time now is 01:08 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