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

Agent007

  • Member
  • **
  • Posts: 120
  • Kudos: 0
Converting multiple files to mp3
« on: 28 January 2003, 07:39 »
hi all,

I have about 100 wav files in a folder....Need to convert them to mp3. I'm using lame to do the conversion.

The systax used is:-

#lame   --preset extreme artist.wav artist.mp3

After each song is over, I have to keep changing the song names. Is it possible to make lame automatically goto the next wav file and select the same name for the mp3 file? until all the wav files are over?

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

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Converting multiple files to mp3
« Reply #1 on: 28 January 2003, 08:16 »
a simple bash script will do it for you. I'm not very experienced with bash scripts so i'm not sure how to do it.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
Converting multiple files to mp3
« Reply #2 on: 28 January 2003, 08:37 »
how about:

find -name "*.mp3" | while read item; do lame --preset "$item" `echo "$item" | sed 's/.mp3/.wav/g'`;done

will that work?

or maybe:

find -name "*.mp3" | while read item; do lame --preset extreme "$item" `echo "$item" | sed 's/.mp3/.wav/g'`;done

depending on the parameters of the lame command

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


voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Converting multiple files to mp3
« Reply #3 on: 28 January 2003, 08:41 »
quote:
Originally posted by Agent007:
hi all,

I have about 100 wav files in a folder....Need to convert them to mp3. I'm using lame to do the conversion.

The systax used is:-

#lame   --preset extreme artist.wav artist.mp3

After each song is over, I have to keep changing the song names. Is it possible to make lame automatically goto the next wav file and select the same name for the mp3 file? until all the wav files are over?

thanks,
007



How about:

$ for i in *.wav; do lame --preset $i ${i%%.wav}.mp3; done
Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
Converting multiple files to mp3
« Reply #4 on: 28 January 2003, 08:54 »
quote:
Originally posted by void main:


How about:

$ for i in *.wav; do lame --preset $i ${i%%.wav}.mp3; done



make me look stupid    
i think either one will work, but i am unfamiliar with void main's methods.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Converting multiple files to mp3
« Reply #5 on: 28 January 2003, 21:06 »
Yeah, the way I usually do it is using bash's builtin text replacement. It would be valuable to get familiar with this as it makes life really easy for many situations like this. See the section on "Parameter Expansion" in the bash man page. This way you call no external programs except for the one you want to run to perform the actual task you need to have done.
Someone please remove this account. Thanks...

Agent007

  • Member
  • **
  • Posts: 120
  • Kudos: 0
Converting multiple files to mp3
« Reply #6 on: 28 January 2003, 11:36 »
Void Main,

A minor glitch...The wav files which have names separated by spaces do not get processed.

Example,
this is a song.wav

where should i make the changes?

thanks,
007

 
quote:
Originally posted by void main:


How about:

$ for i in *.wav; do lame --preset $i ${i%%.wav}.mp3; done

AMD Athlon processor
256MB SDRAM
Linux Distro - RedHat 9.0

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
Converting multiple files to mp3
« Reply #7 on: 28 January 2003, 11:37 »
i believe my example solves that problem, although i am curious to void main's solution.

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Converting multiple files to mp3
« Reply #8 on: 28 January 2003, 12:51 »
quote:
Originally posted by Agent007:
Void Main,

A minor glitch...The wav files which have names separated by spaces do not get processed.

Example,
this is a song.wav

where should i make the changes?

thanks,
007

 



Use Stryker's solution instead. The difference between that one and Void's is that it will work with files whose names contain spaces.
"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 #9 on: 28 January 2003, 16:46 »
yeah, unfortunately, the "for name in *" command will separate the input list on newlines and spaces; unfortunately I have found no workaround for this limitation....  even setting $IFS to a newline doesn't do it.

And i think, stryker, that you have your names backwards; your commands find all mp3's and rename them to wav's (not sure how lame would react if it was given an mp3 as the imput and you told it to recode to mp3);  shouldn't it be:
Code: [Select]

or, this might be a little simpler and not have to call sed each time:
Code: [Select]
from Attrition.Org
 
quote:
Like many times before, Microsoft is re-inventing the wheel and opting for something other than round.

-t.


flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Converting multiple files to mp3
« Reply #10 on: 28 January 2003, 17:50 »
Actually a better solution again would be:

find -name "*.wav" | while read item; do oggenc "$item" -o "${item/.wav/}.ogg";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


voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Converting multiple files to mp3
« Reply #11 on: 28 January 2003, 19:12 »
How can anyone not like a thread like this.  
Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Converting multiple files to mp3
« Reply #12 on: 28 January 2003, 22:25 »
would this work?
I just modified a script i had for converting things to thingers.
Code: [Select]

[ January 28, 2003: Message edited by: The Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Converting multiple files to mp3
« Reply #13 on: 28 January 2003, 23:15 »
Try it.

No it won't, btw.

This bit

#replace spaces with underscores
for i in *.wav; do mv "$i" `echo $i | tr ' ' '_'`; done

won't work, for reasons stated above.
"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 #14 on: 29 January 2003, 00:23 »
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.

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

Someone please remove this account. Thanks...