<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: roy</title>
    <description>The latest articles on DEV Community by roy (@juanxincai).</description>
    <link>https://dev.to/juanxincai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4277350%2Fc8f7bb3c-9c4b-496b-a47e-2d178a049ed2.jpg</url>
      <title>DEV Community: roy</title>
      <link>https://dev.to/juanxincai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juanxincai"/>
    <language>en</language>
    <item>
      <title>How I Fixed FFmpeg Non-Monotonic DTS Crashes While Converting a 3-Hour EPUB to a Chaptered M4B Audiobook</title>
      <dc:creator>roy</dc:creator>
      <pubDate>Wed, 02 Dec 2026 01:56:28 +0000</pubDate>
      <link>https://dev.to/juanxincai/how-i-fixed-ffmpeg-non-monotonic-dts-crashes-while-converting-a-3-hour-epub-to-a-chaptered-m4b-329m</link>
      <guid>https://dev.to/juanxincai/how-i-fixed-ffmpeg-non-monotonic-dts-crashes-while-converting-a-3-hour-epub-to-a-chaptered-m4b-329m</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;args.push("-i", path.resolve(p));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;const labels = inputPaths.map((_, idx) =&amp;gt; &lt;code&gt;[${idx}:a]&lt;/code&gt;).join("");&lt;br&gt;
  const filterComplex = &lt;code&gt;${labels}concat=n=${inputPaths.length}:v=0:a=1,aresample=24000,asetpts=N/SR/TB[out]&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;args.push(&lt;br&gt;
    "-filter_complex", filterComplex,&lt;br&gt;
    "-map", "[out]",&lt;br&gt;
    "-c:a", "libmp3lame", "-b:a", "96k", "-ar", "24000", "-ac", "1",&lt;br&gt;
    outPath&lt;br&gt;
  );&lt;/p&gt;

&lt;p&gt;await execFileAsync("ffmpeg", args, { maxBuffer: FFMPEG_MAX_BUFFER });&lt;br&gt;
}&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


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 &amp;amp; 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 &amp;amp; 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!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ffmpeg</category>
      <category>typescript</category>
      <category>node</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
