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.

The code:

String InputFile = args[0];
String Bitrate;
try{
Bitrate = args[1];
} catch{
Bitrate = "96";
}
String InputFileTrimmed = System.IO.Path.GetFileNameWithoutExtension(InputFile);
String InputDir = System.IO.Path.GetDirectoryName(InputFile);
Console.WriteLine(InputDir);
String TempFile = InputDir+"\\"+InputFileTrimmed+".m4a";
String OutputFile = InputDir+"\\"+InputFileTrimmed+".m4b";
String Arguments = "-i \""+InputFile+"\" -acodec libfaac -ab "+Bitrate+"k \""+TempFile+"\"";
Process pr = new Process();
pr.StartInfo.FileName = "c:\\software\\ffmpeg\\ffmpeg.exe";
pr.StartInfo.Arguments = Arguments;
pr.StartInfo.RedirectStandardOutput = true;
pr.StartInfo.UseShellExecute = false;
pr.Start();
pr.WaitForExit();
string output = pr.StandardOutput.ReadToEnd();
Console.WriteLine(output);
File.Move(InputDir + "\\" + InputFileTrimmed + ".m4a", OutputFile);

 

Comments on this post

Feedback is always welcome. Read some from other folks or leave your own below. Just keep things civil and remember that what you post lives on in public. Forever.

Thanks,
J

12 Responses to “Converting MP3 Into iPod M4B Audiobook Format”

  1. Paul Says:

    Even though I use a Mac, I don't totally rely on iTunes to manage my podcast listing habits. I use a smart playlist to keep track of which podcasts I have not listened to all the way through. By simply checking the play count for 0 and podcast = TRUE ( or in your case Genere = Podcast ) I am able to always have a playlist that is ready for listening.

  2. J Wynia Says:

    I've had poor experiences trying to get smart playlists and podcasts to work. I'll take another look at them to see if a better overall automatic workflow might be easier than I thought.

  3. david2tm Says:

    the whole point of m4b is chapters
    can you point how to add chapters functionality

  4. J Wynia Says:

    First, David, the whole point *to you* in m4b is chapters. I never use them.

    Beyond that, I've never looked at how to add them. The iPod recognizes any MPEG4 audio file named .m4b as a basic audiobook and that was all I needed.

  5. ken gray Says:

    You could try using this to get chapters…i'm not sure though.

    MP3 to iPod Audio Book Converter

    http://www.freeipodsoftware.com./index.php

  6. david2tm Says:

    thanks for advice
    but this program have no support for chapters

  7. Melzetta Smith Says:

    Is there a way to get power point slide show (pps) to convert to podcast file.

  8. J Wynia Says:

    @Melzetta, I don't know of any free solution that would do that. There are a couple of commercial solutions that will turn a Powerpoint file into video. Once it's in that form, making it a podcast is fairly straightforward, but you have to convert the Powerpoint to video in the first place.

    The other alternative would be to export all of the slides to JPG files and use something like Windows Movie Maker to string them together into a video file. However, that would export a WMV, which itself would need to be converted to MP4 if you wanted it to work on iPods.

  9. lilianne Says:

    hi
    i am not a t echie by any stretch kinda ignorant here
    my ex bought my youg son an ipod nano for christmas i am on limited budget so cannot afford songs i was told that u can download in mop3 format and change to ippod format bbut i have no clue how to do this can anyone tell me how i can do this

  10. Chris Albertson Says:

    For all of you who want to add chapters to audio books and podcasts checkout Apple's free software called "chapter tool". You give it an MP4 file and an XML file that describes the chapters and any artwork and chaptertool builds the chapterized audiobook. So now I have one huge 360MB M4B file that contains the entire book and I can find chapters and the book mark thing works. There is no need for file format converters, C# code or ffmpeg. Google will find "chapertool" for you. It is some place in the apple.com site

  11. Chris Albertson Says:

    lilianne, Are you still trying to figure this out? iTunes software makes this dead easy. First off there is no special "iPod format". The iPod will be happy to play MP3 files without first converting them. You first import the music into the iTunes library from files that you get some place or from CDs. Once they are in the library they will automatically load into an iPod when the iPod is connected

  12. Chris Albertson Says:

    Melzetta Smith, Is there a way to convert PP slides to podcast? Yes I think Aple's "Keynote" will do this directly. It can read the MS PP file format and then save-as to various formats. It is very easy. when you click file-export one of the options is a little picture of an iPod. Keynote is part of Apple's iWork office suite. Not free it is about $85.

Leave Your Own Comment

By submitting a comment, you agree to license it under the terms of the Creative Commons Attribution license.

© 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.