Skip to content

nostoslabs/mkm4b

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mkm4b

Fast command-line utility to convert audio files to M4B audiobook format.

Features

  • 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

Requirements

  • Python 3.11+
  • FFmpeg must be installed and available in PATH

Installing FFmpeg

macOS:

brew install ffmpeg

Ubuntu/Debian:

sudo apt update && sudo apt install ffmpeg

Windows: Download from ffmpeg.org and add to PATH.

Installation

# Clone or navigate to the project directory
cd mkm4b

# Install with uv
uv pip install -e .

Usage

Basic usage

mkm4b *.mp3 -o audiobook.m4b

Note: The tool will not overwrite existing output files. If the specified output file already exists, an error will be raised to prevent data loss.

With metadata and cover

mkm4b *.mp3 -o audiobook.m4b \
  --title "My Audiobook" \
  --author "Author Name" \
  --cover cover.jpg

Convert all audio files in a directory

mkm4b /path/to/audio/files -o audiobook.m4b --title "Book Title" --author "Author"

Mix multiple files and directories

mkm4b chapter1.mp3 chapter2.mp3 /path/to/more/chapters -o complete.m4b

Command-line Options

positional 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.)

Supported Formats

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)

How It Works

mkm4b uses FFmpeg to:

  1. Concatenate all input audio files in sorted order
  2. Convert to AAC codec at 64kbps (optimal for audiobooks)
  3. Embed cover artwork as an attached picture
  4. Add metadata (title, author)
  5. 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

Examples

Example 1: Simple conversion

mkm4b chapter*.mp3 -o mybook.m4b

Example 2: Full metadata

mkm4b /audiobooks/project-hail-mary/*.mp3 \
  -o "Project Hail Mary.m4b" \
  --title "Project Hail Mary" \
  --author "Andy Weir" \
  --cover cover.jpg

Example 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"

Troubleshooting

Error: FFmpeg is not installed or not in PATH

Make sure FFmpeg is installed and accessible from command line:

ffmpeg -version

Files 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.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages