Fast command-line utility to convert audio files to M4B audiobook format.
- Converts multiple audio files (MP3, AAC, M4A, FLAC, OGG, WAV, OPUS, WMA) to M4B format
- Supports metadata: title, author
- Embeds cover artwork (PNG, JPG, WebP, etc.) from files or URLs
- Fast conversion using FFmpeg
- Automatic file sorting and concatenation
- Prevents accidental overwrites of existing output files
- Python 3.11+
- FFmpeg must be installed and available in PATH
macOS:
brew install ffmpegUbuntu/Debian:
sudo apt update && sudo apt install ffmpegWindows: Download from ffmpeg.org and add to PATH.
# Clone or navigate to the project directory
cd mkm4b
# Install with uv
uv pip install -e .mkm4b *.mp3 -o audiobook.m4bNote: The tool will not overwrite existing output files. If the specified output file already exists, an error will be raised to prevent data loss.
mkm4b *.mp3 -o audiobook.m4b \
--title "My Audiobook" \
--author "Author Name" \
--cover cover.jpgmkm4b /path/to/audio/files -o audiobook.m4b --title "Book Title" --author "Author"mkm4b chapter1.mp3 chapter2.mp3 /path/to/more/chapters -o complete.m4bpositional arguments:
files Audio files or directories to convert
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output M4B file path (required)
--title TITLE Audiobook title
--author AUTHOR Audiobook author
--cover COVER Cover image file or URL (PNG, JPG, WebP, etc.)
Input audio formats:
- MP3 (.mp3)
- M4A (.m4a)
- AAC (.aac)
- FLAC (.flac)
- OGG (.ogg)
- WAV (.wav)
- OPUS (.opus)
- WMA (.wma)
Cover image formats:
- PNG (.png)
- JPEG (.jpg, .jpeg)
- BMP (.bmp)
- GIF (.gif)
- WebP (.webp)
mkm4b uses FFmpeg to:
- Concatenate all input audio files in sorted order
- Convert to AAC codec at 64kbps (optimal for audiobooks)
- Embed cover artwork as an attached picture
- Add metadata (title, author)
- Package in M4B (MPEG-4 Part 14) container format
The conversion is very fast because:
- FFmpeg handles all heavy lifting in optimized C code
- Minimal Python overhead
- Direct stream processing without intermediate files
Example 1: Simple conversion
mkm4b chapter*.mp3 -o mybook.m4bExample 2: Full metadata
mkm4b /audiobooks/project-hail-mary/*.mp3 \
-o "Project Hail Mary.m4b" \
--title "Project Hail Mary" \
--author "Andy Weir" \
--cover cover.jpgExample 3: Using a URL for cover art
mkm4b *.mp3 -o audiobook.m4b \
--title "My Audiobook" \
--cover "https://example.com/cover.webp"Example 4: Multiple directories
mkm4b /audio/part1 /audio/part2 /audio/part3 \
-o complete-series.m4b \
--title "Complete Series" \
--author "Author Name"Error: FFmpeg is not installed or not in PATH
Make sure FFmpeg is installed and accessible from command line:
ffmpeg -versionFiles not in correct order
Files are sorted alphabetically. Use numeric prefixes for proper ordering:
001-chapter.mp3
002-chapter.mp3
003-chapter.mp3
Error: Output file already exists
If you get an error like "Output file already exists: output.m4b", remove or rename the existing file before running the conversion again. The tool prevents accidental overwrites to protect your data.
MIT