Author Topic: Converting multiple files to mp3  (Read 1183 times)

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Converting multiple files to mp3
« Reply #15 on: 29 January 2003, 00:29 »
quote:
Originally posted by void main:
Actually the spaces are a problem in the lame command, not the "for" loop. This works for me:

$ for i in *.[Ww][Aa][Vv]; do lame --preset extreme "$i" "${i%%.[Ww][Aa][Vv]}.mp3"; done

Which also accounts for case. The quotes should fix the problem with spaces in the parameters for lame.



Or to do everything in the current directory and all subdirectories:

$ for i in `find -iname '*.wav'`; do lame --preset extreme "$i" "${i%%.[Ww][Aa][Vv]}.mp3"; done

[edit]
This last example doesn't work. Sorry about that!
[/edit]

[ January 28, 2003: Message edited by: void main ]

Someone please remove this account. Thanks...

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Converting multiple files to mp3
« Reply #16 on: 29 January 2003, 00:38 »
I don't think that last one works with spaces.
 You're right though that "for i in *.wav" will work if you enclose the "$i" in quotes, but that won't work if you're using "for i in `find..."
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca


voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Converting multiple files to mp3
« Reply #17 on: 29 January 2003, 00:51 »
You are right, and the bad part is I actually knew that wouldn't work, and I actually tested it and proved that it didn't work, and then I posted it anyway as I was distracted on another forum...

[ January 28, 2003: Message edited by: void main ]

Someone please remove this account. Thanks...

Agent007

  • Member
  • **
  • Posts: 120
  • Kudos: 0
Converting multiple files to mp3
« Reply #18 on: 30 January 2003, 12:04 »
hi all,

Thanks a tonne to beltorak, the following syntax works superbly!! Encoding wav files to mp3 is just a breeze!

 
quote:

find -name "*.wav" | while read item; do lame --preset extreme "$item" "${item/.wav/}.mp3";done




Could someone pls explain as to what this portion of the syntax means? Whats the dollar sign for?
"$item" "${item/.wav/}.mp3"

thanks,
007

PS:- I try to stay away from sed, since its a bit complicated to remember the characters and stuff.....

[ January 30, 2003: Message edited by: Agent007 ]

AMD Athlon processor
256MB SDRAM
Linux Distro - RedHat 9.0

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Converting multiple files to mp3
« Reply #19 on: 30 January 2003, 21:56 »
$ is used to identify a variable. In this case $item will refer to each wav file returned by the 'find' command.
The "${item/.wav/}.mp3" bit is used to specify the output filename. This removes ".wav" from the filename and then adds ".mp3" onto the end.
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca


beltorak0

  • Member
  • **
  • Posts: 223
  • Kudos: 0
    • http://www.angelfire.com/realm/beltorak
Converting multiple files to mp3
« Reply #20 on: 31 January 2003, 21:29 »
sure man.  glad it worked   .

Until Stryker posted his answer tho, i coudn't figure out how to get around the whole "for FILE in *" problem....  ty Stryker.
from Attrition.Org
 
quote:
Like many times before, Microsoft is re-inventing the wheel and opting for something other than round.

-t.


Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
Converting multiple files to mp3
« Reply #21 on: 31 January 2003, 10:16 »
quote:
Originally posted by beltorak:
sure man.  glad it worked       .

Until Stryker posted his answer tho, i coudn't figure out how to get around the whole "for FILE in *" problem....  ty Stryker.



no problem man, that's what i'm here for. it was strange too, this was posted just a few hours after i was just done learning some of the sed command and the while command.

and yes, i was thinking you were going from mp3 to wav, my mistake, but you get the idea.

[ January 31, 2003: Message edited by: Stryker ]


LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Converting multiple files to mp3
« Reply #22 on: 31 January 2003, 14:15 »
Speaking of going from *.mp3 to *.wav, I decided to play:

for i in `find -name "*.mp3"`; do mpg123 -w "${i/.mp3}.wav" $i; done

This is a good thread. We need to archive this one.
"American English -- the noble language of your superiors"

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
Converting multiple files to mp3
« Reply #23 on: 31 January 2003, 14:26 »
hey! that looks like a nice simple script! i found another script to do this but it didn't work  :(
i've been using xmms to do this job but will try that now you posted it. thanks!
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Converting multiple files to mp3
« Reply #24 on: 31 January 2003, 15:59 »
OK..now I have I question.

I have a shitload of *.mp3 files that are saved on CDROMs that I want to relocate to a single directory on my Linux drive. The files are sorted in their respective directories by band-names, and most of them have spaces (They are from my windoid days on Kazaa and Napster.) I cannot use the tr command, as they are on a read only filesystem, and I can't copy them to a temp directory, as bash gives me a bunch of error messages pertaining to the spaces in the files.  

Is there a workaround to this?
"American English -- the noble language of your superiors"

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Converting multiple files to mp3
« Reply #25 on: 31 January 2003, 16:19 »
Just do

find /cdromdirectory -name '*.mp3' | while read item; do cp "$item" /destinationdirectory; done
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca


LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Converting multiple files to mp3
« Reply #26 on: 31 January 2003, 17:17 »
Nice... that was quite easy. Like always, I am making things 100x more difficult than they should be. Here I am on the friggin' bash man page all night....

Thanks flap...
"American English -- the noble language of your superiors"

Agent007

  • Member
  • **
  • Posts: 120
  • Kudos: 0
Converting multiple files to mp3
« Reply #27 on: 31 January 2003, 20:53 »
I just envy u guys who r expert with BASH...    How do I get started? Are the man pages enough?

some pointers to a newbie wud be a gr8 help!

thanks,
007
AMD Athlon processor
256MB SDRAM
Linux Distro - RedHat 9.0

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca