Let's imagine we have a lot of mp3 files ( forexample one of the pluralsite courses converted to mp3 ).
URL=https://www.pluralsight.com/courses/run-effective-meetings
PASS=pass
USER=user
OUTPUT="%(playlist_index)s. %(title)s-%(id)s.%(ext)s"
youtube-dl --username $USER --password $PASS -o $OUTPUT --extract-audio --audio-format mp3 $URL
Once you have a list of files we can start converting it first by combining all mp3 into one, and then converting it to m4a/m4b format.
ls | grep "mp3" | awk '{printf "file |%s|\n", $0}' | sed -e "s/|/\'/g" > list.txt \
&& ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp3 \
&& ffmpeg -i output.mp3 output.m4a \
&& mv output.m4a output.m4b
I wanted to convert multiple mp3 files to a single m4b, and ran into a lot of problems. What finally worked for me in the end was something like this:
Step 1, turn each chapter into its own m4b file. In my case the files where named e.g. "Ch 1a", "Ch 1b", ..., "Ch 2a", etc. So for each chapter I created a input file matching the ffmpeg "concat" format, and then ran the following ffmpeg invocation in order to turn every handful of mp3s to a single m4b. The
-vn
flag is used to strip away the album art (I'll be adding it back in the last step, but it had the wrong dimensions here which made ffmpeg refuse to work with it).Step 2, create a metadata file that describes every chapter. I did this by running
ffprobe
on all of the output files from the previous step, and calculated the correct start and end positions for every chapter. This file is saved asbook.meta
. I also have the album art saved asbook.jpg
.ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "book-001.m4b"
Step 3, stitch it all together. I created a final "concat" file (
book.txt
) which contains one line per created m4b file from step 1. Then used the following ffmpeg invocation to turn it into a single file:In order to actually do this, I used the following small Node.js script: