LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-02-2004, 04:56 PM   #1
khermans
Member
 
Registered: Sep 2001
Distribution: Ubuntu, Debian, Gentoo
Posts: 162

Rep: Reputation: 30
Batch LAME MP3 conversion ???


I'm trying to find a way to batch convert a whole slew of files using lame. I have my options set up, but I don't know how to make it run through a list of files. Any help would be greatly appreciated :-)

Kristian Hermansen
 
Old 07-02-2004, 05:24 PM   #2
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
may be this page can help you
http://www.tldp.org/HOWTO/MP3-CD-Burning/audio.html
 
Old 07-02-2004, 06:18 PM   #3
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
An easy way of quickly getting it done would be doing a little loop in the shell and then using id3ed or some other batch id3 editor to change the tags.

for file in *.wav; do lame --alt-preset extreme "$file"; done would be enough to encode all the .wav files in a directory to .wav.mp3 using the extreme --alt-preset (what better options could you wish for? ).


Håkan
 
Old 07-02-2004, 06:34 PM   #4
khermans
Member
 
Registered: Sep 2001
Distribution: Ubuntu, Debian, Gentoo
Posts: 162

Original Poster
Rep: Reputation: 30
Yes this worked for me. Thanks for the second post. The first post was good, but it took me a little while to figure out that $i needed to be within quotes like "$i"!!! The TLDP.org page in the first reply will not work because of the syntax errors, so thanks for informing me of it in the second post :-)

Kristian Hermansen
 
Old 03-18-2005, 02:48 PM   #5
UltimateZer0
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Rep: Reputation: 0
Quote:
Originally posted by hw-tph
encode all the .wav files in a directory to .wav.mp3 using the extreme --alt-preset (what better options could you wish for? ).
How about a "for; do" script to change the ".wav.mp3" to ".mp3"?

Or, in my case, changing ".mp3.mp3" to ".mp3" because I'm re-encoding all of my music to be ABR192 to save disk space; so while I'm testing my theories, I've got a directory full of .mp3 and .mp3.mp3

My current, albeit failing, theory is something along the lines of:
Code:
for file in *.mp3.mp3; do mv -f "$file.mp3.mp3" "$file.mp3"; done
which always gives me a "cannot stat ... No such file or directory" error.

I wish I could figure out how to do this myself, but I know very little of programming. . . please help me!
 
Old 03-18-2005, 03:06 PM   #6
UltimateZer0
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Rep: Reputation: 0
Nevermind. I just figured it out, with the help of some Linux Veterans. (Thx, guys!)

Just in case anyone is in the predicament I was in, here's the code:
Code:
#!/bin/bash

for file in *.mp3; do lame --preset 192 -ms -h "$file"; done

for i in *.mp3.mp3 ; do
n=`basename "$i" .mp3.mp3`
mv "$i" "$n".mp3
done
I put that text into my editor and saved it as /bin/mp3batch, but I might note that I had to "chmod +x"before it would run.
If you decide to use this, obviously you'll want to tailor it to your needs, but that's basically it.
 
Old 03-18-2005, 04:59 PM   #7
khermans
Member
 
Registered: Sep 2001
Distribution: Ubuntu, Debian, Gentoo
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by UltimateZer0
Nevermind. I just figured it out, with the help of some Linux Veterans. (Thx, guys!)

Just in case anyone is in the predicament I was in, here's the code:
Code:
for i in *.mp3.mp3 ; do
n=`basename "$i" .mp3.mp3`
mv "$i" "$n".mp3
done
This should work much more easily for you:

Code:
rename 's/.mp3//' *.mp3
Try that man ;-P The expression s/.mp3// strips the .mp3 extension for you...

Kristian Hermansen
 
Old 03-27-2005, 12:18 AM   #8
UltimateZer0
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Rep: Reputation: 0
Alright, I've simplified my script; but I was wondering if anyone knew how to throw maybe a "-r" flag in there to be recursive. I have quite a few folders under /music and it's tedious and painful to go into each dir and run the script manually.

Any help would be greatly appreciated.
 
Old 03-27-2005, 01:38 AM   #9
khermans
Member
 
Registered: Sep 2001
Distribution: Ubuntu, Debian, Gentoo
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by UltimateZer0
Alright, I've simplified my script; but I was wondering if anyone knew how to throw maybe a "-r" flag in there to be recursive. I have quite a few folders under /music and it's tedious and painful to go into each dir and run the script manually.
The easiest way that I know how to do this is listed below. Say you are in a directory /home/foo, which has subdirectories sub1, sub2, and sub3. And all the subdirectories have files named blah???.mp3.mp3, where ? can be substituted for a character of any choice. You just want to rename all the .mp3.mp3 files in all the subdirectories right? So here you go:

Code:
find /home/foo -iname *.mp3.mp3 | rename 's/.mp3//'
Let me know if that doesn't work for ya ;-)

Kristian Hermansen

Last edited by khermans; 03-27-2005 at 01:46 AM.
 
Old 03-27-2005, 01:59 PM   #10
UltimateZer0
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Rep: Reputation: 0
Quote:
Originally posted by khermans
You just want to rename all the .mp3.mp3 files in all the subdirectories right?
Well, actually, I was hoping I could re-encode and then rename files recursively; but your scripting gives me an idea. Look this over and see if you think it would work:

Code:
find /home/foo -iname *.mp3 | lame --preset 192 -ms -h *.mp3 && rename 's/.mp3//'
Idunno. . . something like that. . . Whaddaya think?
 
Old 03-27-2005, 06:10 PM   #11
khermans
Member
 
Registered: Sep 2001
Distribution: Ubuntu, Debian, Gentoo
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by UltimateZer0
Well, actually, I was hoping I could re-encode and then rename files recursively; but your scripting gives me an idea. Look this over and see if you think it would work:

Code:
find /home/foo -iname *.mp3 | lame --preset 192 -ms -h *.mp3 && rename 's/.mp3//'
You will probably need to remove the *.mp3 argument to lame, since they are already coming in from the piped find command. I', not sure that the "&&" will work the way you have it. It may, but I haven't tried it myself. To be certain, you can always start another find command after your &&:

Code:
find /home/foo -iname *.mp3 | lame --preset 192 -ms -h && find /home/foo -iname *.mp3.mp3 | rename 's/.mp3//'
Try that...

Kristian Hermansen
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Grip/Lame MP3 Problem programx Linux - Software 4 11-26-2005 10:27 AM
dvd batch conversion layer1man Linux - Software 1 10-25-2005 08:06 AM
audacity, batch conversion mifan Linux - Software 1 08-19-2005 02:51 AM
still need lame, etc to burn mp3 to cd? joel b SUSE / openSUSE 1 05-04-2005 11:48 PM
Batch image conversion mrsolo Linux - Software 1 09-06-2004 04:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:45 AM.

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