Sorry, you need to enable JavaScript to visit this website.

Linux Audio Conversion with Ruby - Walkthrough

Homer's picture

If you've reached the stage where your digital music collection is out of control; with a multitude of different file formats, bitrates and naming conventions; then wouldn't it be great if you could get some help sorting that mess out?

On the Windows platform there are a multitude of applications that can deal with the problem, such as dbPowerAMP to name one of the better ones, but under Linux the solution is not so clear.

Now, thanks to a Ruby application called sneetchalizer (yes really!) there is a powerful automated solution to audio file format conversion, which can convert between OGG Vorbis, MP3, AAC/MP4 (or M4A as Apple calls it), WMA and others, whilst preserving the metadata tags which describe the audio file contents (known as IDv3 tags on MP3 files).

Note: depending on the source of your audio files, some of them may be encrypted with a DRM key. In order to convert such files, you will first need to remove the DRM - Dreaded Restrictions for Music ;) - with applications such as QTFairUse6, FairUse4WM, or with workarounds such as loopback recording, using programs like tunebite, (a method which now also works on DRM protected videos ... yay!).

Now I'm not going to bore you with the full background to Ruby and the other concepts in this topic, partly because I'm sure you'll easily be able to research it yourself, but also because I've only just discovered Ruby, so I'm no expert. However, within just a few minutes of learning about this amazing tool, I had it running like a thing possessed through my music collection, and now ... you can too.

For the purpose of this Walkthrough, I'm assuming the distro is Fedora 8, but the principles are not entirely alien to other distros, so I'm sure you'll figure it out.

You'll need to be root to install these packages.

]# su -

First, get Ruby:

]# yum install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc

Next, get RubyGems, the Ruby standard for publishing and managing third party libraries, which is sort of like the equivalent of CPAN (Comprehensive Perl Archive Network). Think Yum or Apt for Ruby.

]# yum install rubygems

Now get wmainfo-rb, a library for reading low level information from files encapsulated in an Advanced Systems Format header (ASF/WMA). Also get flacinfo-rb for FLAC metadata, ruby-ogginfo for OGG metadata, MP4Info for MP4 metadata, ruby-mp3info for MP3 metadata, and apetag for Monkey Audio metadata.

~]# gem install wmainfo-rb --include-dependencies
~]# gem install ruby-mp3info --include-dependencies
~]# gem install flacinfo-rb --include-dependencies
~]# gem install MP4Info --include-dependencies
~]# gem install ruby-ogginfo --include-dependencies
~]# gem install apetag --include-dependencies

Make sure that you've got all the necessary tools and libraries to do the actual audio conversion:

]# su -
]# rpm -ivh http://rpm.livna.org/livna-release-8.rpm
]# yum install flac faac faad2 vorbis-tools lame mplayer

And finally, the all important conversion script, written in Ruby:

]# wget http://badcomputer.org/unix/code/sneetchalizer/src/sneetchalizer-0.9.0.t...
]# tar xzf sneetchalizer-0.9.0.tar.gz
]# cd sneetchalizer-0.9.0
]# ruby install.rb
]# exit

That's it!

Now you can start converting audio files.

Example:

]# ls
song1.wma song4.mp3 song7.m4a
song2.wma song5.mp3 song8.m4a
song3.wma song6.mp3 song9.m4a
stuff.doc
]# sneetchalizer --in=wma,mp3,m4a --out=ogg -q6 .

(Observe ... the trailing dot "." above)

This will convert all WMA, MP3 and M4A files in the current directory to OGG, keep the originals, and preserve the metadata.

There are many other options, and in conjunction with find, perl, sed, tr, awk, and so on can be a very powerful tool for reorganising your music files.

Try this Perl batch renaming script:

http://www.evolt.org/node/351

Also, see:

]# man sneetchalizer

For those feeling extra adventurous, I recommend the aoTuV optimised version of oggenc (static gcc 4 compile) with impulse_trigger_profile, available here:

http://www.rarewares.org/quantumknot/oggenc-aotuv451.gz

Have fun!

Bibliography:

http://mediakey.dk/~cc/howto-install-ruby-on-rails-on-fedora-core-5-fc5/
http://www.hydrogenaudio.org/forums/index.php?act=ST&f=8&t=15049
http://www.unixgods.org/~tilo/Ruby/ID3/docs/index.html
http://badcomputer.org/unix/code/sneetchalizer/
http://www.geocities.jp/aoyoume/aotuv/
http://www.ruby-lang.org
http://rubyforge.org