Updated Feb 09, 2010: A newer version of the script has been released - for the update, please visit: http://techpatterns.com/forums/about1491.html
This whole thing came about when I decided it was time to pick up a new iRiver H140 portable media player. Once of the factors that led to the iRiver was it's support for the Ogg file format from the fine folks at Xiph.org. At the same time, I wanted to archive our CD collection in a losless format, like FLAC. So the solution seemed simple: Encode everything in FLAC using whatever combination of ripper/encoder, then do some batch conversion to compress and convert the files so that they could be loaded onto the iRiver. After a bit of searching, however, I didn't come across any tool that would do what I wanted:
- Handle the actual FLAC to Ogg conversion.
- Would do it on a large set of files.
- Would maintain the directory structure of the original FLAC file repository.
- Would be smart enough so that I could make incremental updates (encode a few more CDs into FLAC, run the script, and only have the new files converted).
- I wanted it to work on Windows so that my wife could run it from her laptop, where she would most often use the iRiver player.
- Update: I now have a linux version of this script, provided by Evan Boogs! See the link below
This is what you'll need:
Run the Cygwin Setup.exe application, walk through the wizard making sure you add the 'perl' and 'audio' packages to the list of things to install, and let it do the installation. My copy is installed at C:\cygwin, which is the default.
Unzip the vorbis-tools zip file. I unzipped mine into C:\Program Files\vorbis-tools.
I then added the path C:\Program Files\vorbis-tools\to my Windows System Path variable. See Start -> Settings -> Control Panel -> System -> Advanced -> Environment Variables.
There is also a version that will do the same but instead will output an MP3. This was contributed by another user and can be downlaoded: Download flac2ogg-linux.pl .
Next, open up a Cigwin Bash shell (Start -> Programs -> Cygwin -> Bash Shell), and make sure the perl script is executable:
> cd /usr/local/bin
> chmod a+x flac2ogg.pl
Assuming you already have a whole directory tree full of FLAC encoded files, here is how you use the script. We'll assume your FLAC files are located under C:\music\flac and that you want all of the Ogg versions to be created under C:\music\ogg. Type the following from a Bash shell prompt:
flac2ogg.pl --source=/cygdrive/c/music/flac --dest=/cygdrive/c/music/ogg
This will search through all files under C:\music\flac, find anything that ends in .flac, create the corresponding directory structure under C:\music\ogg, and covert the FLAC file into an Ogg file in that directory. All FLAC file-tag information will be retained, and the new file will have the same name except for the .ogg suffix.
So for example if your FLAC collection consisted of this:
C:\music\flac\Some Band\Some Album\Some Track.flac
You would end up with this:
C:\music\ogg\Some Band\Some Album\Some Track.ogg
By default, the script will use the 'quality level 6' quality level for the Ogg files, which usually ends up right around 192 average bit rate and is a good trade off between size and sound quality. The full set of options:
flac2ogg.pl --source=/source/dir --dest=/dest/dir --quality=n --force
--source= The path to the top-most directory containing your FLAC files.
--dest= The path to the directory where you want the Ogg files to go.
--quality=n where n is a number between 1 and 10, 10 being the best quailty.
--force Overwrite the Ogg file, even if it already exists
By default, the script will only convert a Flac file if (a) the Ogg version does not exist or (b) the FLAC file is newer than the Ogg file that already exists. You would use the '--force' option to override this behavior, re-converting all of your FLAC files. This would be used if you wanted to re-encode the entire collection at a different quality level, for example.
So far, the script seems to be fairly resilient to oddly named FLAC files (with odd characters in the file names), but YMMV.
Enjoy, have fun, and let me know if you run into problems.