Audiobook transcoding notes
Baltakateiʼs notes for transcoding Audiobooks.
Stats
Commands
Create a copy of the audiobook mp3 files
$ dir="/tmp/zasni/5/" $ mkdir -p "$dir" $ cd "$dir" $ cp ~/1869..War_and_Peace/*.mp3 "$dir"/ $ ls -1 "$dir" How To - Track 001.mp3 How To - Track 002.mp3 How To - Track 003.mp3 (...) How To - Track 030.mp3 How To - Track 031.mp3 How To - Track 032.mp3
Create a Bash script named make_list.sh
to generate a file list parsable by ffmpeg
#!/bin/bash fout="mylist.txt"; while read -r line; do printf "file '%s'\n" "${line#./}" >> "$fout"; done < <(find . -type f -name "*.mp3" | sort);
Run the bash script make_list.sh
$ /bin/bash make_list.sh
Concatenate and save the mp3 files as a lossless, but large, WAV file:
$ ffmpeg -f concat -safe 0 -i mylist.txt output.wav
- If ffmpeg reports the output WAV file is too large, add the
-rf64 auto
option to use a non-standard WAV format that supports larger files.[1]:
$ ffmpeg -f concat -safe 0 -i mylist.txt -c:a pcm_s24le -rf64 auto output.wav
Convert the WAV file to a 32 kbps opus file[2]:
$ ffmpeg -i output.wav -c:a libopus -b:a 32k output.opus
Note: the output.opus
file is what I ended up saving since the ogg container mentioned later suffered playback issues due to how the album artwork was saved as a single video frame.
Alternatively, concatenate the multiple mp3 files into WAV format via a stdout/stdin pipe (no need to store a large file) to a second simultaneous ffmpeg operation that converts the WAV data into OPUS format which is written to disk.
$ ffmpeg -f concat -safe 0 -i mylist.txt -c:a pcm_s24le -rf64 auto -f wav - | \ ffmpeg -i - -c:a libopus -b:a 32k output.opus
Extract album artwork from one of the original audiobook mp3 files.
$ ffmpeg -i How\ To\ -\ Track\ 001.mp3 -an -vcodec copy album_artwork.png
Add album artwork and output to an ogg container.
$ ffmpeg -i output.opus -i album_artwork.png -map 0:a -map 1:v -c:a copy -q:v 10 output.ogg
History
- 2023: BK-2020-03: Baltakatei wrote a Bash script to automated the conversion of a directory of mp3 files into an opus audio track of a single mkv file. The script is saved in
BK-2020-03/user/mp3s_to_mkv.sh
and is run as:mp3s_to_mkv.sh [DIR IN] [DIR OUT] [BITRATE]
. Baltakatei found a bitrate of48k
(48kbps) for the audio track is sufficient for audiobooks.
See also
- Wikipedia:Audiobook transcoding notes
- libro.fm: DRM-free audiobooks
External links
References
- ↑ llogan. (2020-02-07). “Enable RF64”. SuperUser.com. Accessed 2023-03-26. Archived from the original on 2023-03-26.
- ↑ Chance, Adam. (2013-12-05). “How to encode audio with Opus codec?”. superuser.com. Accessed 2023-03-26. Archived from the original on 2022-07-04.
Footnotes