Batch convert m4b to m4a with ffmpeg
I buy a ton of audiobooks. I needed to batch-convert my collection of .m4b
audiobooks to .m4a
. I typically use OpenAudible to download the audiobooks I buy on Audible. It's nice to be able to vector search transcripts with NotebookLM when I know the general concept but need a quick refresher. Unfortunately, NotebookLM doesn't support .m4b
files, so conversion was necessary.
Luckily, converting files using ffmpeg
is straightforward with just a couple of shell tricks. Two key insights make this smooth:
-
Explicitly mapping only the audio stream (
-map 0:a
) avoids issues with any stray video or metadata streams. -
Simple shell loops or the
find
command paired with a loop ensure robust processing, even with nested directories or tricky filenames.
Quick and simple for flat directories
Here's the minimal one‑liner if all your files are in the same folder:
for file in *.m4b; do
ffmpeg -i "$file" -map 0:a -acodec copy "${file%.m4b}.m4a"
done
Robust command for nested directories and special characters
If your audiobook collection includes nested directories or filenames with special characters, combining find
and a while
loop is safer:
find . -name '*.m4b' | while IFS= read -r file; do
ffmpeg -i "$file" -map 0:a -acodec copy "${file%.m4b}.m4a"
done
Explanation:
find . -name '*.m4b'
searches the current directory and all subdirectories for.m4b
files.while IFS= read -r file
safely handles spaces and special characters in filenames.-map 0:a
instructsffmpeg
to ignore everything except the audio stream.-acodec copy
enables a fast, lossless stream copy, skipping re-encoding.
Key takeaways:
- Always use
-map 0:a
for audio-only conversions to prevent unwanted re-encoding attempts. - Choose a
find
andwhile
loop approach for complex directory structures or filenames. - Stream copying (
-acodec copy
) ensures quick conversions without quality loss.
With this approach, you can breeze through hundreds of audiobooks