Converting MP3 Into iPod M4B Audiobook Format

Jan
08
2008

Back a couple of weeks before Christmas, an unfortunate series of events resulted in my 4GB iPod nano going through the washing machine. And, as is the case with many such incidents, it rendered the device entirely non-functional.

I bit the bullet and picked up a replacement because it's fairly critical to my mental well-being. I need to be able to throw on a bit of music or a podcast when I'm driving or need to drown out the outside world. So, I ordered a new 4GB nano video.

Then, a couple of days after getting that nano and using it, the consulting company that I'm subcontracting through gave all of the consultants on my project a 30GB Zune.

That, of course, caused a quick re-org of my portable media strategy. I ended up making the nano a purely podcast and audiobook device and moved all of my music (and hopefully some video when I get it cooperating) to the Zune.

Unfortunately, revisiting nearly any process in one's life can quickly shine a light on previously ignored problems and make you re-question your solution. Such was the case with my podcasting listening. When I switched over to the nano, I missed the ability to listen at faster-than-normal speeds for spoken word podcasts. However, the other benefits outweighed that downside, so I moved on.

However, last night, I wondered if I couldn't just convert some of those podcasts into iPod audiobooks (the ones with .m4b as the extension). Several of the podcasts already distribute in that format and you get things like bookmarking of where you were in the audio as well as the ability to speed things up.

I'll leave it as an exercise for the reader to guess what I think about a device that allows only the speeding up of a specific class of audio files to the exclusion of other classes of audio files.

Regardless, I checked if the Swiss Army knife of audio/video: ffmpeg would be able to handle it and was happy to see it would. So, I wrote a really simple C# console app to convert these .mp3 files into .m4b files. The workflow is still a bit lacking as it doesn't easily tie in to the iPod/iTunes functionality of putting "the 1 latest unplayed" podcast from each feed on the device, but I can quit hoping that the people speaking would just hurry the hell up.

There were a couple of oddities that needed to be coded around. Most noteable is the proper quoting of file paths (which still might not work in all cases) and the fact that you need to actually convert from MP3 to M4A and then rename that M4A to M4B in order to be done.

At any rate, the code is below the fold if you would like to mess with it yourself. You call it by running

MP3toMB.exe input.mp3 128

It also works if you just drag an MP3 onto the exe by assuming a 96kbps bitrate. Obviously, this is coded for Windows, but the same principle could easily be accomplished on Mac with Applescript or Linux with shell scripting or just batch files on Windows given a commandline copy of ffmpeg.

I've also got a Windows app that combines lots of MP3's into a single audiobook file, but I wanted something that I could use to automate and run on a more nightly basis to convert stuff, which this gives me.
Read the rest of this entry »

New EP From Mat D and the Profane Saints: Brand New Faith

Jun
13
2007

About a year ago, I mentioned the band that a friend of mine from junior high and high school is fronting. At the time of that writing, they had an EP out that was a diamond in the rough. It was enjoyable and I looked forward to them refining their craft and seeing where things would go.

Well, I just listened through the new one that came in the mail today and I have to say that Mat and crew have taken that rough chunk of coal, cut and polished it and the resulting EP: Brand New Faith is a much more mature release in nearly every way a collection of music can be.

The song structures are more complex and Mat, while still doing some of that cruising-along-monotone that appropriately drives the song "This Truck Makes More $$$ After Midnight", he is also exploring much more of his tonal and dynamic range on "Bound for Glory".

The EP and the music overall are in that Americana/Roots Rock/Alt Country/Grit/Honky Tonk/Blues Rock/Whatever genre that has been growing over the last few years. The themes tap into some of that same mythology and themes that something like HBO's Carnivale explores. Many of the bits are familiar, including the vocabulary of faith, but with that gritty twist that makes it interesting.

Here's the band's own description of the album:

Voodoo curses, Doomsday Preachers and Truck Stop Transsexuals cross paths. A killer travels down highway 61 only to put his faith in a statue of Jesus while searching for the next 'good time.' A pin-up queen gives her soul to God and breaks the devil’s heart. An outlaw trucker rolls down the back roads of lost love and sin, pulled between the powers of heaven and hell. When you find the Ghosts of Redemption and the long lost lover known as Damnation rolled up like a cowboy's cigarette on the wrong side of the tracks…you’ve found a Brand New Faith.

Overall, it reminds me of bits of Ray Wylie Hubbard and The Legendary Shack Shakers, but unique in its own way. That's a good thing.

If you want to give it a preview, you can hear all of the songs on the band's page. And, if you like what you hear or just want to support independent music from the Midwest, you can pick up the album from CDBaby.

Easy Downloading of CDBaby Sample MP3's

Apr
29
2007

A couple of days ago, Garrick asked a good question that I've wondered about myself: where can you find downloadable music from the upper midwest? I like finding new music and always get an extra bit of warm fuzzy when the artist is from Minnesota or nearby.

While the question raised some ideas about future projects, I did suggest CD Baby's state-specific listings: Minnesota, Iowa, Wisconsin, South Dakota, etc. While the interface that they provide isn't great, it does underscore just how much great music is out there from EVERY area of the world.

CD Baby is a great idea. Make a place for artists to sell their CD's without having to go through labels. Many of the discs are way cheaper than the $15-18 in most stores and I've bought a couple for well under the $10 that iTunes charges as well. Of course, since pretty much anyone can sell a CD there, pretty much anyone *does*, which makes the preview tracks a good idea (and just plain a good source of MP3's).

The tracks are all individual or by M3U playlist for streaming. The problem is that my searching for music is pretty much completely separated from my evaluation of it. I tend to find a list of artists/albums/tracks I might like, download them and listen to them later. I pretty much NEVER listen to the potentially interesting music when I find it.

All of that meant that to get the most out of the CD Baby sample tracks, I wanted a quick way to queue up the downloading of the tracks on a playlist. First, note that the playlist URL for an album changes (daily it looks like), so this is pretty much about downloading in the background while you're browsing the catalog, not trying to spider their entire site. What I am doing works today, but could always change.

At any rate, with a command prompt open (Linux, Windows or Mac doesn't matter) and a copy of wget on your system path, you can make quick work of grabbing the contents of a playlist.

See, an M3U playlist is pretty simple, coming down to pretty much a text file of URL's to MP3 files. That just happens to be the exact thing wget is made to handle. So, the general "workflow" works like this:

  1. Find an album you like.
  2. Right click on the "Play All Songs" link above the track list and copy the link address.
  3. Go to the command prompt and type "wget" followed by a space and then the URL. On Linux, it can be pasted by CTRL+SHIFT+V. Hit ENTER.
  4. Note the filename of the M3U that it downloads.
  5. Run "wget -i playlistname.m3u" and let it run.

It will then download them all one at a time. It all works fairly well. I've got them all downloading to a specific directory called, simply enough "cdbaby". I'm keeping them all under there so that I know where to go to buy the albums I like. However, I do want them organized by artist and album. It's just how I roll.

Fortunately, I wrote code to move and rename MP3's by ID3 tag a while back. Add the folder to iTunes and make another smart playlist and I can evaluate more music easily. And, with as much as I've been working the last couple of weeks, more music is a really good thing.

Renaming MP3 Files According to ID3 Tags with C#

Apr
11
2007

I added a new podcast to my roster this week: Americana Roots, which plays roots rock/Americana music. While I *don't* like the kind of country found on your local country station, I *do* like quite a bit of the music in this Americana/Cowpunk/Alt-Country genre. I'm not sure exactly what it is about that modern Nashville sound, but I'd rather sit in silence than listen to either that or pretty much any form of hip-hop that I've ever come across. But, I figure since that's really the *only* stuff I am not willing to listen to, I'm not exactly being overly narrow in my taste. Anyway, I figured that a podcast like this might introduce me to some music I wouldn't hear otherwise, just like my ongoing SXSW playlist experiment.

Sure enough, on the first episode I listened to, there was a song by a group called The Ryan Bales Band that I really liked. Since the band's store was showing a "Coming soon" link, I did a quick search elsewhere for it and found it for sale as a non-DRM'ed MP3 download. So I bought it from a site called Lone Star Tunes and downloaded it. (See, podcasting works as a promotional tool, people.)

Unfortunately, rather than a neat and tidy ZIP file, it came as an EXE that dumped the files into a directory, with such catchy names as: 3679LSM1.mp3 and 3679LSM2.mp3. Since there was also no directory for Artist or Album, I basically just had 11 MP3 files in a directory, without any way to tell what they were directly. Hoping not to have to both rename them *and* put in the meta-data, I took a peek at the ID3 tags: they were correct.

That got me thinking. This isn't the first time I've had a bunch of MP3 files in a directory that I wanted to sort out into an "Artist/Album/Track - Title" kind of structure. Curious how easy it might be to put together a little console application to do this kind of cleanup, I went searching for how to get info from ID3 tags via C#. (That's what happens when you leave a geek at home alone on a Thursday night.)

Within a few minutes, I had an appropriate class from CodeProject that looked like it might fit the bill. I just took the ID3 class (though I might go back and mess with the rest later) and added that project to a new console app solution in Visual Studio.

For the console app itself, I coded up something that loops through all of the files in the specified directory, looking for those ending in ".mp3". On those, it reads the ID3 tags and creates the directory path for artist and album and then tries to move and rename the MP3 into that directory. Any that fail (for whatever reason) are left in the original directory. I made this move them rather than copy them because most of the time, that's exactly what I want. Fortunately, if you'd prefer that it copy instead, it's pretty much changing the word "Move" to "Copy" in the code.

To run it, I just run "ID3RenameMp3.exe f:\music\unsorted" and it takes care of the rest.

The ID3 part pretty much comes down to knowing the field names for what you're after. They're things like "TALB" for album name. There's a list of them in the CodeProject class, in the FrameInfo.cs file if you want something other than the ones I used.

There are some unused variables you'll notice. Those are from some bits I had in place for checking if you're already inside the appropriate album or artist directory.

The Code

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ID3;

namespace ID3RenameMp3
{

class Program
{
static void Main(string[] args)
{

ID3Info FileID3Info;
String Title;
String Album;
String Artist;
String TrackNumber;
String SongFullPath;
String ParentPath;
String ParentName;
FileInfo songInfo;
String NewSongPath;
String FolderPath;

try
{
FolderPath = args[0];
}

catch (Exception e)
{
FolderPath =
".";

}

string[] songs = Directory.GetFiles(FolderPath);

foreach (string song in songs)
{

songInfo = new FileInfo(song);
SongFullPath = songInfo.FullName;
NewSongPath = FolderPath;

bool IsMp3 = song.EndsWith(".mp3");
if (IsMp3)
{
FileID3Info =
new ID3Info(SongFullPath, true);
Title = FileID3Info.ID3v2Info.GetTextFrame(
"TIT2");
Artist = FileID3Info.ID3v2Info.GetTextFrame(
"TPE1");
Album = FileID3Info.ID3v2Info.GetTextFrame(
"TALB");
TrackNumber = FileID3Info.ID3v2Info.GetTextFrame(
"TRCK");
ParentPath = songInfo.Directory.ToString();
ParentName = songInfo.Directory.Name.ToString();

NewSongPath = NewSongPath + "\\" + Artist;
NewSongPath = NewSongPath + "\\" + Album;

try
{
Directory.CreateDirectory(NewSongPath);
File.Move(song, NewSongPath + "\\" + TrackNumber + " - " + Title + ".mp3");
System.
Console.WriteLine("File moved and renamed to: " + Title + ".mp3");
}

catch (Exception e)
{
System.
Console.WriteLine(e.Message);
}

}
}
}

}
}

Ways to Extend

  • Instead of moving the files, if you had it copy them, you could use this to generate sorted directory trees of your MP3's according to nearly any criteria. You could copy them to Genre directories, Year directories, directories grouped by beats per minute, etc. This is really only limited by how good your metadata is.
  • Create smartlists without iTunes or iPods. This would actually copy the files, but if you specified an output directory different from where the files were, you could create a specific directory to sync with your MP3 player and fill it with files that match the criteria. This would also be helpful for those who use a CD-RW to listen to music in the car (like my car is now, with a broken aux input). You could have this clean out your "CarCD" directory, grab an appropriate set of files and just re-burn that every day.
  • Add recursion. This should also have a specified output directory to avoid infinite loops, but would let you apply your rules to a complete collection of files.
  • Try it out on Mono/Linux. While I spend more time on the Linux side of the fence lately, I wanted to make my initial stab at this utility as simple as possible and that meant Windows. However, since the ID3 stuff can be compiled as an assembly and my code is pretty basic stuff, it should work on Linux via Mono as well. I'm probably going to do this as my next step.

Wrapup

Of course, like many projects of this type, with the basic utility working with just a little bit of coding and testing, I'll probably mostly just get down to using it. It already cleaned up the downloaded album and I'm going through the rest of my files for anything else needing to be cleaned up and then I'll just file it away for the next time I need it.

Smart Folders, Views, Attention Gestures and SXSW Music

Mar
30
2007

I've been an advocate for a while of moving away from a single structure to organize data. The typical folder heirarchy of a computer filesystem bugs me. It's the same with bookmarks, categories for nearly anything, etc.

Basically, any time I'm forced to put something in a limited number of places, I find myself wanting to put it in at least n + 1 places. That's why I like views, in whatever form they take.

On Thunderbird, they're actually called views. On the Mac, they're "smart folders". In iTunes, they're called "smart playlists". Regardless of name, I dig 'em.

What's helped them get moving is that we're finally starting to capture attention gestures better. The less recording of metadata that users have to do, the better the whole "view" thing works. A prime example is what I'm doing with iTunes this week.

This year, like last year, SXSW released a giant torrent of songs from the bands performing for the music side of the conference. And, like last year, Garrick is weeding through them to pick and share his favorites. I thought it might be interesting to do the same. It also offered an opportunity to mess with the iTunes smart playlist functionality that I've been dabbling with a bit lately.

I downloaded the torrent's 700+ songs and imported them into the iTunes library. I added a folder for the smart playlists for this and created the first one. I set it for all songs with "SXSW" in the album (all of the songs in the torrent are in the same "album"), that hadn't been listened to or skipped 1 or more times and made it random.

When I saw "skipped" in the available metadata, I was pretty happy. That's the kind of implicit, easy to capture gesture that has been ignored for a long time. First, I can just hit a button on my multimedia keyboard and skip the current song. It's the natural thing I'm going to do if I don't like it (to move on to the next song) and it means I wasn't willing to listen to it all the way through, even once.

That's entirely different from rating songs. I'm not very likely to take the time to rate a song as having one star if I am ready to bail on it 10-15 seconds into it. Rating a song requires bringing iTunes to the foreground, finding the song in the interface, and making a couple of mouse clicks. Given that listening to music on the computer is *always* a secondary activity, that's just not going to happen for songs I don't like.

All of that makes this first smart playlist a good way to get my first pass through the list. The next smart playlist is the songs that have been listened to at least once and never been skipped. After I've gone through the entire original list of songs, I'll move on to this playlist, which is, at the very least, the songs that didn't bug me. If any do, and I skip them, they drop out of the list.

Now, already, there are a few that I caught myself really digging and wanting to hear again. They rose above the background to be really likeable. In those cases, I *did* go and rate them. I tried to be really honest about the star scale and found myself only bothering to rate stuff that was at least 4-5 stars. That's telling.

There was recently a story about how useless Netflix ratings are because, say a fan of Jet Li's movies is going to rate Fearless and other movies highly, but is not likely to go into the romantic comedy section and rate those poorly. The net result is that *everything* is rated highly and the star system doesn't work. So far, this experiment indicates that if I use "skipping" as my "thumbs down", then the presence of a rating *at all* is the only really useful indicator of my "thumbs up".

Regardless, for the final playlist, I did make the criteria a rating of at least 3 stars, in case I do eventually rate something on the low end. That final list, listened to at least once, never skipped and highly rated, will be a list of favorites that I can easily share.

For the most part, it required no more thinking about building a list of favorites than just listening for the heck of it would. The majority of the process is handled by just capturing my implicit attention actions. The little bit of action I *am* taking is to just note down what's already being brought to the foreground of my mind by enjoying the song enough to consciously think about liking the song.

In iTunes, this kind of thing works really well, because much of the metadata comes from backend databases (like a 1980's playlist just reading the ID3 tags for release date) and much of the rest can come from just paying attention to your existing actions. At the operating system level, they're starting to pay attention as well.

If you're on Windows, you might be jealous of the Mac's smart folders. Well, things are finally getting going over there.

Windows Desktop Search brings rudimentary smart folders to Windows. You can save searches as links (not the same as being able to map folders, but a start). After doing a search, you drag the magnifying glass of the address bar to where you want the link and there you go.

You do have to tell Windows Desktop Search to index anything other than the "My Documents" tree, which may or may not matter to you. If you tell it to index everything (like I did), it will take a while, but once it's done, you finally have a quick search for the files, emails, appointments, etc. on your Windows computer.

And, if you're a bit geeky and looking for very specific kinds of searches, you might want to look at the search query reference document. It covers all of the nitty gritty like how to get all of the emails you sent for a given day, etc.

Every implementation I see that essentially puts your files and data into a big pile, letting you define views to pull out exactly what you want is a step in the right direction.

I *like* being able to search specifically through all of my PHP files as a subset of my files *and* being able to bring up PHP files by project. The fact that I could also bring up all of my PHP projects that use PEAR libraries or all of my C# code that uses the TortugaNET library without having to store things that way in folders is fantastic and, eventually, will be seen as the only sensible way to do things.

Is there some way to fast forward to that time and skip the crap we're stuck with now?

« Older Entries  

J Wynia

For better or worse, I'm the guy who runs things here. I'm a web consultant, software developer, writer and geek from Minneapolis, MN. This site is a fairly wide cross-section of the things I'm interested in and enjoy writing about.

Oh, and if you happen to be looking for hosting for your Subversion repositories or just web hosting in general, take a look at Dreamhost. It's what I use for Subversion and your signup helps me out.

Latest Microposts

Follow Microposts on Twitter | Subscribe to Microposts

My Attendance At the Gym

Feeds and Links


www.flickr.com
This is a Flickr badge showing public photos from J Wynia. Make your own badge here.

Search


Pages

Archives

Computers Blog Directory
© 2003-2008 J Wynia. All original content is licensed under the terms of the Creative Commons Attribution license unless otherwise noted. Content from other sources is licensed under its original terms.