Repository navigation
feat: Read and write Audible .aa and .aax metadata - #145
Merged
Merged
Conversation
decriptor
force-pushed
the
feat/audible
branch
from
November 21, 2026 19:25
88300f4 to
edc1dfd
Compare
decriptor
force-pushed
the
feat/audible
branch
from
November 21, 2026 20:30
edc1dfd to
d64b0db
Compare
decriptor
force-pushed
the
fix/mp4-gnre
branch
from
November 21, 2026 20:50
f0c5ecc to
78d0591
Compare
decriptor
force-pushed
the
feat/audible
branch
2 times, most recently
from
November 21, 2026 21:31
9c8aad4 to
faca4e6
Compare
Owner
Author
|
Review: 0 findings at faca4e6. The last review round (at 9c8aad4) found only two non-blocking items, and both are fixed here: the history is folded so every commit builds and passes, and the PR body is current. What was checked:
|
decriptor
force-pushed
the
feat/audible
branch
from
November 21, 2026 22:30
faca4e6 to
f17572f
Compare
There is no published specification for .aa. The container layout follows the prose description on MultimediaWiki and was checked byte by byte on three real files and against ffprobe. AudibleFile reads the header and table of contents, the text dictionary (AudibleTag), the cover chunk, and the duration (audio chunk size in bits over the bit rate the codec key names). A save rewrites only the dictionary: every later table-of-contents offset, the whole-file entry, the declared file size, and the cover's image position move by the change in its size, and every other byte, including the encrypted audio, is copied unchanged. An unchanged save is byte-identical. SetValue refuses the keys the player needs to decrypt the audio and Clear keeps them. MediaFile detects .aa by the magic at offset 4 or by extension, and maps .aax to MP4.
Audible .aax files are MPEG-4 with brand 'aax '. Mp4Tag and Mp4File gain Narrator (©nrt), ShortTitle (@sti), ParentTitle (@pti), ParentShortTitle (@pst), ParentProductId (@ppi), ProductId (prID), ReleaseDate (rldt), and ProductVersion (VERS). The '@' codes are a literal 0x40. The names match what ExifTool reports for each code. The eight codes join Mp4AtomMapping's tag atoms, so they are read from a file, replaced rather than duplicated on a set, and written through a udta-namespace key in an mdta meta. CDEK, CDET, AACR, and GUID stay unmapped and are carried through a save. An 'aavd' sample entry, which keeps AAC in the mp4a layout with encrypted samples, now reports AAC.
…ring A save updated the cached table of contents only when its path equalled SourcePath ordinally. A save through another spelling of the source path (dir/./x.aa, another case on a case-insensitive file system) rewrote the source but kept the old layout, so the next save failed. After a save, the source's own header and TOC are now read back. When they match what was written, that layout is adopted. A source that another writer replaced meanwhile is still refused.
Each test feeds an input that only one bound stops: a chunk or the whole-file entry moved or grown past 32 bits, a declared size that leaves 32 bits, a dictionary over the cap, a cover chunk inside the TOC, a cover position inside its own header, and a source replaced by another writer. The overflow check is now a single offset-plus-size bound; neither value can go below zero.
… test The edited-save check compared every byte after the dictionary, so it failed on a complete .aa whose cover position correctly moved with the cover chunk. It now expects that one field to move by the size change.
The README, the package README, the CHANGELOG, the AudibleFile remarks, and the migration guide now say that edited .aa files were checked with ffprobe, ffmpeg, and ExifTool but not with Audible's own apps, which may check a digest the file stores, and advise keeping a copy. The package description and tags name Audible, the package README lists Matroska and Audible, and the migration guide notes where TagLib# maps .aa keys differently.
The read-back of the source's header ran after the atomic rename and used the caller's token, so a cancel that landed after the commit threw from SaveToFileAsync although the new file was on disk, and the stale layout made the next save fail. The read-back now ignores the token, and any failure while reading back, sync or async, only skips the refresh.
decriptor
force-pushed
the
feat/audible
branch
from
November 21, 2026 22:45
f17572f to
f3c80a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds Audible audiobook support.
.aa: newAudibleFile/AudibleTag(MediaFormat.Audible,TagTypes.Audible). Reads the header, table of contents, text dictionary, cover chunk, and duration. Writes the dictionary..aax: it is MPEG-4 (ftypbrandaax). It stays on the MP4 reader..aaxis now also mapped to MP4 by extension.Mp4TagandMp4Filegain the Audible item atoms as named properties. Anaavdsample entry now reports AAC.Decryption and activation are out of scope. The audio payload, including ciphertext, is copied byte for byte.
Motivation and Context
Closes #110
Clean room and sources
No ISO or vendor specification exists for
.aa. I did not read TagLib#, ffmpeg (aadec.c) or any other GPL/LGPL implementation. The layout comes from two sources:.aafiles (hexdump + a small Python dump script), cross-checked againstffprobe -show_format -show_streamson the same files.For
.aaxatom codes, the sample cannot help:second.aaxis cut at 10 KiB insidemoov/trak/mdia/minf/stbl/stsz, beforeudta, so it has noilst(box dump below). The codes and names come from running ExifTool as a black box (exiftool -listx -QuickTime:all, ItemList table). I then confirmed each one round-trips by writing it with TagLibSharp2 into a syntheticaaxfile and reading it back withexiftoolandffprobe..aalayout, field by field (all integers big-endian)0x002edc5f= TOC entry 0 size = end of entry 11 (0x2eb486 + 0x27d9). The samples are truncated to 10240 bytes, so the declared size is larger than the file.0x57907536{u32 type, u32 offset, u32 size}u32 count, thencount × {u8 0x00, u32 keyLen, u32 valueLen, key, value}. No terminators. Keys are ASCII, values UTF-8.TAG:lines. ffprobe hidescodec,HeaderSeed, andHeaderKey, and cutslong_descriptionat 128 chars.0, 0x415, 0x82a, …, which start at 0, so no absolute positions. Copied unchanged.u32 imageLength, u32 filePosition (the next byte), imageDuration = chunk 10 size × 8 / bit rate, with the bit rate taken from the
codeckey. This matches ffprobe to the microsecond on all three files:Sample rate and channels: acelp16 is 16000 Hz mono and mp332 is 22050 Hz, both as ffprobe reports. For acelp85, ffprobe reports
sample_rate=8500, which is its bit rate. I report 8000 Hz, the sampling rate of the ACELP.net 8.5 kbit/s mode. MP3 channels are reported as 0 (unknown) because they live only inside the encrypted payload. ffprobe also reportschannels=0.Design decisions
SetValuethrowsArgumentExceptionforcodec,HeaderSeed,HeaderKey, andEncryptedBlocks.Clear()removes only the descriptive keys (title, author, narrator, provider, price, dates, descriptions, keywords, copyright, short and parent titles). Identifiers, licensing keys, and unknown keys stay.title. Artist andAuthor→author.Narrator,Provider,PublishDate(rawpubdate). Year is the year ofpubdate; setting it keepsDD-MON-. Description→description.LongDescription,Keywords, Copyright (raw, may contain©),ShortTitle,ParentTitle,ParentShortTitle,ProductId,TitleId, read-onlyCodec. Every key is reachable by name throughGetValue/SetValue/Keys. Album, Comment, Genre, and Track have no key in the format: they return null and ignore a set, the same no-op as the baseTag.Pictures.IPicture(MIME from magic bytes). Rewriting it would change the size of the last chunk, and I have no real file with a cover chunk to check that against. The cover chunk is kept unchanged, and its position field moves with the chunk.ScanWithoutAudioTests(1 MiB payload, sync and async)..aaxnames follow ExifTool, and theAudibleTagnames where they overlap:Narrator©nrt,ShortTitle@sti,ParentTitle@pti,ParentShortTitle@PST,ParentProductId@ppi,ProductIdprID,ReleaseDaterldt,ProductVersionVERS.@is a literal 0x40.CDEK/CDET/AACR/GUIDhave no known meaning (ExifTool calls three of themUnknown_*). They get no property, but the ilst fix keeps them across saves.Out of scope, and risks
The README, package README, CHANGELOG,
AudibleFileremarks, and migration guide now carry the same caution: edited.aafiles were checked with ffprobe, ffmpeg, and ExifTool, not with Audible's own apps. Keep a copy, or save to a new path.Decryption, activation, and checksum validation. I don't know what the
68ec733412b9key (a 40-hex digest) or chunk 3's 40 opaque bytes cover. If Audible's own player checks a digest over the dictionary, an edited.aacould be refused by that player, even though ffprobe and ffmpeg read it. I cannot test that without the player.Chunks 7 to 9 are past the end of every sample, so I cannot prove they hold no absolute file offsets. Chunk 3 (seen whole) and chunk 6 (seen in part) hold only sizes and offsets relative to the audio.
Writing the cover, and chapters (chunk 6 has the per-chapter sizes).
second.aaxdoes not open. Itsmoovis cut off insidestsz, and ffprobe also rejects it ("contradictionary STSC and STCO … error reading header"). Making the MP4 reader accept a truncatedmoovwould change MP4 behaviour in general and is not part of this issue. The env-gated.aaxtest reports Inconclusive for that file. It passes on a complete syntheticaaxfile.Testing
Gates
dotnet build -c Release: 0 warnings, 0 errors (netstandard2.0, netstandard2.1, net8.0, net10.0, plus the tests, benchmarks, and examples).dotnet test -c Release(on top of fix: Read MP4 gnre and keep unedited ilst atoms #133 ee9e7ec): net8.0 4867 passed, 15 skipped, 0 failed. net10.0 4867 passed, 15 skipped, 0 failed. The skips are env-gated integration tests.dotnet format --verify-no-changes: clean.dotnet list package --vulnerable --include-transitive: none.dotnet teston net10.0, each checked in a detached worktree on fix: Read MP4 gnre and keep unedited ilst atoms #133's head ee9e7ec: 4842 → 4867 passed, 15 skipped, 0 failed.Real files (taglib-sharp
samples/audible/)The env-gated tests
AudibleIntegrationTests(TAGLIBSHARP2_TEST_AA,TAGLIBSHARP2_TEST_AAX) ran locally on net8.0 and net10.0 with each.aafile: 5/5 pass for first, third, and fourth.For each
.aa: read, an unchanged render, then a save that changed title (to a non-ASCII value), narrator, and year, and addedcustom_key.cmp)ffmpeg -v error -i out -f null -pubdate=20-JAN-2012,custom_key; duration 2853.849412 (unchanged)A synthetic full-length
.aawas built from first.aa's chunks plus a 64×64 JPEG cover in chunk 11. TagLibSharp2 reads the cover. After a save, ffprobe reads the new tags and the same duration (8.022588 s), the cover position equals the new chunk offset + 8, the image bytes and audio chunk are identical, and the header size equals the file length..aax:second.aaxbox dump:ftyp(aax, compatibleaax M4B mp42 isom), thenmoov(487335 bytes declared, file 10240),mvhd,trak,tkhd,edts,tref/chap,mdia,mdhd,hdlr,minf,stbl,stsd(anaavdentry holdingesdswith object type 0x40),stts,stsc, andstsz, where it is cut off. There is noudta. A syntheticaaxfile (ffmpeg … -brand "aax ", sample entry renamedmp4a→aavdas in the sample) was tagged with all eight Audible properties through TagLibSharp2. ExifTool then reportsNarrator,ShortTitle,ParentTitle,ParentShortTitle,ParentProductID,ProductID,ReleaseDate, andProductVersionwith the written values. ffprobe reads it asaac/aavd, themdatpayload is byte-identical,ffmpeg -v error … -f null -is clean, and TagLibSharp2 reads every value back.Unit tests
AudibleFileTests: dictionary mapping; duration for each codec, including the first.aa size against ffprobe's value; cover parsing and rejection of a bad cover position or length; reading a truncated file; every prefix shorter than the dictionary end fails without throwing; wrong magic, bad TOC count, missing or overlapping dictionary, bad entry counts and lengths; 2000 random mutations never throw; path, stream, unseekable-stream, and async reads agree; detection by magic and extension;.aax→MP4; an MP4 named.aastays MP4; dispose.AudibleRoundTripTests: unchanged render is byte-identical (including invalid UTF-8 and non-ASCII keys, and bytes after the last entry); every chunk past the dictionary moves by Δ and keeps its bytes; the cover position moves; truncated-file save; a chunk that would be split, or data from another file, fails the save;Clearkeeps the DRM keys; sync and async save to the source twice, to another path, from bytes, and from a stream without a path.AudibleTagTests: every property round-trips under its key; the unmapped fields; Year; SetValue position and duplicates; protected and invalid keys; IsEmpty; every truncation of the dictionary; the exact rendered bytes.Mp4AudibleAtomTests: exact atom codes (0x40 vs 0xA9), theMp4Fileforwarders, one item after a set on a file that has it,CDEK/CDET/AACR/GUIDcarried through a save, the Audible atoms round-tripping through a QuickTime keyed (mdta) meta, theaaxbrand, andaavd→AAC.MalformedInputTestsandScanWithoutAudioTestsinclude Audible.I reverted each guard to check that a test fails: cover-position patch, whole-file entry resize, the layout update after a save to the source,
aavd, the dictionary/TOC overlap check, the DRM-key guard,Clear's key list, and magic detection. Every revert turned at least one test red.Type of Change
Checklist
dotnet test)Unreleased, README format list and tag table, MIGRATION-FROM-TAGLIB)Review round 1
gnre/©cpy/keyed items beside a set value0e394f9and88300f4were dropped5d4d942: after a save, read the source's own header and TOC back and adopt them when they match what was written9038b738294c5a92f9f4e8294c5aBefore/after (old head 6aa1db2, new head): over 568 corpus files plus a QuickTime-keys file, 10 read answers changed, all intended. Genre now comes from
gnreon 9 files, and Copyright from©cpyon 4 of them; each genre matches ffprobe and ExifTool. The keyed title is now read on the QuickTime-keys file. Setting Genre, Copyright, and Title on all 36 MP4s now gives single values in ffprobe, where the old head gaveAcid Punk;Jazz,M4A copyright;New (c), andT;rv-title.mdatis byte-identical in every save. ffmpeg decode output is the same as for the originals.Review round 2
git rebase --onto origin/fix/mp4-gnre origin/main). Dropped this PR's own MP4 commits: the ilst-item parser change (cfaa62f) and the alias/keys work (0e394f9,88300f4). fix: Read MP4 gnre and keep unedited ilst atoms #133 covers them. Their CHANGELOG entries were removed here (88af1ec) and are to be added to fix: Read MP4 gnre and keep unedited ilst atoms #133's CHANGELOG, where the code lives; 88af1ec's message wrongly says fix: Read MP4 gnre and keep unedited ilst atoms #133 already documents them.Mp4AtomMapping's tag-atom list is read from its payload, so that line became redundant and was removed when the history was squashed.edc1dfd): the read-back after the atomic rename no longer sees the caller's token, and any read-back failure only skips the layout refresh. Pinned by SaveToFileAsync_CancelledAfterTheCommit_ReturnsTheWriteAndCanSaveAgain and SaveToFile_SourceHeaderReadFailsUnexpectedly_StillSucceeds.Review round 3
78d0591, which is now on main 85ce8d2. fix: Read MP4 gnre and keep unedited ilst atoms #133 owns all the MP4 keys/mdta and legacy-alias handling, along with their CHANGELOG entries.[Unreleased], the Audible lines sit in### Addednext to fix: Read MP4 gnre and keep unedited ilst atoms #133's QuickTime-keys entry, and main's and fix: Read MP4 gnre and keep unedited ilst atoms #133's### Fixedentries are kept.git merge-treeagainstorigin/mainand againstfix/mp4-gnreboth report no conflicts.Mp4AtomMapping's tag-atom list. fix: Read MP4 gnre and keep unedited ilst atoms #133 reads every tag atom from its payload, and resolvesudta-namespace keys in mdta metas through that list.d64b0db:Review round 4
feat: Map the Audible .aax atoms on MP4(b97971c), so the Audible properties land together with their codes. This usedgit rebase -idriven by aGIT_SEQUENCE_EDITORscript that adds fixup and exec lines. The redundantContainerBoxesline is gone, and the PR no longer touchesMp4BoxParser.cs. Every commit is green (see Gates). The head tree differs from the round-3 head only by that removed line.Mp4AudibleAtomTestscases (4 UnnamedAudibleItem rows, RoundTripUnderTheirExactCodes, InAQuickTimeKeyedMeta_RoundTrip, SetOnAFileThatHasIt_LeavesOneItem), plus fix: Read MP4 gnre and keep unedited ilst atoms #133's EveryProperty_IsWrittenAsAKeyedItem and EveryMappedAtom_IsReadAndReplacedWithItsTwin.VERSturns 4 red: AudibleAtoms_RoundTripUnderTheirExactCodes, AudibleAtoms_InAQuickTimeKeyedMeta_RoundTrip, EveryProperty_IsWrittenAsAKeyedItem, and EveryMappedAtom_IsReadAndReplacedWithItsTwin.ee9e7ec, a fast-forward fromeb1a4ccand78d0591, still on main 85ce8d2. The only conflicts were in CHANGELOG.md: the Audible lines stay after fix: Read MP4 gnre and keep unedited ilst atoms #133's QuickTime-keys entry. The diff against fix: Read MP4 gnre and keep unedited ilst atoms #133 is Audible code, the Audible MP4 properties,aavd, the eight tag-atom codes, and docs. Every commit is green. The gates and env-gated tests pass as above.