How I Fixed FFmpeg Non-Monotonic DTS Crashes While Converting a 3-Hour EPUB to a Chaptered M4B Audiobook
args.push("-i", path.resolve(p)); } const labels = inputPaths.map((_, idx) => [${idx}:a]).join(""); const filterComplex = ${labels}concat=n=${inputPaths.length}:v=0:a=1,aresample=24000,asetpts=N/SR/TB[out]; args.
args.push("-i", path.resolve(p));
}
const labels = inputPaths.map((_, idx) => [${idx}:a]).join("");
const filterComplex = ${labels}concat=n=${inputPaths.length}:v=0:a=1,aresample=24000,asetpts=N/SR/TB[out];
args.push(
"-filter_complex", filterComplex,
"-map", "[out]",
"-c:a", "libmp3lame", "-b:a", "96k", "-ar", "24000", "-ac", "1",
outPath
);
await execFileAsync("ffmpeg", args, { maxBuffer: FFMPEG_MAX_BUFFER });
}
And during final `.m4b` muxing across chapters, we apply the same `-af aresample=24000,asetpts=N/SR/TB` guard along with `-movflags +faststart` and `-disposition:v:0 attached_pic` so cover art and chapter markers work reliably in Apple Books, BookPlayer, Smart AudioBook Player, and Audiobookshelf.
---
## Measured Full-Book Benchmark: *The Time Machine* (Unabridged)
After shipping the fix, we ran the entire Standard Ebooks EPUB3 of *The Time Machine* through the exact production pipeline and published the unmodified outputs + raw `ffprobe` JSON on GitHub:
| Metric | Measured Result |
|---|---|
| **Source EPUB** | H. G. Wells, *The Time Machine* (1895, Standard Ebooks EPUB3) |
| **Sections Detected โ Kept** | 17 detected โ 4 boilerplate auto-skipped (`Imprint`, `Endnotes`, `Colophon`, `Uncopyright`) โ **13 story chapters** |
| **Length** | 178,635 characters (~32,450 words), 153 chunks |
| **Audio Duration** | **3h 01m 35s** (`10,895s`) |
| **End-to-End Build Time** | **7m 23s** (5m 14s 12-way parallel TTS + 2m 09s FFmpeg packaging) |
| **Output Files** | **88.4 MB `.m4b`** (AAC 64 kbps ยท 24 kHz, `attached_pic`, `+faststart`) + **124.7 MB numbered `.mp3` ZIP** |
| **Published Order Cost** | **$2.99** (`$0.008 / 1k chars`, no subscription) |
---
## One Surprising iOS Gotcha We Discovered Along the Way
If you build anything outputting `.m4b` files, warn your iPhone users clearly: **Apple Books on iOS does not import `.m4b` files directly from the Files app**, even though Apple Books on macOS opens them with a double-click.
On iPhone/iPad without a Mac, the cleanest workflow is opening the `.m4b` directly in the free, open-source **BookPlayer** app (`Files โ Share โ BookPlayer`). If you want Apple Books on iPhone, you import into Apple Books on Mac first and sync via Finder. We documented the full walkthrough in our [iPhone & Apple Books M4B import guide](https://audiobookdrop.com/how-to-import-m4b-iphone).
---
## Inspect the Real Files Yourself
- **Full 3-hour `.m4b`, 13-chapter `.mp3` ZIP, SHA-256 checksums & raw `ffprobe` JSON:** [github.com/juan-xin-cai/audiobookdrop-samples](https://github.com/juan-xin-cai/audiobookdrop-samples)
- **Live converter (free 30s real-book preview, no signup):** [audiobookdrop.com](https://audiobookdrop.com)
- **78-second end-to-end walkthrough video:** [Watch on YouTube](https://www.youtube.com/watch?v=dg9IgygrIBk)
If you've run into other weird FFmpeg MP4/M4B chapter quirks (especially with non-ASCII chapter titles or very large cover PNGs), I'd love to hear how you handled them in the comments!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.