I've been following this answer to use ffmpeg
to convert and play some of my Audible audio-books in LinuxMint. Each book is a single source-file, but I've noticed that ffmpeg
lists all the chapters at the start of conversion.
Is there a way to get ffmpeg
to split the the book into chapters – convert each chapter into separate files (split by chapters)? Preferably by ffmpeg
alone, but using other programs/scripts (together with ffmpeg
) is also an option…
(I've seen a few other answers about splitting DVDs into chunks of even lengths or into chapters (using ffmpeg
and a python-script), but that's not quite what I'm after, so I'm hoping it was a simpler way of doing it…)
Best Answer
I've been doing exactly this myself recently: as Nemo commented above - ffprobe gives you a json file with the chapter start and ends easily using the command...
ffprobe -i fileName -print_format json -show_chapters
If you add
-sexagesimal
to the command it creates a slightly more human readable output IMO and the output can be redirected to a file for later processing.FFmpeg needs a little help so I also used jg and AtomicParsley - the former to parse the JSON file, the latter to add images and metadata to the resultant m4b file.
The script also supports outputting with an m4a file, or conversion to mp3 as required - simple call it with the parameters $1 - input file and (optionally) $2 output type - defaults to m4b.
Using that as a basis I created the following script...
If desired you can edit the JSON file (.dat file) as Audible files just name the chapters "Chapter 1", "Chapter 2", etc.
for eg. initially the first part of the file might read...
By simply changing the relevant line to...
"title": "Introduction"
will change the resultant split file.