Tag Archives: aac

Converting mp3 to ipod-ready audio books

DISCLAIMER: The below technique works about half of the time: For no readily discernible reason, some of the files come out in chipmunk mode. It appears, from what I’ve been able to determine so far, that mpg123 is playing the original mp3 file at the wrong speed.

—————–

As a fan of Librivox, it’s frustrating to me that the iPod doesn’t recognize audio books in mp3 format as audio books. It wants them in aac format. Converting them is a hassle, mostly because I always forget how. So, here’s a little Perl script I whipped up for the purpose.

The same thing is necessary if you rip an audiobook from CD.

Share and enjoy:

#!/usr/bin/perl

opendir F,".";
my @files = readdir(F);
closedir F;

foreach my $chapter (@files) {
    next unless $chapter =~ m/.mp3$/i;

    my $filename = $chapter;
    $filename =~ s/.mp3$//;
    $filename = $filename . '.m4b';

    `mpg123 -s "$chapter" | faac -b 80 -P -X -w -o "$filename" -`;
}

Note that while this retains the track name, it seems to lose the album name and author, so you may need to add that back. Presumably faac has command-line arguments for this, too, but I haven’t found them yet. Haven’t looked, either.