Home » How To » How to create an iTunes/iPod compatible audiobook (MPEG4 m4b) on Linux using MP4Box and mp4v2 v1.9.1 – it can be done!

How to create an iTunes/iPod compatible audiobook (MPEG4 m4b) on Linux using MP4Box and mp4v2 v1.9.1 – it can be done!

I’ve been wracking my brains over this for the past few weeks and it finally struck me how to create an m4b audiobook with chapters that is compatible with your iPod, iTunes, VLC, etc.  It was very simple once I figured it out:

Step 1:

encode the mp3 files to “aac” (mpeg4) using your favorite converter (I use ffmpeg):

ffmpeg -i "track1.mp3" -y -vn -acodec libfaac -ab 128k -ar 44100 -threads 3 -f mp4 track1.aac

Step 2:

Create a chapters file so that MP4Box can understand it:

* Common syntax : CHAPTERX=h:m:s[:ms or .ms] on one line and CHAPTERXNAME=name on the other – the order is not important but chapter lines MUST be declared sequencially (same X value expected for 2 consecutive lines).

track1.chapters:

CHAPTER1=00:00:00.000
CHAPTER1NAME=Chapter 001
CHAPTER2=00:30:00.139
CHAPTER2NAME=Chapter 002
CHAPTER3=01:00:00.728
CHAPTER3NAME=Chapter 003
CHAPTER4=01:30:01.269
CHAPTER4NAME=Chapter 004
CHAPTER5=02:00:01.858
CHAPTER5NAME=Chapter 005
CHAPTER6=02:30:02.375
CHAPTER6NAME=Chapter 006
CHAPTER7=03:00:02.964
CHAPTER7NAME=Chapter 007
CHAPTER8=03:30:03.553
CHAPTER8NAME=Chapter 008
CHAPTER9=04:00:04.094
CHAPTER9NAME=Chapter 009
CHAPTER10=04:30:04.683
CHAPTER10NAME=Chapter 010
CHAPTER11=05:00:05.224
CHAPTER11NAME=Chapter 011
CHAPTER12=05:30:05.765
CHAPTER12NAME=Chapter 012
CHAPTER13=05:46:14.106
CHAPTER13NAME=Chapter 013
CHAPTER14=06:16:14.143
CHAPTER14NAME=Chapter 014
CHAPTER15=06:46:14.732
CHAPTER15NAME=Chapter 015
CHAPTER16=07:16:15.249
CHAPTER16NAME=Chapter 016
CHAPTER17=07:46:15.790
CHAPTER17NAME=Chapter 017
CHAPTER18=08:16:16.331
CHAPTER18NAME=Chapter 018
CHAPTER19=08:46:16.920
CHAPTER19NAME=Chapter 019
CHAPTER20=09:16:17.460
CHAPTER20NAME=Chapter 020
CHAPTER21=09:46:18.050
CHAPTER21NAME=Chapter 021
CHAPTER22=10:16:18.639
CHAPTER22NAME=Chapter 022

Step 3:

Add the chapters to the audio file (creates Nero format chapter markers):

MP4Box -add track1.aac -chap track1.chapters test.mp4

Step 4:

Convert the Nero chapter markers to Quicktime chapter markers using mp4chaps from the mp4v2 project (you will want v1.9.1 or higher):

mp4chaps --convert --chapter-qt test.mp4
converting chapters in file "test.mp4" from Nero to QuickTime

Step 5:

Rename the file from .mp4 to .m4b extension so iTunes will see it as an audiobook:

mv test.mp4 test.m4b

Proof that it works:

and VLC showing the chapters:

Of course, we aren’t putting in any tags such as “author” or “genre” in this example. Use your favorite tags editor to do so.

Share Button

