Web Projects Consulting

How To Create an M4B Audiobook with Chapters from a Directory of MP3 Files to Play on IPOD

This is the fastest way to create an ipod-playable m4b file. The “drawback” is that the codec is proprietary but this is how you’d put it, it is free and the most efficient in quality and encoding.

Download the latest Nero Aac MPEG4 Encoder/Decoder binary from here. Unpack, copy neroAacDecneroAacEnc and neroAacTag to ~/bin.

mkdir -p ~/bin
mkdir neroaac
mv NeroDigitalAudio.zip neroaac/
unzip neroaac/NeroDigitalAudio.zip
mv neroaac/linux/* ~/bin/
rm -rf neroaac

audiobook, mp4, ipod, m4b, mpeg 4, neroAacEnc, ffmpeg, faac, chapters, mp3
Make sure ffmpeg is available:

sudo yum -y install ffmpeg

Now create the script you will use in your directory with mp3 files:

leafpad ~/bin/make_ipod_audiobook

The steps are explained below.

Create some useful variables and directories. This will contain temporary files:

SESS_DIR=/tmp/session_DIR_$$
mkdir -p "$SESS_DIR"

Output directory and file:

OUTDIR=pwd
OUTFILE="$OUTDIR"/"$3".m4b

ffmpeg recode to wav and simultaneously create command for neroAacEnc:

COMMAND=""
for F in *.[Mm][Pp]3
  do
    ffmpeg -i "$F" "$SESS_DIR/${F%.*}".wav
    COMMAND="$COMMAND-if ${F%.*}.wav "
  done

Run neroAacEnc with all prepared parameters:

cd "$SESS_DIR"
neroAacEnc $COMMAND-of tmp.m4a

Set tags:

mv tmp.m4a tmp.mp4
neroAacTag tmp.mp4 -meta:genre="Audiobook" -meta:artist="$1" -meta:album="$2" -meta:title="$3"

Finally, everything within a ready-made script:

#!/bin/bash

[ "$#" -lt 1 ] && exec echo -e "usage: $0 [author] [series] [book name]"

SESS_DIR=/tmp/session_DIR_$$
mkdir -p "$SESS_DIR"
OUTDIR=pwd
OUTFILE="$OUTDIR"/"$3".m4b

COMMAND=""
for F in *.[Mm][Pp]3
  do
    ffmpeg -i "$F" "$SESS_DIR/${F%.*}".wav
    COMMAND="$COMMAND-if ${F%.*}.wav "
  done

cd "$SESS_DIR"
neroAacEnc $COMMAND-of tmp.m4a
neroAacTag tmp.m4a -meta:genre="Audiobook" -meta:artist="$1" -meta:album="$2" -meta:title="$3"
mv tmp.m4a  "$OUTFILE"
cd "$OUTDIR"
rm -rf "$SESS_DIR"

After you save the script and make it executable, you can run:

cd DIR_WITH_LOTS_OF_MP3_FILES
make_ipod_audiobook "Author" "Series" "Title"

The output file, $OUTFILE, will also have chapters set up automatically be the encoder. The quality is better than for those made with faac, and file size is normally 1/4 less too.

Enjoy!

3 thoughts on “How To Create an M4B Audiobook with Chapters from a Directory of MP3 Files to Play on IPOD

  1. Klaus

    Time for bash bashing 😉
    Don’t create temp dirs like that – use mktemp for that, it’s part of the coreutils package.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.