Notes on editing chapters of a M4B

I have an audiobook, but I wasn’t satisfied with the chapters. They were just numbers, and didn’t match with the chapters in the ebook.

This was the result.

First, use ffprobe to confirm the m4a file has chapters. We don’t want to figure out the timestamps ourselves.

ffprobe Morgan_Housel_-_The_Psychology_of_Money.m4a 
ffprobe version n6.0 Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 13.2.1 (GCC) 20230801
  ...
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55cd72a08740] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Morgan_Housel_-_The_Psychology_of_Money.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    title           : The Psychology of Money: Timeless Lessons on Wealth, Greed, and Happiness
    artist          : Morgan Housel
    composer        : Chris Hill
    album           : The Psychology of Money: Timeless Lessons on Wealth, Greed, and Happiness
    date            : 2020
    encoder         : inAudible 1.97
    comment         : Money - investing, personal finance, and business decisions - is typically taught as a math-based field, where data and formulas tell us exactly what to do. But in the real world people don’t make financial decisions on a spreadsheet. They make them at 
    genre           : Audiobook
    description     : Money - investing, personal finance, and business decisions - is typically taught as a math-based field, where data and formulas tell us exactly what to do. But in the real world people don’t make financial decisions on a spreadsheet. They make them at 
  Duration: 05:48:30.64, start: 0.000000, bitrate: 63 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 13.606000
      Metadata:
        title           : 001
    Chapter #0:1: start 13.606000, end 804.571000
      Metadata:
        title           : 002
    Chapter #0:2: start 804.571000, end 1981.405000
      Metadata:
        title           : 003
    Chapter #0:3: start 1981.405000, end 3212.387000
      Metadata:
        title           : 004
    Chapter #0:4: start 3212.387000, end 4043.987000
      Metadata:
...

Pretty good, it contains enough metadata that I can probably rename it straight into a m4b.

# Dump the chapters, which will be in .ttxt format
$ MP4Box -dump-chap book.m4b
# Add the improved chapters back to the m4b
# MP4Box will edit the original file by default. We want that, because otherwise we will have to explicitly copy over the cover image, the artist/genre/encoder/composer metadata...
$ MP4Box -chap book.ttxt Psychology\ of\ Money\ -\ Morgan\ Housel.m4b

Perfect. The finished audiobook is a joy to browse through.

Leave a Reply

Your email address will not be published.