This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

Get your FLAC on with MP3FS

By Nathan Willis on October 05, 2006 (8:00:00 AM)

Share    Print    Comments   

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_directory bitrate name_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.

Share    Print    Comments   

Comments

on Get your FLAC on with MP3FS

Note: Comments are owned by the poster. We are not responsible for their content.

LAME - yeuch!

Posted by: Anonymous Coward on October 06, 2006 07:20 AM
Through much experimentation, I could not find any LAME settings (even 320kbps cbr) which did not completely ruin the sound of the music I was encoding, even when played back on relatively low quality playback equipment (eg, my crusty old laptop's sound output and a ~US$20 pair of closed headphones).

I seriously recommend integrating with <a href="http://bladeenc.mp3.no/" title="mp3.no">BladeEnc</a mp3.no>, it's faster and produces much better quality sound files. OGG is probably a little bit better, but if you need MP3, you need MP3.

#

Awesome idea!

Posted by: Anonymous Coward on October 06, 2006 08:05 PM
What a great idea. I'll use this when VBR support is added (CBR is sub-optimal for me). Perhaps user definable Lame arguments would be appropriate?

I haven't tried it yet, but I'm wondering how one would go utilising SMP systems, possibly copy the desired files in batches shared equally between all of the CPUs in the system.

#

LAME - not yeuch!

Posted by: Anonymous Coward on October 07, 2006 03:23 PM
Actually I would recomment exactly the opposit<nobr> <wbr></nobr>... and for exactly the same reason!

AFAICH BladeEnc seems to add artefacts to the mp3 that are quite audible, while I haven't been able to catch lame doing the same thing.

#

typo

Posted by: Anonymous Coward on October 06, 2006 08:38 PM
thanks for this article! Awsome!! finally i can get my FLACs on my IPod!!

one comment though: the mout option "-o allow_others" is "-o allow_other"

#

this software is

Posted by: Anonymous Coward on October 06, 2006 09:25 PM
illegal in the US and Europe due to patents on the mp3 format. Leave it to linux people to stoop to advertizing warez on "linux.com", a flagship website for the "free as in warez" crowd.

#

Re:this software is

Posted by: Anonymous Coward on October 06, 2006 11:37 PM
In the U.S. I can't sing the Happy Birthday song without paying someone royalties, how fucked up is that?

The U.S. is not the world, it's one country. Should all websites only write for U.S. viewers?

Some people continued to drink alcohol too when it was against the law.

#

Re:this software is

Posted by: Anonymous Coward on October 07, 2006 12:35 AM
The software is not illegal. The distribution of MP3 encoders in US and Europe is legal, if the distributor pays the royalties. And the article definitely doesn't contain anything illegal. How do you know that I got my copy of lame from unauthorized dealer? Or that I live in one of the silly countries that support such stupid laws?

#

Re:this software is

Posted by: Anonymous Coward on October 07, 2006 02:47 AM
There are no software patents in the EU. There may be some patents on methods used in the MP3 encoding, but they are illegally granted and simply not enforcible. It's absolutely legal to use and distribute mp3 en- and decoders in Europe.

#

Re:this software is

Posted by: Anonymous Coward on October 10, 2006 12:16 AM
Repeat after me: Legality is not morality.

#

Misleading lead-in

Posted by: Anonymous Coward on October 07, 2006 12:53 AM
I think this is an interesting approach for some situations, but your header advertises it as somehow 'creating compatability between flac and mp3 devices'. In truth this is no more useful than a script which transcodes while copying, for the case of mobile devices.

As for devices not supporting vorbis, the percentage is large and growing, and you don't have to break the law to encode to it.

-jrodman

#

Re:Misleading lead-in

Posted by: Nathan Willis on October 10, 2006 11:53 AM
I don't know where you got that quoted phrase, but it wasn't from the article.

In fact, MP3FS is far more useful than a transcoding-and-copying script.


  • It is automatic

  • It is transparent to the devices

  • It takes no preparation on the user's part

  • It uses zero disk space

  • It can be remounted at any bitrate

  • it can be used simultaneously by an unlimited number of devices and applications



And who said anything about breaking the law? MP3 encoder licenses are not difficult to get or expensive, for those who live in a place where the law requires them. In fact there are some companies who pay for license fees to distribute them free to Linux users.

#

Cool

Posted by: Anonymous Coward on October 07, 2006 08:10 AM
Wow!
Sounds really cool!
Very interesting concept!

#

id3

Posted by: Anonymous Coward on October 09, 2006 07:44 AM
The article mentions flac id3 -> mp3 id3, but what about the other way around? For instance I'd like to use itunes to edit the tags and it doesn't support flac. Similarly, itunes stores volume information in the id3 tag which is pretty useless if the data doesn't go back the other way.

Also, does this transparent transcoding support mp3? I have a large legacy collection of mp3s that I don't want to reencode...

Finally, what is its caching like?

ps: all acronyms written in lower case due to the lameness filter!

#

Re:id3

Posted by: Nathan Willis on October 10, 2006 11:59 AM
I asked David Collet (MP3FS's creator) about that issue (tag writing); unfortunately he wasn't able to get back to me by press time. In short, though, he said that he has considered implementing writablity, but he isn't convinced that it is worth the trouble.

For one thing, you have to make the tags writable, but not the data blocks (because the tags really exist in the FLAC files, while the MP3-encoded audio does not).

For another, FLAC uses Ogg-style tags, and they aren't always easy to map between ID3-style tags, particularly when different apps want to write them in different ways. He did express a willingness to look into adding more tags to the set exported.

And no, don't worry, MP3FS will not double-encode any MP3s. It transcodes FLAC and FLAC only; everything else passes through unaltered.

#

How to "unmount" those mp3 directories?

Posted by: Anonymous Coward on May 31, 2007 11:27 PM
Subject explains what is my problem. So what is the command for "unmount" or delete those<nobr> <wbr></nobr>.mp3 files created from<nobr> <wbr></nobr>.flac files?

#

Re: How to "unmount" those mp3 directories?

Posted by: Anonymous [ip: 71.62.178.67] on November 25, 2007 05:36 AM
fusermount -u /mp3dir

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya