Skip to content

A set of bash scripts to convert audio files into M4B audiobooks with chapter markers, customizable bitrate, book metadata and embedded cover art.

License

Notifications You must be signed in to change notification settings

weak-head/m4b-maker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

M4B Audiobook Maker

A set of bash scripts to convert audio files into M4B audiobooks with chapter markers, customizable bitrate, book metadata and embedded cover art.

lint GitHub Release #!/bin/bash MIT License

Table of Contents

Overview

M4B Audiobook Maker is a set of bash scripts that simplify converting audio files into the M4B audiobook format. It includes m4bify for single conversions and m4bulk for batch processing.

Single Audiobook Conversion (m4bify)

Combines audio files into a single M4B audiobook with chapter markers, ensuring correct playback order by processing files alphabetically. Chapters are automatically created based on metadata, filenames, or top-level subdirectories. You can customize the audio quality, and if an image file or embedded art is available, it will be added as the book cover. Additionally, directory names that follow supported patterns are parsed to extract metadata such as the author, title, and year.

Batch Audiobook Conversion (m4bulk)

Scan a root directory for audiobook folders and convert them to M4B files in parallel. Pass custom options, such as bitrate and chapter settings, to apply them to all audiobooks. m4bulk leverages multiple worker threads for simultaneous processing, speeding up batch conversions.

Getting Started

Ensure the following dependencies are installed: ffmpeg and mp4v2.

# For RPM-based systems (Fedora, RHEL, CentOS)
sudo dnf install ffmpeg libmp4v2

# For Debian-based systems (Ubuntu, Debian)
sudo apt install ffmpeg

To install the scripts, run:

make install

This installs the scripts to /usr/local/sbin/.

m4bify

m4bify creates M4B audiobook by processing files in the specified directory, sorting them alphabetically to ensure the correct playback order. Chapters can be organized either as file-based, where each audio file becomes its own chapter named using metadata or filenames, or directory-based, where each top-level subdirectory is treated as a chapter, combining all its audio files, including those in nested folders, into one.

Other features include:

  • Configurable audio bitrate, with high-quality AAC VBR as the default.
  • Metadata extraction from directory names that follow supported patterns.
  • Automatic cover art inclusion from image files or embedded artwork.
  • Comprehensive logs with chapter metadata.

Syntax

m4bify [--help] [-d | --chapters-from-dirs] [-b <bitrate> | --bitrate <bitrate>] <directory>

Options

  • -d, --chapters-from-dirs: Treats each top-level subdirectory as a chapter.
  • -b <value>, --bitrate <value>: Sets the audio encoding bitrate (e.g. "128k", default: VBR Very High).
  • --help: Displays usage instructions and exits.

Arguments

  • <directory> (required): Path to the directory containing audiobook files.

Directory Patterns

Pattern Example
<author_name> - <book_title> (<year>) J.K. Rowling - Harry Potter and the Philosopher's Stone (1997)
<author_name> - <book_title> Agatha Christie - Murder on the Orient Express
<book_title> (<year>) To Kill a Mockingbird (1960)

Both hyphen (-) and underscore (_) are supported as separators. Additionally, square brackets ([]) can be used as an alternative to parentheses (()) for enclosing year information.

m4bulk

m4bulk automates batch conversion of audiobook folders to M4B format using m4bify. It scans a root directory for audiobook folders and processes them in parallel.

Key features:

  • Distributes tasks across multiple workers.
  • Automatically detects audiobook directories in the root folder.
  • Allows customization of m4bify options, such as bitrate and chapter generation.
  • Generates and saves logs for each audiobook conversion in the source folder.

Syntax

m4bulk [--help] [--workers <N>] [m4bify-options] <audiobooks_directory>

Options

  • --workers <N>: Number of worker threads (default: 50% of CPU cores).
  • --help: Displays usage instructions and exits.

Arguments

  • [m4bify-options] (optional): Optional arguments passed directly to m4bify (e.g. -b <rate>).
  • <audiobooks_directory> (required): Directory containing subdirectories of audiobooks to convert.

Usage Examples

Metadata Extracted from Directory Name

Combine all audio files in /home/user/audiobooks/Author Name - Book Title (1993)/ into a single M4B audiobook. Chapters are automatically generated based on file metadata or filenames. Author, title and year are extracted from the directory name:

m4bify "/home/user/audiobooks/Author Name - Book Title (1993)"

Subdirectory Chapters with Custom Bitrate

Combine all top-level subdirectories in /home/user/audiobooks/book/ into a single audiobook, with each subdirectory treated as a separate chapter. Files are processed recursively in alphabetical order, with audio encoded at 96 kbps:

m4bify --chapters-from-dirs --bitrate 96k /home/user/audiobooks/book

Bulk Conversion with Default Settings

Convert all subdirectories in /home/user/audiobooks/ to M4B format using default settings. The process utilizes 50% of available CPU cores:

m4bulk /home/user/audiobooks

Bulk Conversion with Custom Threads and Bitrate

Convert audiobook directories in /home/user/audiobooks/ with 4 worker threads. Each subdirectory is treated as a chapter, and audio is encoded at 128 kbps:

m4bulk --workers 4 -d -b 128k /home/user/audiobooks

Contributing

Contributions, bug reports, and feature requests are welcome! Feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Thanks to the creators of ffmpeg and mp4v2 for their excellent tools that make this project possible.

About

A set of bash scripts to convert audio files into M4B audiobooks with chapter markers, customizable bitrate, book metadata and embedded cover art.

Topics

Resources

License

Stars

Watchers

Forks