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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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:
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
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.
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:
for song in tmp/*.mp3
do lame -m m -b 160 "$song" "~/mono_mp3s/$song"
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.