Friday, December 26, 2008

Breaking Up MP3 Files

I have a small MP3 player that I take to the gym to keep me occupied while I'm working out. It's a hand little thing — except that it's little which means that the buttons are both few, and small.

In particular, the fast forward button is also the next track button — you press quickly to change tracks, and you hold it down to fast forward.

Which brings up a problem when you want to fast forward through a selection: if you are fast-forwarding and let up on the button ever so slightly, it skips to the next track. Which is a really bad thing when your tracks are two hour radio shows.

Yeah, it's bad design. But it's a lot cheaper than an iPod. So let's make do with the player we have, and note that CD players have this same problem with audio books. The audio book publishers have solved this by breaking up the selection, say a chapter, into smaller tracks, which take 3-4 minutes to read. If you need to scroll through a bunch of tracks, you can easily do so at 15-20 key presses per hour of audio.

There's a utility for doing this with MP3 tracks, called mp3splt, available via apt-get in Ubuntu, and presumably available for most Linux distributions, as well as Windows machines and Macs. It will break up an MP3 (or OGG) file into user specified segments. It's pretty flexible, in that you can specify the length of each segment, or break when the silence is longer than a predefined number of seconds, or into fixed-length segments, or, what I like best, into nearly fixed-length segments which are adjusted in length so that they begin and end during silent stretches.

It's a command line utility, and it works really well: except that it destroys about 90% of the ID3 tags, including all the ID3 version 2 information. I don't like that, as my MP3 player can be programmed to sort by title, album name, or performing artist, and I use this to determine the order I'll listen to programs such as Prairie Home Companion and Car Talk.

The canonical command line utility to label MP3 files is id3v2. I used this to write a rather small Perl script, splitmp3, which calls mp3splt to split an MP3 file into chunks which are each about five minutes long, preserving the ID3 labels of the original file, and including the appropriate track number. You can download the file from this link:

Let me know how it works for you, and feel free to add improvements.