Comments

  1. The time in the chapters file is the start of the chapter.

  2. gdgrte says:

    if you need a drm remover,you can find what you need here.
    http://www.dvdtoitunes.net/itunes-drm-remover.html

  3. Depending on which country you live, removing the DRM is likely illegal. Apple allows you to convert your music library to non DRM: Want to upgrade your iTunes DRM’d music (m4p,aac) to non-DRM legally? Check out iTunes 8

    Unfortunately, I don’t think that covers any DRM’d audiobooks.

    You can legally purchase non-DRM MP3 audio books: MP3 Audiobooks on Amazon

    Audio books on cd are quite inexpensive: Audio books on CDs especially if they’re used: Used audio books on cd

  4. Jason says:

    Thanks for sharing this! I’ve been getting fed up with having albums of audio books on my iPhone.

    I downloaded and installed mp4chaps (v1.9.1) using “./configure && make && sudo make install” and got the following error:

    mp4chaps: error while loading shared libraries: libmp4v2.so.1: cannot open shared object file: No such file or directory

    I solved it this way

    $ cd /usr/lib
    $ sudo ln -s /usr/local/lib/libmp4v2.so.1

  5. Benny says:

    Thanks for your explanation, but it doesn’t work for me.
    A few questions:
    Do you have your audio book in a single mp3 file (here: test.mp3)?
    If yes, where did you get the “track1.aac” file in step 3?

  6. step one should read:

    ffmpeg -i “track1.mp3” -y -vn -acodec libfaac -ab 128k -ar 44100 -threads 3 -f mp4 track1.aac

    thanks for catching that! 🙂

    Does that help?

  7. Benny says:

    It helps a bit, thanks. But I can’t get it working, though :).

    I can’t play the m4b file in totem (“no known streams found”), and in vlc shows a length of 459:38:02 (instead of 18:58) and no chapters (same on the iPod).

    Here’s the list of commands:
    http://pastebin.com/m1c36f075

  8. Benny says:

    Sorry, that should read “…and vlc shows…”

  9. Benny says:

    Aaaand sorry again. Found the mistake.
    My chapters file looked something like this:
    CHAPTER3=00:03:18.7002364274
    I changed it to
    CHAPTER3=00:03:18.700
    and everything works…not!
    VLC and iTunes show the chapters and play everything fine, but on the iPod the chapters don’t show up.
    I will try to use iTunes instead of Amarok to transfer the file (see: http://forums.jrlearnsmedia.com/forums/showthread.php?t=33).

  10. Benny says:

    Everything works now.
    Thanks to your post I created a python script and posted it here: http://ubuntuforums.org/showthread.php?t=1418085

  11. That’s wonderful Benny! Great work!!!!! 🙂

  12. PG says:

    Thanks for this useful blog.

    I just wanted to let you know that the free (as in beer but not as in speech) Nero encoder has an album mode which combines multiple input files into one output file and automatically adds chapter marks, so you don’t have to create a chapter file. You do still need to run mp4chaps to convert the chapter types though.

    The downside is it only takes wav files as input so you have to decode your MP3s first, but as a bonus it also comes with a tagger which can set album titles and also add cover art. I believe it is a much better quality encoder than faac too, but I’m no expert on that!

  13. PG says:

    I thought a sample workflow might be useful:

    – decode MP3s
    cd /home/music/directory
    for i in *.mp3; do lame –decode “$i” “`basename “$i” .mp3`”.wav; done

    – combine wavs into one mp4 file (repeat -if file.wav for each wav)
    neroAacEnc -cbr 64000 -if file1.wav -if file2.wav -of out.mp4

    – convert chapters
    mp4chaps –convert –chapter-qt out.mp4

    – add tags
    neroAacTag out.mp4 -meta:title=”book name” -meta:artist=”author” -add-cover:front:cover.jpg

    – rename to m4b
    mv out.mp4 finalBookName.m4b

  14. San says:

    i put some dirty but hopefully useful script on ubuntuforums for converting m4a files in directory without reencoding. want to try? http://ubuntuforums.org/showthread.php?p=10604092#post10604092

  15. Othniel Graichen says:

    I’m a Linux user with a iPod Classic but no iTunes. I download .m4b audiobooks which I can play fine on Ubuntu/friends. I can’t transfer them to the iPod and get them to play. I want to hear the AAC stream and see the PNG artwork which changes periodically.

    I use gtkpod to transfer TO the iPod, but the m4b audiobooks dont show up in Audiobooks on the iPod interface.

    What am I doing wrong?

  16. Smithb857 says:

    what are some really good and popular websites for blogging? ?? . dgebaedcee

    1. wordpress.com is one of the best.

  17. John says:

    Great tutorial! Thanks! One question: What if I have separate aac files that DID already correspond to natural chapter breaks. What would be a CLI way to concatenate those files into a m4b file with chapters corresponding to the files? I know that m4baker does this, but I’d like to control it manually on the command line.

    1. I believe you’re talking about creating a single monolithic m4b file with chapters.

      In step 2, you could write a script that would add the length of the previous file(s) to the chapter times. Step 3 would include appending all the audio files together in sequence and then using mp4box to add the chapters to the monolithic m4b file.

      The other steps should remain the same.

  18. Ajar says:

    Is there a way to add an image to each chapter

  19. Ajar says:

    Is there a way to add an image to a chapter?

    1. Atomic Parsley may be able to. I don’t own an iPod to test it.

Leave a Reply

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

*
*

Facebook login by WP-FB-AutoConnect