audiobook-forge 2.9.1

CLI tool for converting audiobook directories to M4B format with chapters and metadata
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# Audiobook Forge 🎧

[![Rust](https://img.shields.io/badge/rust-1.75%2B-orange.svg)](https://www.rust-lang.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Tests](https://img.shields.io/badge/tests-77%20passing-brightgreen.svg)](tests/)

A blazing-fast CLI tool for converting audiobook directories to M4B format with chapters and metadata. Written in Rust for maximum performance and reliability.

## 📑 Table of Contents

- [Why Audiobook Forge?]#-why-audiobook-forge
- [Features]#-features
- [Installation]#-installation
- [Quick Start]#-quick-start
- [Documentation]#-documentation
- [Performance]#-performance
- [Contributing]#-contributing
- [License]#-license

---

## 🎯 Why Audiobook Forge?

When downloading audiobooks, they often come as **multiple separate MP3 files** — one for each chapter or section. While this works fine with audiobook players, managing your library becomes significantly easier when **each audiobook is consolidated into a single file**.

**Audiobook Forge** takes those scattered audio files and merges them into a single **M4B file** (MPEG-4 Audiobook format), which is the standard for audiobook applications.

### 📚 Benefits of Single M4B Files

✅ **Simplified Library Management** - One file per audiobook instead of dozens

✅ **Better Metadata & Chapter Support** - Embedded chapter markers and complete metadata

✅ **Improved Portability** - Transfer entire audiobooks with a single file copy

✅ **Enhanced Playback Experience** - Resume exactly where you left off across devices

✅ **Reduced Storage Overhead** - Efficient compression while preserving quality

✅ **Universal Compatibility** - Works with Apple Books, Audiobookshelf, Plex, and most players

---

## ✨ Features

- **📁 Auto-Detect Current Directory**: Run from inside audiobook folders without `--root` parameter
- **⚡ Parallel File Encoding**: Encode files concurrently for **3.8x faster** processing (121s → 32s)
- **🚀 Parallel Book Processing**: Convert multiple audiobooks simultaneously
- **🎯 Smart Quality Detection**: Automatically detects and preserves source audio quality
- **📖 Chapter Generation**: Multiple sources (files, CUE sheets, auto-detection)
- **📝 Chapter Updates** (v2.9.0): Replace generic chapter names with meaningful titles from Audnex API, text files, or EPUB
- **🎨 Metadata Management**: Comprehensive metadata from multiple sources
- **🖼️ Auto-Extract Cover Art** (v2.8.0): Automatically extracts embedded cover art as fallback
- **🎭 Interactive Metadata Matching** (v2.3.0+): BEETS-inspired fuzzy matching with confidence scoring
- **🎧 Audible Integration** (v2.2.0): Fetch comprehensive metadata from Audible's catalog
- **🔄 Batch Operations**: Process entire libraries with a single command
- **⚡ Copy Mode**: Ultra-fast concatenation without re-encoding when possible
- **🔗 M4B Merge** (v2.9.1): Combine multiple M4B files into one without re-encoding
- **🔁 Error Recovery**: Automatic retry with configurable settings
- **📊 Progress Tracking**: Real-time progress with ETA calculation
- **⚙️ Configuration**: Comprehensive YAML-based configuration with CLI overrides

---

## 💖 Support This Project

If you find **audiobook-forge** useful, please consider supporting its development!

[![Sponsor](https://img.shields.io/badge/Sponsor-❤-ea4aaa?style=for-the-badge&logo=github-sponsors)](https://github.com/sponsors/juanra)

Your sponsorship helps:
- 🚀 **Active Development**: Keep the project maintained and add new features
- 🐛 **Bug Fixes**: Respond quickly to issues and edge cases
- 📚 **Documentation**: Maintain comprehensive guides and examples
- 🆓 **Free & Open Source**: Keep audiobook-forge free for everyone

Every contribution, no matter the size, is deeply appreciated! 🙏

---

## 📦 Installation

### Quick Install

```bash
cargo install audiobook-forge
```

### Dependencies

Install required tools:

**macOS:**
```bash
brew install ffmpeg atomicparsley gpac
```

**Ubuntu/Debian:**
```bash
sudo apt update
sudo apt install ffmpeg atomicparsley gpac
```

**Fedora/RHEL:**
```bash
sudo dnf install ffmpeg atomicparsley gpac
```

### Verify Installation

```bash
audiobook-forge check
```

**📖 Detailed installation guide**: See [docs/installation.md](docs/installation.md)

---

## 🚀 Quick Start

### Convert a Single Audiobook

```bash
# Auto-detect: Run from inside an audiobook folder
cd "/path/to/My Audiobook"
audiobook-forge build

# Or specify the path explicitly
audiobook-forge build --root "/path/to/My Audiobook"
```

### Batch Process Multiple Audiobooks

```bash
audiobook-forge build --root "/path/to/audiobooks" --parallel 4
```

### With Audible Metadata

```bash
# Rename folders with ASINs: "Book Title [B00G3L6JMS]"
audiobook-forge build --root /audiobooks --fetch-audible
```

### Interactive Metadata Matching

```bash
# Match existing M4B files with Audible metadata
audiobook-forge match --file "Book.m4b"

# Batch match entire directory
audiobook-forge match --dir /path/to/m4b/files
```

### Update M4B Chapters (v2.9.0) 🆕

Replace generic chapter names ("Chapter 1", "Chapter 2") with meaningful titles from multiple sources:

```bash
# Update chapters from Audnex API (Audible chapter data)
audiobook-forge metadata enrich --file "Book.m4b" \
  --chapters-asin B08V3XQ7LK

# Update from text file (simple, timestamped, or MP4Box format)
audiobook-forge metadata enrich --file "Book.m4b" \
  --chapters chapters.txt \
  --merge-strategy keep-timestamps

# Update from EPUB table of contents
audiobook-forge metadata enrich --file "Book.m4b" \
  --chapters book.epub

# Update chapters only (skip metadata enrichment)
audiobook-forge metadata enrich --file "Book.m4b" \
  --chapters chapters.txt \
  --update-chapters-only
```

**Supported chapter sources:**
- **Audnex API**: Fetch official Audible chapter data by ASIN
- **Text files**: Simple (one per line), timestamped (HH:MM:SS Title), MP4Box format
- **EPUB files**: Extract from table of contents

**Merge strategies:**
- `keep-timestamps`: Update names, preserve existing timestamps (default for text/EPUB)
- `replace-all`: Replace entire chapter list with new data
- `skip-on-mismatch`: Error if chapter counts don't match
- `interactive`: Prompt for each file (default)

**📖 Complete usage guide**: See [docs/usage.md](docs/usage.md)

### M4B Merge (v2.9.1) 🆕

Combine multiple M4B files into a single file **without re-encoding**:

```bash
# Auto-detect sequential parts (Part 1, Part 2, Disc 1, etc.)
audiobook-forge build --root /path/to/book

# Force merge even without detected pattern
audiobook-forge build --root /path/to/book --merge-m4b
```

**Supported naming patterns:**
- **Part patterns**: `Part 1`, `Part 2`, `Pt 1`, `Pt. 1`
- **Disc patterns**: `Disc 1`, `Disc1`, `CD1`, `CD 1`, `Disk 1`
- **Numeric suffix**: `Book 01.m4b`, `Book 02.m4b`

**Features:**
- **Lossless audio concatenation** - No re-encoding, preserves original quality
- 📖 **Chapter preservation** - All chapters merged with adjusted timestamps
- 📝 **Metadata copying** - Metadata from first source file is preserved
- 🔍 **Smart detection** - Automatically identifies related files by naming pattern

---

## 📚 Documentation

Comprehensive documentation is available in the `/docs` directory:

- **[Installation Guide]docs/installation.md** - Setup and dependencies
- **[Usage Guide]docs/usage.md** - Commands, examples, and workflows
- **[Configuration Guide]docs/configuration.md** - All configuration options
- **[Metadata Guide]docs/metadata.md** - Metadata management and Audible integration
- **[Troubleshooting Guide]docs/troubleshooting.md** - Common issues and solutions

### Quick Reference

**Essential Commands:**

```bash
audiobook-forge build                    # Convert audiobook (auto-detect)
audiobook-forge build --root /path       # Convert with explicit path
audiobook-forge organize --root /path    # Organize library
audiobook-forge match --file book.m4b    # Interactive matching
audiobook-forge metadata fetch --asin ID # Fetch Audible metadata
audiobook-forge config show              # Show configuration
audiobook-forge check                    # Verify dependencies
```

**Key Configuration:**

```yaml
performance:
  enable_parallel_encoding: true  # 3.8x faster encoding
  max_concurrent_encodes: "auto"

metadata:
  auto_extract_cover: true  # Auto-extract embedded cover art (v2.8.0)
  audible:
    enabled: false
    region: "us"
```

See [docs/configuration.md](docs/configuration.md) for complete options.

---

## 📊 Performance

### Benchmarks

**Parallel File Encoding (v2.1.0+):**

| Mode | Time | CPU Usage | Speedup |
|------|------|-----------|---------|
| Serial encoding | 121.5s | 13% | Baseline |
| Parallel encoding | 32.1s | 590% | **3.8x faster** 🚀 |

*Test: 10-file audiobook (~276MB) on 8-core CPU*

**Overall Performance vs Python:**

| Operation | Python | Rust v2.0 | Rust v2.1+ | Speedup |
|-----------|--------|-----------|------------|---------|
| Startup | ~500ms | ~10ms | ~10ms | **50x** |
| Single book (copy) | 45s | 12s | 12s | **3.8x** |
| Single book (transcode) | 180s | 65s | 17s | **10.6x** 🚀 |
| Batch (10 books) | 25m | 8m | 2.5m | **10x** 🚀 |
| Memory | ~250 MB | ~25 MB | ~25 MB | **10x less** |

### Performance Tips

1. **Enable parallel encoding** (default in v2.1.0+)
2. **Use parallel workers**: `--parallel 4` or more
3. **Enable copy mode**: Automatic for M4A/AAC files
4. **Use SSD storage**: Faster I/O for large libraries
5. **Apple Silicon**: Hardware acceleration with `aac_at` encoder

---

## 🎯 Supported Formats

### Input

- **MP3** (`.mp3`) - MPEG Audio Layer III
- **M4A** (`.m4a`) - MPEG-4 Audio
- **AAC** (`.aac`) - Advanced Audio Coding

### Output

- **M4B** (`.m4b`) - MPEG-4 Audiobook with embedded chapters and metadata

### Metadata Sources

- **Local**: ID3 tags, M4A atoms, CUE sheets, filenames, folder names
- **Auto-Extract**: Embedded cover art from MP3/M4A files (v2.8.0)
- **Audible**: Comprehensive metadata from 10 regional stores (v2.2.0)
- **Interactive**: Fuzzy matching with confidence scoring (v2.3.0+)

---

## ⚙️ Configuration

Configuration file: `~/.config/audiobook-forge/config.yaml`

```bash
# Initialize default configuration
audiobook-forge config init

# Show current configuration
audiobook-forge config show

# Edit configuration
audiobook-forge config edit
```

**Example configuration:**

```yaml
performance:
  enable_parallel_encoding: true
  max_concurrent_encodes: "auto"

processing:
  parallel_workers: 4
  skip_existing: true

metadata:
  auto_extract_cover: true
  audible:
    enabled: false
    region: "us"
    download_covers: true
```

**📖 Complete configuration reference**: See [docs/configuration.md](docs/configuration.md)

---

## 🔧 Common Issues

### FFmpeg not found

```bash
brew install ffmpeg                    # macOS
sudo apt install ffmpeg                # Ubuntu/Debian
```

### Permission denied

```bash
chmod -R u+rw /path/to/audiobooks
```

### Out of memory

```bash
audiobook-forge build --root /path --parallel 1
```

**📖 Complete troubleshooting guide**: See [docs/troubleshooting.md](docs/troubleshooting.md)

---

## 🤝 Contributing

Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

### Quick Start for Contributors

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/my-feature`
3. Make your changes
4. Run tests: `cargo test`
5. Run linter: `cargo clippy`
6. Format code: `cargo fmt`
7. Commit: `git commit -m "feat: add my feature"`
8. Push and open a Pull Request

---

## 📄 License

This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

**MIT License Summary:**

- ✅ Commercial use
- ✅ Modification
- ✅ Distribution
- ✅ Private use
- ⚠️ Liability and warranty disclaimer

---

## 🙏 Acknowledgments

- **Original Python version**: This Rust rewrite delivers 3-4x better performance
- **FFmpeg**: The backbone of audio processing
- **Rust community**: For excellent crates and tooling
- **Contributors**: Thanks to all who have contributed

### Built With

- [Rust]https://www.rust-lang.org/ - Systems programming language
- [Tokio]https://tokio.rs/ - Async runtime
- [Clap]https://github.com/clap-rs/clap - CLI framework
- [FFmpeg]https://ffmpeg.org/ - Audio/video processing
- [AtomicParsley]https://github.com/wez/atomicparsley - Metadata embedding
- [MP4Box/GPAC]https://github.com/gpac/gpac - MP4 container tools

---

## 📞 Support

- **Documentation**: [docs/]docs/ folder
- **Issues**: [GitHub Issues]https://github.com/juanra/audiobook-forge/issues
- **Discussions**: [GitHub Discussions]https://github.com/juanra/audiobook-forge/discussions

---

Made with ❤️ and 🦀 (Rust)