...making Linux just a little more fun!

2-Cent Tips

2-cent tips: convert the collection of your mp3 files into ogg

Mulyadi Santosa [mulyadi.santosa at gmail.com]


Sat, 26 Jan 2008 21:54:43 +0700

First, why? Easy, because mp3 is patended format and ogg is open source format. So, to guarantee your peace of mind (like what Cattano said to Frank Lucas in "American Gangster" :) ), use ogg.

To do it, first I assume you have mpg123 (http://www.mpg123.de/) installed and the binary is located in searchable path (check your $PATH).

Your mp3 files probably contain spaces, so use this script:

#!/bin/bash
 
for b in *; do (  cd $b; for a in *; do mv -v "$a" $(echo $a | sed s/\
/\_/g); done ) ; done

The script assumes your working directory has subdirectories that holds the mp3 files (think of it as albums). Outer loop lists the directories and inner loop "cd" into them and rename the files inside so they don't contain spaces anymore.

Finally, the real piece of work:

#!/bin/bash
 
for b in *;
do ( cd $b;
     for a in *;
            do test=$(echo $a | cut -f1 -d\.).wav ;
            mpg123 -v -w $test "$a";
            oggenc  $test ;
            rm -fv $test ;  rm -fv "$a" ;
     done );
done

In short, the script loops over your collections. It uses mpg123 to convert your mp3s into wavs. Then, oggenc converts it as ogg. The wav is then deleted since we don't need it anymore. Why create wav 1st, you might ask? Well, i tried to pipe mpg123 directly to oggenc but somehow it didn't work (at least in my case), so that's my workaround.

regards,

Mulyadi.

[ Thread continues here (5 messages/8.94kB) ]


Talkback: Discuss this article with The Answer Gang

Copyright © 2008, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 149 of Linux Gazette, April 2008

Tux