Repository navigation
Implement Main profile and additional ASC support; add SetAACDescriptorFromConfig - #657
Conversation
tobbee
left a comment
There was a problem hiding this comment.
Thanks, Monty! Parsing the full GASpecificConfig and the sync extensions is a real step forward. I ran the branch over every AAC esds in the FFmpeg FATE suite and in the mp4ff test data, decoding each config with both master and this branch:
- All 30 configs that the branch decodes re-encode to identical bytes. That includes SBR and PS signalled through sync extensions. Master gets those wrong and drops them on
Encode; it decodes138856e5a54880as plain LC, for example. - Keeping
frameLengthFlagis valuable too. 960-sample frames are used in DAB+ and DRM, butEncodecurrently always signals 1024.
There are a few things I'd like changed before merging, though.
1. Channel configuration 0 (PCE) is now an error
Eleven configs that decode on master fail on this branch with channel configuration zero requires an unsupported Program Config Element. For example:
al04_44.mp4:12000504002001e000al_sbr_ps_04_new.mp4:140006040000000056e5a8al22_chCfg0PCE_44.mp4:1200050c05200109440003ac042f
For these, master returns the object type, sampling frequency and channel configuration, and callers rely on that. The IAMF parser takes its sample rate from it, for example. Both AAC Main conformance streams in the suite also have a PCE (am00_88.mp4: 0880004400000000, and am05_44.mp4), so the branch doesn't decode them either.
Could you parse the program_config_element (ISO/IEC 14496-3, subpart 4)? The GA flags and sync extensions come after it, so it has to be parsed to reach them anyway. For Encode, either keeping the parsed fields or keeping the raw PCE bits would work. Note that the byte_alignment() before the PCE comment field is relative to the start of the AudioSpecificConfig. If a PCE parser is more than you want to take on now, please at least keep returning the header fields for channel configuration 0 instead of failing.
2. Trailing bits are rejected
The AudioSpecificConfig syntax only looks for a 0x2b7 sync extension when SBR isn't signalled explicitly and at least 16 bits remain. It only looks for 0x548 when sbrPresentFlag is 1 and at least 12 bits remain. Any other trailing bits are ignored. The branch rejects any trailing byte, so these configs decode on master but fail here:
121000: LC followed by a zero byte2b8a080000: explicit HE-AAC followed by a zero byte121056e5000000: a sync extension withsbrPresentFlag0, followed by zero bytes
I'd follow the spec conditions and ignore whatever is left over, including non-zero padding. On the encode side, setting PSSyncExtensionPresent with SBRPresentFlag false writes a 0x548 extension that no decoder reads, so validate could reject that combination.
3. Tests
Coverage of the aac package drops from 90.3% to 72.2%. Could you add table tests for the following?
- Main
frameLengthFlagdependsOnCoreCoderandCoreCoderDelay- sync-extension decode/encode roundtrips: SBR on and off, with and without PS
- PCE
- the
validateerror paths CoreSamplesPerFrameandSetAACDescriptorFromConfig
The hex strings above can serve as test vectors.
4. API behaviour changes
DecodeAudioSpecificConfignow reads its whole reader, so the reader must end where the config ends. That's fine for the callers in this repo, but it deserves a CHANGELOG line.- For an unsupported object type or a bad frequency index, it now returns
nilwhere master returned the partly decoded config. Either behaviour is OK with me, but it should be a deliberate choice: a caller that readsasc.ObjectTypeafter an error will now panic.
5. Small things
- The doc comment of
SetAACDescriptorWithChannelConfigstill lists only AAClc, HEAACv1 and HEAACv2. SetAACDescriptorFromConfigaccepts the reserved channel configurations 8–10 and 15, which gives a sample entry with channel count 0. Theaac.NrChannels(...) == 0check fromSetAACDescriptorWithChannelConfigwould fix that.- Please add a CHANGELOG entry under Unreleased and use a Conventional Commits title, such as
feat(aac): parse full GASpecificConfig and sync extensions, add AAC Main. We rebase-merge, so the commit message lands on master as written.
Finally, out of curiosity: what produces the AAC Main files you're seeing? Main is rare outside conformance streams, so a small sample would make a good test case if you can share one.
I wanted to reject something that wasn't known to be handled, rather than having it potentially fail silently. I'm not set up with good test case coverage, so I was a little wary of just implementing it.
I can certainly try, especially if you have the test samples. Otherwise, I'll go back and preserve your convention of returning what is understood.
AFAIK the trailing bytes aren't part of the ASC, and I'm used to the ASC needing to be clean (or god knows what random proprietary hardware will do). But that's hypothetical, I shouldn't be breaking working cases. I leaned pretty hard on Codex for the tests, and as far as I saw it had added coverage and I hadn't noticed that it altered success criteria. I'm not an AAC expert by any stretch (I'm on the opposing team ;-) and I need to trace all these things out by hand with the spec in front of me.
OK. My thinking is that with all the extensions and retcons, I needed to be sure what other fields could conditionally follow the ASC and parse those properly, and I've not gotten that far. I'll look a bit deeper at it.
I can do that.
Completely fair. That's a hard fail on me.
That is even more fair. I should have kept existing behavior. When I started coding, it was just for me, then I never went back and changed it.
Will fix.
Will fix. Editing error on my part when I rebased on your version of the SetAACDescriptorWithChannelConfig.
Will fix.
Right now I have absolutely no use for it! I needed ASC decode/encode to bolt various GCP services onto WebRTC. My thinking didn't go much farther than 'huh, I probably have everything I need now to turn on Main' which used to be more common at least in my memory. If I ever ran into it again, I wanted it to work, not page me when I was asleep. And that's it. If your verdict is 'yeah, no, not worth the extra surface' I'd completely understand. |
|
Thanks for the thorough answer, and for wading this far into AAC. PCE: A real parser would be best. All the samples are public in the FFmpeg FATE suite: These files have channel configuration 0 with a PCE: I understand the worry about silent misparsing. If you'd rather not take on the PCE now, a middle ground would be to decode channel configuration 0 as master does, returning the header fields without an error, but have Trailing bits: The DecoderSpecificInfo length is given in bytes, so the leftovers after the last field are formally part of the config. Decoders just ignore them, so rejecting them would break files that play fine today. Main: Let's keep it. Tests: The edits to the existing test cases follow from the intended behaviour changes, so they're fine. What's missing is new cases for the items listed in my review. Fork PRs need my approval before CI runs, so I'll approve the checks after your next push. No rush. |
896b5f8 to
38f425d
Compare
…n rules Completes PR Eyevinn#657 along its review: - Channel configuration 0 decodes its program_config_element (ISO/IEC 14496-3:2019 Table 4.2) into the new ProgramConfigElement, with the byte alignment before the comment field counted from the start of the AudioSpecificConfig, and Encode writes it back. The FATE suite configs with a PCE, including the AAC Main conformance streams am00_88 and am05_44, decode with the channel counts that ffprobe reports and re-encode byte for byte. - Sync extensions are only looked for under the conditions of Table 1.19: 0x2b7 if SBR is not signalled explicitly and at least 16 bits are left, then 0x548 if at least 12 bits are left. Unknown sync words, unknown extension object types and other leftover bits are ignored instead of rejected, so configs with trailing zero bytes, such as those of twofields_packet.mp4 and mov_stream_shorter_than_movie.mov, decode again. In the 2019 edition the 0x548 check is outside the sbrPresentFlag condition, so a PS sync extension after an SBR flag of 0 is read and written too. - Decode errors return the fields decoded so far, as master did for an unsupported object type or frequency index. Escaped object types are reported with their value, such as 39 for ER AAC ELD. - AudioSpecificConfig.NrChannels gives the channel count from the channel configuration or the PCE. SetAACDescriptorFromConfig uses it and rejects configs without channels, such as the reserved channel configurations 8-10 and 15. - Tests cover AAC Main, frameLengthFlag, the core coder delay, sync extensions with SBR on and off and with and without PS, PCEs, trailing bits, the validation errors, CoreSamplesPerFrame and SetAACDescriptorFromConfig. Coverage of aac goes from 90.3% on master to 95.6%. Of the 63 distinct AAC configs in the FATE suite, the 40 that master decodes still decode, and so do am00_88 and am05_44. 40 of these 42 re-encode byte for byte; the other two lose only trailing zero bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EagxH7ENAVwUPJWTRiw1wQ
Also add TrakBox.SetAACDescriptorFromConfig to create a sample entry from a full AudioSpecificConfig.
…n rules Completes PR Eyevinn#657 along its review: - Channel configuration 0 decodes its program_config_element (ISO/IEC 14496-3:2019 Table 4.2) into the new ProgramConfigElement, with the byte alignment before the comment field counted from the start of the AudioSpecificConfig, and Encode writes it back. The FATE suite configs with a PCE, including the AAC Main conformance streams am00_88 and am05_44, decode with the channel counts that ffprobe reports and re-encode byte for byte. - Sync extensions are only looked for under the conditions of Table 1.19: 0x2b7 if SBR is not signalled explicitly and at least 16 bits are left, then 0x548 if at least 12 bits are left. Unknown sync words, unknown extension object types and other leftover bits are ignored instead of rejected, so configs with trailing zero bytes, such as those of twofields_packet.mp4 and mov_stream_shorter_than_movie.mov, decode again. In the 2019 edition the 0x548 check is outside the sbrPresentFlag condition, so a PS sync extension after an SBR flag of 0 is read and written too. - Decode errors return the fields decoded so far, as master did for an unsupported object type or frequency index. Escaped object types are reported with their value, such as 39 for ER AAC ELD. - AudioSpecificConfig.NrChannels gives the channel count from the channel configuration or the PCE. SetAACDescriptorFromConfig uses it and rejects configs without channels, such as the reserved channel configurations 8-10 and 15. - Tests cover AAC Main, frameLengthFlag, the core coder delay, sync extensions with SBR on and off and with and without PS, PCEs, trailing bits, the validation errors, CoreSamplesPerFrame and SetAACDescriptorFromConfig. Coverage of aac goes from 90.3% on master to 95.6%. Of the 63 distinct AAC configs in the FATE suite, the 40 that master decodes still decode, and so do am00_88 and am05_44. 40 of these 42 re-encode byte for byte; the other two lose only trailing zero bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EagxH7ENAVwUPJWTRiw1wQ
38f425d to
4f33ac9
Compare
tobbee
left a comment
There was a problem hiding this comment.
I made some changes on top of yours, so that I could merge the PR. Thanks for the contribution.
|
Heya,
Didn't mean to let this sit-- it's just a bloody busy time at the day job. The patch itself was to facilitate something we needed, and I'd been putting off saying "I'll get to it, promise!" especially as you'd also taken the time to write back with a thoughtful and fairly deep review.
Is there anything remaining you'd like to be done with it, or have you more or less gotten it into the shape you wanted? At very least, I'll need to give a go soon at moving my code here onto your official release.
Monty
…________________________________
From: Torbjörn Einarsson ***@***.***>
Sent: Tuesday, November 3, 2026 8:10 AM
To: Eyevinn/mp4ff ***@***.***>
Cc: Montgomery, Christopher(AWF) ***@***.***>; Author ***@***.***>
Subject: Re: [Eyevinn/mp4ff] Implement Main profile and additional ASC support; add SetAACDescriptorFromConfig (PR #657)
External Email
Merged #657<#657> into master.
—
Reply to this email directly, view it on GitHub<#657?email_source=notifications&email_token=CCCILT5ELRC5A2I7CECGJVL5XHKLPA5CNFSNUABQM5UWIORPF5TWS5BNNB2WEL2JONZXKZKFOZSW45CON52GSZTJMNQXI2LPNYXTGNJQGIYTEMJUGE2DBJTSMVQXG33OUZQXK5DIN5ZKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#event-35021214140>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/CCCILT6D22WUEIQW7RG5MMT5XHKLPAVCNFSNUABFKJSXA33TNF2G64TZHMZDGNZSGU3TGMRWHNEXG43VMU5TKOJUGU2TCMBVGI22C5QC>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/CCCILT6P3LIAU5VAY4BGJHT5XHKLPA5CNFSNUABQM5UWIORPF5TWS5BNNB2WEL2JONZXKZKFOZSW45CON52GSZTJMNQXI2LPNYXTGNJQGIYTEMJUGE2DBJTSMVQXG33OUZQXK5DIN5ZKKZLWMVXHJKTGN5XXIZLSL5UW64Y> and Android<https://github.com/notifications/mobile/android/CCCILTY24LEYSYFMDWA56FD5XHKLPA5CNFSNUABQM5UWIORPF5TWS5BNNB2WEL2JONZXKZKFOZSW45CON52GSZTJMNQXI2LPNYXTGNJQGIYTEMJUGE2DBJTSMVQXG33OUZQXK5DIN5ZKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>. Download it today!
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
@montybay No problem, I've spent a lot of time (and especially tokens) on fixing all unstable/bad-input corners of mp4ff recently and wanted to make a release so I added what I wanted. |
Along the same lines as c94c23a, but going the rest of the way to fully parse the ASC and allow re-encoding it into a new stream. This was done to allow Main profile demux/remux.