How do I use ffmpeg to convert audible files I'm running ffmpeg v2.8.1 from Homebrew, and trying to convert Audible files but there's some trick I"m missing.

This command produces this error output.

ffmpeg -activation_bytes 1CEB00DA -i Volume1.aax -vn -c:a copy output.mp4

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc9a4010600] [aax] file checksum == d72f1f04e3c73d0bc68e742db1bc69b58dc3a500
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc9a4010600] [aax] mismatch in checksums!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc9a4010600] error reading header
Volume1.aax: Invalid data found when processing input


I know the file is ok, because it plays in iTunes. I does have the file image/cover art embedded in it as well,

From the ffmpeg docs, I read
Audible AAX files are encrypted M4B files, and they can be decrypted by specifying a 4 byte activation secret.

I'm presuming - probably incorrectly - that the one given is ok. If not, how does one find that secret.
First run these commands:

brew install chromedriver ffmpeg
sudo easy_install pip
pip install selenium requests
git clone https://github.com/inAudible-NG/audible-activator
cd audible-activator
sed -i '' 's,chromedriver_path = "./chromedriver",chromedriver_path = "/usr/local/bin/chromedriver",' audible-activator.py
./audible-activator.py


Then enter your Audible username and password and wait for a while for the eight character activation key to be printed.

If you do not run the sed command that changes the value of the chromedriver_path variable, ./audible-activator.py results in an error like 'chromedriver' executable needs to be in PATH even if chromedriver is on the path or in the audible-activator directory. If your sed is GNU sed, replace sed -i '' with sed -i.

After that run a command like this:

ffmpeg -activation_bytes youractivationkey -i input.aax -c copy output.m4b


(I edited the command above based on the comments by LiWang and marcus erronius to replace output.m4a;mv output.m4{a,b} with output.m4b and to replace -vn -c:v copy with -c copy.)

If you try to use the ffmpeg command above with an aa file instead of an aax file, it results in an error like Option activation_bytes not found. To download a book from Audible as aax instead of aa, choose "Enhanced" from the "Audio Quality" dropdown in the view for downloading a book.

aax files are encrypted mp4 / m4a / m4b files so the ffmpeg command above does not re-encode audio and it preserves metadata such as chapters. mp4, m4a, and m4b are alternative filename extensions for the MPEG-4 Part 14 container format. The m4a and m4b extensions were originally introduced by Apple. One difference between the m4a and m4b extensions is that the option to remember the previous playback position in iTunes is enabled by default for files with an m4b extension but not for files with an m4a extension. iTunes also displays files with an m4b extension under audiobooks by default.

Old versions of iTunes did not have the checkbox to enable remembering the previous playback position, but remembering the previous playback position was always enabled for files with an m4b extension, so even Wikipedia still incorrectly states that "an .m4a audio file cannot "bookmark" (remember the last listening spot), whereas .m4b extension files can." (Even though I don't know if there are still other media players which behave like old versions of iTunes in that respect.)

The UTI for the m4b extension is com.apple.protected-mpeg-4-audio and Finder shows the kind of all m4b files as "protected MPEG-4 audio" even though all files with an m4b extension do not have copy protection.