Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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.
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
... 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
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?
... 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?
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.