Get your FLAC on with MP3FS

259

Author: Nathan Willis

I don’t know if the folks at Xiph.org can live day-in and day-out using only the free Vorbis, FLAC, Speex, and Theora codecs, but the rest of us routinely run into consumer devices that don’t recognize and support them. But with a little help from Filesystem in Userspace (FUSE) and MP3FS, you cross one incompatibility off that list. MP3FS lets you mount a directory hierarchy of FLAC audio files and transparently present them as MP3s to software and hardware devices alike.

Yeah, you could just rip your CDs to MP3, then load them onto your iPod, phone, car PC, or Squeezebox. But MP3 is lossy; you have to sacrifice either disk space or audio quality. If you want to keep high-quality MP3s on your hard disk, they eat up too much space on your MP3 player. You could rip multiple copies at different bit rates, but that would be crazy.

On the other hand, if you rip your music to FLAC (both lossless and a free codec), MP3FS can fool all those lesser devices into thinking they are MP3s at whatever bit rate you decide — and all with just one copy of each file. MP3FS runs at the filesystem layer, advertising a virtual foo.mp3 file for each foo.flac file in the directory and transcoding the FLAC audio to MP3 on the fly whenever the file is read.

Getting started

The current release of MP3FS is a gzipped source tarball that depends on FUSE, libFLAC (for reading FLAC audio files), and LAME (for transcoding them on the fly). Unpack the tarball, run a ./configure, make, make install trifecta, and you are ready to go.

As with other FUSE filesystems, you need to make sure that FUSE is loaded before you can use MP3FS. Run modprobe fuse as root, or just add fuse to your /etc/modules file to have it load at boot time.

You mount a directory with MP3FS using the mp3fs command. The syntax is simple: mp3fs name_of_flac_directorybitratename_of_mount_point. The bitrate option is the MP3 bitrate (in kilobits per second) that MP3FS will dynamically transcode files into. At present, only fixed-bitrate encoding is supported. You can add standard FUSE options to the command by appending them to the end with the -o flag. The MP3FS documentation recommends allow_others, which lets all users (not just root) access the directory, and ro, which mounts the directory as read-only. MP3FS does not implement write access, but FUSE must be told so explicitly.

Thus, to mount the directory /home/nate/flac_music as 256Kbps MP3 files, first create a directory in which to mount the MP3s with a command like mkdir /home/nate/mp3_music, then, as root, type mp3fs /home/nate/flac_music 256 /home/nate/mp3_music -o allow_others,ro.

FLAC? FLAC who?

Now, as far as any application with access to that directory knows, it is filled with real, live MP3 files. I can copy files from mp3_music/ to a portable device using Nautilus, or play them in a music player. That’s the beauty of doing all this with a FUSE module — it works at the filesystem level; no application needs to know the truth.

Mounting mp3_music/ with MP3FS in this way causes it to auto-translate the FLAC files in every subdirectory as well. And in case you were wondering, no other file types are affected at all. If I have any .OGG files or real MP3s in the same directory hierarchy, they are accessible as-is through the mp3_music/ directory.

Since MP3FS also translates the FLAC files’ tags to ID3 tags on the fly, you can query any of the files in that directory as if they were MP3s. For example, id3v2 -l /home/nate/mp3_music/Dead_Letter_Office/All_The_Right_Friends.mp3 returns:


id3v2 tag info for /home/nate/mp3_music/Dead_Letter_Office/All_The_Right_Friends.mp3:

TSSE (Software/Hardware and settings used for encoding): LAME v3.96.1

TIT2 (Title/songname/content description): All The Right Friends

TPE1 (Lead performer(s)/Soloist(s)): R.E.M.

TALB (Album/Movie/Show title): Dead Letter Office

TRCK (Track number/Position in set): 22

You get all the benefits of keeping your music collection in simple, compatible MP3 files, but you can still access it (or back it up) in its true form through flac_music/.

The long and short

There are a few caveats. Although FUSE is perfectly stable, MP3FS is experimental software; don’t use it to run your air traffic control center by any means.

This is particularly important if you are interested in accessing your music collection through MP3FS full-time. I tested MP3FS against a number of Linux audio players, and several of them went flaky.

  • Rhythmbox failed to recognize the MP3s at all.
  • So did Muine, but Muine crashed and left a zombie Mono process running at 100% CPU usage as well.
  • Beep read the tags and track lengths correctly but failed to play them.
  • So did Juk.
  • Banshee played but constantly tried to save album art it retrieved automatically from the Web, even though the directory was read-only. This generated repetitive error dialogs.

On the bright side, Listen, XMMS, and amaroK all worked flawlessly.

The Banshee problem is clearly a bug in the player, but it illuminates a limitation in the current release of MP3FS as well. Right now, the module only converts album title, song title, artist, and track number tags. I can live without album art, but support for additional tags such as replay gain would be nice.

Similarly, MP3FS is limited to translating FLAC audio to MP3. I think the proof of concept is solid, though, and I hope additional input and output file types will be supported in future releases.

All in all, MP3FS is a terrific piece of work; it scratches an itch I think many of us feel. On my home network, all the PCs and laptops are capable of playing both Vorbis and FLAC audio, but that’s not so with the car MP3 player, the portables, and (regrettably) my music-loving friends. I don’t need MP3FS to listen to music around my house, but it sure helps whenever I have to take it out the front door.

Now, if you’ll excuse me, I’ve got some CDs to rip.