Skip to content

Xaenyr/Audiobook_PowerShell_Tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Audiobook PowerShell Tools

Three scripts for managing audiobook libraries, powered by FFmpeg.

Script Purpose
Convert-AudioBooks.ps1 Batch-converts MP3 folders into single M4B files
Clean-M4B.ps1 Batch-creates clean copies of existing M4B files
normalise_m4b.py Batch-normalizes M4B volume levels

Requirements

  • Windows 10 or later
  • PowerShell 5.1 or later (included with Windows 10) — for .ps1 scripts
  • Python 3.x — for normalise_m4b.py
  • FFmpeg installed and available in your system PATH

Installation

  1. Download or clone this repository
  2. Place the script(s) you need in your audiobook library's root folder

Usage

PowerShell scripts: Right-click any .ps1 script and select Run with PowerShell.

If Windows blocks script execution, open PowerShell and run:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Then run the script again.

Python script: Double-click normalise_m4b.py, or run it from a terminal:

python normalise_m4b.py

Convert-AudioBooks.ps1

Batch-converts audiobook folders containing MP3 files into single M4B files, preserving chapter markers, cover art, and metadata tags.

Features

  • Converts entire audiobook libraries in one run
  • Preserves chapter structure (one chapter per MP3 file, named from ID3 tags)
  • Extracts and embeds cover art from MP3 tags
  • Copies metadata tags (title, author, year, genre, comment) to the M4B file
  • Reproduces the source folder structure in the output/ folder
  • Skips already-converted books on subsequent runs — safe to interrupt and resume
  • Handles filenames with spaces, accents, and apostrophes

Folder structure

The script expects the following structure, where each book has its own folder containing MP3 files:

My Audiobooks/               ← root folder (place the script here)
  Convert-AudioBooks.ps1
  Standalone/
    Book1/
      01.mp3
      02.mp3
    Book2/
      01.mp3
  Series1/
    Book3/
      01.mp3
  Series2/
    Book4/
      01.mp3

The script will create an output/ subfolder next to itself and reproduce the same structure with M4B files:

My Audiobooks/
  output/
    Standalone/
      Book1.m4b
      Book2.m4b
    Series1/
      Book3.m4b
    Series2/
      Book4.m4b

Notes

  • MP3 files within each book folder are sorted alphabetically before being concatenated
  • Audio is re-encoded to AAC at 64 kbps, which is standard quality for spoken word content
  • If a book has no cover art embedded in its MP3 tags, the M4B is created without a cover
  • If a chapter title tag is missing, the MP3 filename is used as the chapter name instead

Clean-M4B.ps1

Batch-creates clean copies of existing M4B files using FFmpeg's stream copy mode (-c copy). Useful when a M4B has a non-standard internal structure that prevents tools like Mp3tag from opening it in write mode.

Features

  • Processes entire audiobook libraries in one run
  • Reproduces the source folder structure in the clean/ folder
  • Skips already-processed files on subsequent runs — safe to interrupt and resume
  • Handles filenames with spaces, accents, and apostrophes
  • Removes partial output files on error to avoid leaving corrupted files behind

Folder structure

Place the script next to your M4B files:

My Audiobooks/               ← root folder (place the script here)
  Clean-M4B.ps1
  Standalone/
    Book1.m4b
    Book2.m4b
  Series1/
    Book3.m4b

The script will create a clean/ subfolder and reproduce the same structure:

My Audiobooks/
  clean/
    Standalone/
      Book1.m4b
      Book2.m4b
    Series1/
      Book3.m4b

Notes

  • No audio re-encoding — stream copy only, so the process is fast and lossless
  • Original files are never modified

normalise_m4b.py

Batch-normalizes the volume of M4B files to a consistent loudness level (-17 LUFS, roughly equivalent to the 89 dB MP3Gain target). Useful when audiobooks from different sources have inconsistent volume levels.

Additional requirement

Install ffmpeg-normalize via pip before first use:

pip install ffmpeg-normalize

Features

  • Processes all M4B files in the same folder as the script in one run
  • Skips files already prefixed with 89db_ — safe to run multiple times
  • Outputs normalized files with a 89db_ prefix, leaving originals untouched
  • Appends a timestamped entry to a cumulative normalise_m4b.log file for each run
  • Logs all warnings and errors from ffmpeg-normalize
  • Handles filenames with spaces, accents, and apostrophes

Folder structure

Place the script directly in the folder containing the M4B files to normalize:

My Audiobooks/
  normalise_m4b.py
  Book1.m4b
  Book2.m4b
  Book3.m4b

After running, normalized files appear in the same folder:

My Audiobooks/
  normalise_m4b.py
  normalise_m4b.log
  Book1.m4b
  Book2.m4b
  Book3.m4b
  89db_Book1.m4b
  89db_Book2.m4b
  89db_Book3.m4b

Notes

  • Audio is re-encoded to AAC — this is unavoidable for M4B volume normalization
  • The loudness target (-17 LUFS) can be adjusted by editing the LUFS variable at the top of the script
  • The output prefix (89db_) can also be changed via the PREFIXE variable
  • Files that exceed the target true peak automatically fall back to dynamic normalization mode; this is expected behavior for spoken word content and produces correct results

License

MIT License — free to use, modify, and redistribute.

About

PowerShell script to batch-convert MP3 audiobook folders to M4B and tool to clean m4b

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors