LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-04-2008, 02:10 PM   #1
thepenguiniscool
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Rep: Reputation: 0
Convert WAV's two MP3s within subdirectories


Sorry this is going to be such a long question, and hello! and thanks!

I decided to rip all my cd's to wav quite some time ago and now need to convert to mp3's. CDs are filed in /me/home/wav/artist/album/*.wav. Ultimately what I want is an exact copy in mp3 format in /me/home/mp3/artist/album/*.mp3

I've thought of copying the entire "wav" directory and saving as "mp3", convert all wav's to mp3, then deleting all remaining "wav"s with: find ~/mp3 -name "*.wav" -exec rm '{}' \; but there's two problems:

1. the code I could come up with to convert all "wav's" only works at the album level so I have to change directory to every single album I have: for i in *.wav; do lame -h -b 192 "$i" "${i%.wav}.mp3"; so

-is there a way to convert all these wav's from the top level directory "mp3"

2. the other issue is space: copying 80 gb of wavs, then converting an extra 10 of mp3 I'm not sure I have room for.


My other thought (and favorite if possible), is to run one bit of code from the original ~/wav directory that would convert all wav's in that directory and subdirectory, copy to another location and save the file structure so I end up with /me/home/mp3/artist/album/*.mp3.

The closes I could come up with here was this:

a=$(find /home/me/wav -name "*.wav")
for i in $a
do
lame -h -b 192 "$i" "$/home/music/mp3/{i%.wav}.mp3"
done


but again the problem is two part:

1. The code didn't work
2. If it did, it wouldn't save the file structure. I think I'd end up with a million individual mp3's filed in the folder ~/mp3.

If that made sense to anyone, do you have any suggestions?
 
Old 09-04-2008, 02:40 PM   #2
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
#!/bin/bash -
# wav2mp3

FILES=`ls *.wav`

for i in $FILES; do
OUT=`echo $i | sed -e 's/.wav//'`
lame -h -b 96 $i $OUT.mp3
done








put the script in this directory, or a directory in your path. /me/home/wav/artist/album/


#!/bin/bash -
# wav2mp3

FILES=`ls *.wav`

for i in $FILES; do
OUT=`echo $i | sed -e 's/.wav//'`
lame -h -b 96 $i /me/home/mp3/artist/album/$OUT.mp3
done



The second script should output it in /me/home/mp3/artist/album/
It will only do the directory your're currently in or run the script in. You'll have to adjust it if you want recursive directories

test it on a test directory with a few wavs to see if it fits your needs

Last edited by ncsuapex; 09-04-2008 at 03:09 PM. Reason: try that
 
Old 09-04-2008, 03:34 PM   #3
thepenguiniscool
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks! definatley useful but leads me to two other questions, can I copy the all the folders (and folders only) in the entire subdirectory for ~/wav, and paste in ~/mp3, so i don't have to create the folders in ~/mp3 by hand.

Also, it only converted one word song titles that had no spaces in them. Is there a way around that.

I guess I still have to do this album by album? which is fine I guess, just want to make that clear so I can quit wondering.
 
Old 09-04-2008, 04:30 PM   #4
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
you can probably change this line:

FILES=`ls *.wav`


to

FILES=`ls -R *.wav`

-R is recursive


starting at /me/home/wav and that should convert all the wavs under me/home/wav to mp3 recursively but im not sure what that would do with the output.. It would probably lump them all in /me/home/mp3/artist/album/

Im sure someone with more programming experience could tell you how to use a variable to put them in their album directory under /me/home/mp3/


There is a way to copy all the files/folder from ~/wav to ~/mp3 keeping them aligned as they were but it would copy all the wavs as well.. But I'm sure if you researched the "cp" command you might could find a way to copy directories only without files.
 
Old 09-04-2008, 04:49 PM   #5
thepenguiniscool
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Original Poster
Rep: Reputation: 0
adding the -R resulted in ls: cannot access *.wav: No such file or directory.

But thanks again for the suggestions, you've definatley given me more avenues to explore. I'll post back any developments.
 
Old 09-04-2008, 05:08 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Use find, ls is odd.

I can't understand why would you use find in your first post to rm files and not to lame them.

Code:
find ~/mp3 -name '*.wav' | while read i; do echo lame -h -b 192 "$i" "$/home/music/mp3/{i%.wav}.mp3"; done
Not tested. If all is fine, remove echo to do the work.

You could use -exec '{}' as well, but then you can't use bash string mangling to substitute the extensions (that would be easy to do on a separate command though).
 
Old 09-04-2008, 05:50 PM   #7
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
Quote:
adding the -R resulted in ls: cannot access *.wav: No such file or directory.
what directory did you run that script in?
 
Old 09-04-2008, 06:39 PM   #8
thepenguiniscool
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Original Poster
Rep: Reputation: 0
in the ~/wav directory, where I have no music directly. The actual files are all in the subdirectories ~wav/album/artist


I'll try you're suggestion i92guboj when I'm on the right computer and let you know how that turns out. BTW just so you know my skill level - when I said this "The closes I could come up with here was this: [insert script]." in the first post, i really meant "the closest thing google could come up with for me is this: [insert script]" I haven't the slightest what most of the finer points of these script syntaxes are doing. In all honesty I won't know how to take advantage of this suggestion:

"You could use -exec '{}' as well, but then you can't use bash string mangling to substitute the extensions (that would be easy to do on a separate command though).

Last edited by thepenguiniscool; 09-04-2008 at 06:41 PM. Reason: clarify response to ncsuapex
 
Old 09-04-2008, 06:50 PM   #9
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
Quote:
in the ~/wav directory, where I have no music directly. The actual files are all in the subdirectories ~wav/album/artist

are you wavs *.wav or *.WAV?

case matters...
 
Old 09-04-2008, 06:53 PM   #10
thepenguiniscool
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Original Poster
Rep: Reputation: 0
They are *.wav
 
Old 09-06-2008, 05:03 PM   #11
thepenguiniscool
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Rather than copying and pasting the whole directory I'm doing it in like in 3 or 4 pieces. Copying the first 20 or so bands and albums, folders and all. CD'ing to that new folder, running:

find ~/music -name '*.wav' | while read i; do lame -h -b 192 "$i" "${i%.wav}.mp3"; done

to convert all to mp3, then deleting all the wav's with: find ~/music -name "*.wav" -exec rm '{}' \;

This seems to be working just fine. THanks everyone.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
command to convert mp3s to lower bitrates? bgryderclock Linux - Software 4 10-07-2006 06:25 PM
Convert encoding through subdirectories? dl7und Linux - Software 2 04-16-2006 02:06 AM
Need to convert MP3s to OGG Vorbis files crash_override_me Linux - Software 3 09-24-2005 01:13 PM
Decoding of mp3s to wav's distorts sound php Linux - General 2 12-28-2003 02:20 PM
rippers, mp3s and mp3s.... (?) bxb32001 Linux - General 0 07-14-2001 01:53 PM


All times are GMT -5. The time now is 09:09 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration