ChapterForge

ChapterForge is a library and CLI to mux chapters (text and optional images) into MP4 files while preserving metadata and handling Apple-compatible chapter tracks.
Table of Contents
Motivation and Backstory
MPEG4 and its container MP4 standard do not explicitly describe chapter marks. Apple however did, implicitly.
Back in the days, under the umbrella of the QuickTime.framework, Apple had released authoring tools for audiobooks. With those tools you could add jump-marks to an M4A file. Those jump-marks could have a description text, an image and possibly more. That way a user could conveniently jump to specific sections of the audio -- useful for example as a mark for chapters. There are many players that understand those, but not all do. Specifically Apple who has pushed for this "extension" of the standard, has traditionally been understanding it in their players. That is true for Music.app, iTunes.app, QuickTime.app and even Books.app. All of them today support chapter marks. Windows has existing support there as well. That said it becomes clear, this is not standard but at least a functional solution for the challenge of encoding such thing into the audio file.
Apple did support authoring tools - but that was way back in PowerPC times. The QTKit is long gone. There appears to be not a single open source tool in the market that would support a recent OS. There are tools like ffmpeg - it does even support chapter marks for MP4 - but - no images for those. The only tool in the market supporting images in chapter marks in 2025 appears to be Auphonic - commercial.
All the existing libraries offered to application developers, even the big players like Bento4 do not support chapter marks with images. AVFoundation, the framework Apple offers these days for media playback and authoring does fully support reading of MP4 chapter marks including images. Thus creating a player supporting that feature is trivial. The kicker here is, Apple does not support any way of authoring / writing / creating such files - none at all.
No one had a strong enough interest to change this, until today.
My tinker project needs support for storing a track-list / set-list in the file itself. That way I can attribute those beautiful DJ sets and have neat track-mark thumbnails and descriptions on the player, persisted in the M4A file. A few thousand lines of code later, we have a new library based on no other works available which does the job for me - maybe also for you.
Features
ChapterForge uses the audio track from the input. It then combines that with a text track for the description, an optional text track for per-chapter URLs, and a video track for optional chapter images. All of that information gets bundled in the resulting output M4A file. With that M4A file you can now see chapter marks in your player.
Platforms
Supported players (just a selection of known goods):
|
text |
image |
url |
url-text |
| QuickTime.app |
X |
X |
o |
o |
| Music.app |
X |
X |
o |
o |
| Books.app |
X |
X |
o |
o |
| VLC |
X |
o |
o |
o |
(X = full support and display, o = not displayed, all other functions remain)
Text commonly is displayed as the chapter title.
Image commonly is displayed as a thumbnail. In QuickTime we additionally get a "movie" presented - a very nice experience.
URL commonly is displayed nowhere.
URL text commonly is displayed nowhere.
Note that AVFoundation supports all of those attributes for parsing and extraction - on macOS and iOS it is therefor trivial to support them.
Example output to validate players
We ship two reference files you can open in your favorite player to sanity-check chapter handling:
- Input JSON:
testdata/chapters_10s_2ch_normalimg_meta.json
- 2 chapters at 0 and 5 seconds (fits the 10s input)
- Cover:
images/cover_normal.jpg
- Per-chapter images:
images/normal*.jpg
- URL track with per-chapter HREFs
- Built example: ChapterForge Example M4A File
What to expect:
- Chapter list shows the 2 entries with titles and thumbnails.
- Jumps land at the correct 5s offsets.
- QuickTime shows the video track for chapter images; Music.app shows thumbnails.
- URLs are present in the dedicated URL track (AVFoundation surfaces them via
extraAttributes[HREF]), but players generally do not display them.
Bonus: ChapterForge Bonus Track M4A File — 50 chapters, small images, and per-chapter URLs to stress-test players.
QuickTime.app on macOS playing our example file:

Music.app on macOS playing our example file:

Do you have more players showing our example file? Would be great to see them.
Installing
macOS (Homebrew tap)
brew tap tillt/chapterforge https://github.com/tillt/ChapterForge.git
brew install --HEAD tillt/chapterforge/chapterforge
This builds the CLI and static library (and the universal macOS framework when enabled). Head-only for now; tags will become bottled when we ship stable releases.
Windows
Linux
vcpkg (overlay port)
Add this repo as an overlay (or copy ports/chapterforge into your overlays), then:
vcpkg install chapterforge
The overlay tracks the current commit. Update REF/SHA512 in ports/chapterforge/portfile.cmake when you bump versions.
CLI Usage
./chapterforge_cli <input.m4a|.mp4|.aac> <chapters.json> <output.m4a>
./chapterforge_cli <input.m4a> [--export-jpegs DIR] # read/extract
./chapterforge_cli --version
- Write mode: mux chapters/images/URLs into an output M4A. If the input already has metadata (
ilst),
it is reused by default. Fast-start is ON by default (moov before mdat); use --no-faststart if you
need the legacy layout.
- Read mode: extract metadata, chapter titles/URLs/URL-texts, and images from an M4A. The JSON emitted
matches the writer input format and is always printed to stdout. Use
--export-jpegs DIR to dump cover
- chapter images alongside the JSON and reference them in the output.
- Logging: defaults to version + warnings/errors. Set verbosity when embedding via
chapterforge::set_log_verbosity(LogVerbosity::Warn|Info|Debug) or pass --log-level warn|info|debug
to the CLI. Debug-only logs stay hidden unless you raise the level.
- Options:
--faststart (write) Explicitly enable fast-start (default).
--no-faststart (write) Disable fast-start; keep mdat before moov.
--log-level LEVEL One of warn|info|debug.
--export-jpegs DIR (read) Export cover/chapter JPEGs to DIR and reference them in the JSON.
Chapters JSON format
ChapterForge consumes a simple JSON document:
{
"title": "Sample Podcast Episode", // optional top-level metadata
"artist": "John Doe",
"album": "My Podcast",
"genre": "Podcast",
"year": "2024",
"comment": "Created with ChapterForge",
"cover": "cover.jpg", // optional; path is relative to the JSON file
"chapters": [
{
"title": "Introduction", // required
"start_ms": 0, // required: chapter start time in milliseconds (first snaps to 0)
"image": "chapter1.jpg", // optional; path relative to the JSON file
"url": "https://example.com", // optional; creates a URL text track with HREF
"url_text": "Intro link label" // optional; text payload for the URL track (defaults empty)
},
{
"title": "Main Discussion",
"start_ms": 10000,
"image": "chapter2.jpg",
"url": ""
}
]
}
Notes:
- Chapters are positioned by absolute start times (
start_ms). Apple family players (QuickTime,
Music.app, AVFoundation) and VLC snap the first chapter to 0 even if you author a non-zero
start_ms. We warn on non-zero first starts; if you truly need a gap, add an explicit
leading “blank” chapter covering 0–gap_ms.
- Chapter images are optional; omit
image to create a text-only chapter.
- URL track text:
url_text is optional and defaults to empty (Apple-authored behavior). If set,
it travels in the URL tx3g samples; some players may surface it as visible text.
- Chapter URLs are optional; omit
url to skip the URL track entirely.
- If top-level metadata fields are omitted and the input file already contains metadata (
ilst), that metadata is preserved automatically.
- Paths for
cover and per-chapter image are resolved relative to the JSON file location.
Output
Atom flow (input → output)
ChapterForge preserves the source audio track and metadata (ilst) and adds up to three new tracks for chapters:
Input (AAC in M4A/MP4)
├─ ftyp
├─ free (optional)
├─ moov
│ ├─ mvhd
│ ├─ trak (audio)
│ │ ├─ tkhd
│ │ └─ mdia → minf → stbl (reused, including stsd/stts/stsc/stsz/stco)
│ └─ udta/meta/ilst (reused if present)
└─ mdat
Output (ChapterForge)
├─ ftyp
├─ free (optional or moved for faststart)
├─ moov
│ ├─ mvhd
│ ├─ trak (audio, reused stbl when input is MP4/M4A)
│ ├─ trak (chapter titles, tx3g)
│ │ └─ stbl with stsd(tx3g) + stts/stsc/stsz/stco
│ ├─ trak (chapter URLs, tx3g with href) [only if any chapter has `url` or `url_text`]
│ │ └─ same structure as titles; text may be empty, href carries the URL
│ ├─ trak (chapter images, jpeg)
│ │ └─ stbl with stsd(jpeg) + stts/stsc/stsz/stco/stss
│ └─ udta/meta/ilst (reused if present, otherwise from JSON)
└─ mdat (audio + chapter samples)
Fast-start repacks moov ahead of mdat when requested.
These settings mirror Apple-authored “golden” files so that QuickTime, Music.app, and AVFoundation surface titles, URLs, and thumbnails reliably.
Technical Breakdown
- Track references (
tref/chap): audio track points only to the title text track and the image track (when present); the URL track is deliberately not referenced. This matches Apple-authored files and keeps QuickTime showing titles while Music.app shows thumbnails.
- HREF propagation: every chapter URL is mirrored into the title track payload as well, which makes AVFoundation expose it in
extraAttributes[HREF].
- Timescales: text/url/image tracks use 1000 Hz; audio timescale is preserved from the source. Track IDs may differ; structure/flags/handlers remain.
- Chapter images: the video track dimensions come from the first JPEG; keep all chapter images the same size (and yuvj420p) so every frame displays in QuickTime/Music. Dimension mismatches emit a mux-time warning and may hide later frames.
Chapter track reference (titles, URLs, images)