Optimized AAX-to-MP3 conversion
Audible is great, and the app is not bad, but I find Plex and other apps more attractive to use for audiobooks. Now, if only I could take my books home...
Added Bonus: pick your own choice of book covers!
Audible AAX/C formats
I didn't know much about this, until I found the KrumpetPirate/AAXtoMP3 tool that taught me the basics, so I quote that source here:
Audible uses the AAX file format to maintain DRM restrictions on their audio books and if you download your book through your library it will be stored in this format.
Downloading audible.com/library provides the same AAX files, and nothing else. There used to be an option to download lower quality files in a non-DRM format, which would only show when visiting the library from Linux, but that appears to have beem removed.
Worse yet, newer (upcoming?) AAXC files will be even harder to use in Linux:
The AAXC format is a new Audible encryption format, meant to replace the old AAX. The encryption has been updated, and now to decrypt the file the authcode is not sufficient, we need two "keys" which are unique for each audiobook. Since getting those keys is not simple, for now the method used to get them is handled by the package audible-cli, that stores them in a file when downloading the aaxc file. This means that in order to decrypt the aaxc files, they must be downloaded with audible-cli. Note that you need at least ffmpeg 4.4.
Prerequiste: activation_bytes
To decode the AAX files you need your own authentication
code, that comes from Audible. To obtain this string, I used
inAudible-NG/audible-activator
and saved the bytes in ~/.authcode to use later.
Performance comparison for short and long books
KrumpetPirate/AAXtoMP3 works very well so, for a while, this was the tool I used.
After a while, it started to bother me that the conversion
took a long time and only used 1 CPU core, all the time.
Having to convert a boatload of books and having a 12-core
CPU, I was motivated to create my aax2mp3
script to parallelize the encoding of chapters.
The performance diffences is thus most notable with long books, but there is quite a visible difference even with short books, e.g.
- How to Talk So Teens Will Listen and Listen So Teens Will Talk: 3 hrs and 18 mins is converted in half the time.
- Elantris, Tenth Anniversary Special Edition: 28 hrs and 42 mins is converted in a third of the time.
Performance of AAXtoMP3
Short book: 3h 18m converted in 3m 50s
$ time AAXtoMP3 \
HowtoTalkSoTeensWillListenandListenSoTeensWillTalk_ep7.aax
...
real 3m50.693s
user 3m58.307s
sys 0m13.704s
$ id3v2 -l Audiobook/Adele\ Faber\,\ Elaine\ Mazlish/How\ to\ Talk\ So\ Teens\ Will\ Listen\ and\ Listen\ So\ Teens\ Will\ Talk/How\ to\ Talk\ So\ Teens\ Will\ Listen\ and\ Listen\ So\ Teens\ Will\ Talk-01\ Chapter\ 1.mp3
id3v2 tag info for Audiobook/Adele Faber, Elaine Mazlish/How to Talk So Teens Will Listen and Listen So Teens Will Talk/How to Talk So Teens Will Listen and Listen So Teens Will Talk-01 Chapter 1.mp3:
TRCK (Track number/Position in set): 1
TPE1 (Lead performer(s)/Soloist(s)): Adele Faber, Elaine Mazlish
TPE2 (Band/orchestra/accompaniment): Adele Faber, Elaine Mazlish
TALB (Album/Movie/Show title): How to Talk So Teens Will Listen and Listen So Teens Will Talk
TYER (Year): 2005
TIT2 (Title/songname/content description): How to Talk So Teens Will Listen and Listen So Teens Will Talk-01 Chapter 1
TCON (Content type): Audiobook (255)
TCOP (Copyright message): ©2005 Adele Faber and Elaine Mazlish (P)2005 HarperCollins Publishers
TSSE (Software/Hardware and settings used for encoding): Lavf58.76.100
CTOC (): frame
CHAP (): frame
CHAP (): frame
APIC (Attached picture): (Album cover)[, 3]: image/png, 272335 bytes
Audiobook/Adele Faber, Elaine Mazlish/How to Talk So Teens Will Listen and Listen So Teens Will Talk/How to Talk So Teens Will Listen and Listen So Teens Will Talk-01 Chapter 1.mp3: No ID3v1 tag
Long book: 28h 42m converted in m s
$ time AAXtoMP3 \
ElantrisTenthAnniversarySpecialEdition_ep6.aax
...
real 47m11.226s
user 52m53.673s
sys 4m37.468s
$ id3v2 -l Audiobook/Brandon\ Sanderson/Elantris-Tenth\ Anniversary\ Special\ Edition/Elantris-Tenth\ Anniversary\ Special\ Edition*\ 1.mp3
id3v2 tag info for Audiobook/Brandon Sanderson/Elantris-Tenth Anniversary Special Edition/Elantris-Tenth Anniversary Special Edition-01 Chapter 1.mp3:
TRCK (Track number/Position in set): 1
TPE1 (Lead performer(s)/Soloist(s)): Brandon Sanderson
TPE2 (Band/orchestra/accompaniment): Brandon Sanderson
TALB (Album/Movie/Show title): Elantris: Tenth Anniversary Special Edition
TYER (Year): 2015
TIT2 (Title/songname/content description): Elantris-Tenth Anniversary Special Edition-01 Chapter 1
TCON (Content type): Audiobook (255)
TCOP (Copyright message): ©2005, 2015 Dragonsteel Entertainment, LLC (P)2015 Recorded Books
TSSE (Software/Hardware and settings used for encoding): Lavf58.76.100
CTOC (): frame
CHAP (): frame
CHAP (): frame
APIC (Attached picture): (Album cover)[, 3]: image/png, 615956 bytes
Audiobook/Brandon Sanderson/Elantris-Tenth Anniversary Special Edition/Elantris-Tenth Anniversary Special Edition-01 Chapter 1.mp3: No ID3v1 tag
Performance of aax2mp3
Short book: 3h 18m converted in 3m 50s
$ wget -O cover.jpg https://m.media-amazon.com/images/...jpg
$ time aax2mp3.sh \
HowtoTalkSoTeensWillListenandListenSoTeensWillTalk_ep7.aax
...
real 2m0.036s
user 4m21.804s
sys 0m4.618s
$ id3v2 -l 1.\ Chapter\ 1.mp3
id3v1 tag info for 1. Chapter 1.mp3:
Title : Chapter 1 Artist: Adele Faber, Elaine Mazlish
Album : How to Talk So Teens Will List Year: 2005, Genre: Vocal (28)
Comment: Track: 1
id3v2 tag info for 1. Chapter 1.mp3:
TSSE (Software/Hardware and settings used for encoding): LAME 64bits version 3.100 (http://lame.sf.net)
TIT2 (Title/songname/content description): Chapter 1
TPE1 (Lead performer(s)/Soloist(s)): Adele Faber, Elaine Mazlish
TALB (Album/Movie/Show title): How to Talk So Teens Will Listen and Listen So Teens Will Talk
TYER (Year): 2005
TRCK (Track number/Position in set): 1/10
TCON (Content type): Vocal (28)
TLEN (Length): 526419
APIC (Attached picture): ()[, 0]: image/jpeg, 51854 bytes
Long book: 28h 42m converted in m s
$ wget -O cover.jpg https://m.media-amazon.com/images/...jpg
$ time aax2mp3.sh \
ElantrisTenthAnniversarySpecialEdition_ep6.aax
...
real 14m37.037s
user 62m19.688s
sys 0m46.445s
$ id3v2 -l 1.\ Chapter\ 1.mp3
id3v1 tag info for 1. Chapter 1.mp3:
Title : Chapter 1 Artist: Brandon Sanderson
Album : Elantris: Tenth Anniversary Sp Year: 2015, Genre: Vocal (28)
Comment: Track: 1
id3v2 tag info for 1. Chapter 1.mp3:
TSSE (Software/Hardware and settings used for encoding): LAME 64bits version 3.100 (http://lame.sf.net)
TIT2 (Title/songname/content description): Chapter 1
TPE1 (Lead performer(s)/Soloist(s)): Brandon Sanderson
TALB (Album/Movie/Show title): Elantris: Tenth Anniversary Special Edition
TYER (Year): 2015
TRCK (Track number/Position in set): 1/79
TCON (Content type): Vocal (28)
TLEN (Length): 195651
APIC (Attached picture): ()[, 0]: image/jpeg, 89607 bytes
CPU usage of AAXtoMP3 and aax2mp3
Short book: 3h 18m converted in 3m 50s
Long book: 28h 42m converted in m s
Code
The gist of this is using xargs to parallelize the
extraction and encoding of individual chapters.
This would probably be better using
GNU parallel, but
I learned about that one a few months too late.
aax2mp3.sh
The main script aax2mp3.sh does most of the work.
Note
This script takes the activation codes from a
different file: ~/audible_activation_bytes
The --max-procs flag is set to only 10 so that a few
CPU cores are left for other tasks. In a pinch this value
can be increased to the number of CPU threads, if the
system won't be used by anybody in the meantime, to further
reduce the time it takes to encode chapters.
aax2mp3-chapter.sh
And to process each chapter, here is
aax2mp3-chapter.sh


