Convert audio files recursively

A few months ago I mentioned a one-line command to convert audio files between formats, and after suffering a rather unsettling loss of my /home directory, I found myself re-converting all the same mp3 files back to ogg, which is what I prefer.

This time though, I wanted to avoid having to bounce between 10 or 12 directories, and just filter through the subdirectories looking for mp3 files, and convert those to ogg. The command as I posted it needed slight adjustments anyway, and after tweaking it a little bit and not getting the results I wanted, I fell back to the find command.

find can execute commands against the files it reports, which means a simple pair of instructions, instead of one particularly long one, is just as easy. From my “music” directory,

find . -iname "*mp3" -exec nice mplayer -ao pcm '{}' -ao pcm:file='{}'.wav \;

This plucks out the mp3s and feeds them through mplayer, which was the original idea. (You need both of those -ao flags, by the way. I’m not 100 percent sure why, though. …) Next is the conversion to ogg, which is the same idea.

find . -iname "*wav" -exec nice oggenc -q7 '{}' -o '{}'.ogg \;

In both commands, the double-curly-brackets represent the file name, while the trailing backslashed semicolon is the flag for find that tells it where to quit.

You’ll probably notice that I just concatenate the appropriate extension; if you’re clever you could substitute it altogether. I find this a little clearer for me, but that’s only because I use qmv, which is part of the renameutils suite, to recursively change the “.mp3.wav.ogg” string back to “.ogg”. If you want to go that route as well, this command

qmv -R * --format=destination-only

Gives you a simple list that you can search-and-replace through in a text editor, and qmv will move them to their proper names. After that, it’s two more small find commands for cleaning up:

find . -iname "*mp3" -delete
find . -iname "*wav" -delete

And you’re finished. ;)

About these ads

1 Response to “Convert audio files recursively”


  1. 1 RK 2010/01/18 at 11:13 PM

    You might already know it, but converting fram one lossy format to another lossy format (e.g. mp3 -> ogg) means a loss of audio quality!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,958,708 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: