Zhuowei Zhang on Nostr: I spent all morning trying to decode the Apple Positional Audio Codec (APAC)’s ...
I spent all morning trying to decode the Apple Positional Audio Codec (APAC)’s GlobalConfig from its MPEG4 Sample Description Box (stsd).
If you want to follow along:
the codec is in /System/Library/Frameworks/AudioToolbox.framework/AudioCodecs
See apac::GlobalConfig::Serialize and apac::GlobalConfig::Deserialize
If you need a sample file:
afconvert -o sound.m4a -d apac -f mp4f sound.wav
Or grab a sample file from
https://trac.ffmpeg.org/ticket/11480Pull the stsd from the m4a with mp4extract --payload-only moov/trak[0]/mdia/minf/stbl/stsd/apac sound.m4a sound_config.bin
The config starts after dapa then 4 0x00 bytes
First two bytes of the apac bitstream are 0x08 0x00 (see IsAPACBitstreamVersionValid / ACAPACBaseEncoder::GetMagicCookie)
followed by the GlobalConfig
Published at
2025-04-19 18:36:21 GMTEvent JSON
{
"id": "2c6690b09caa1e61cf952d7cd5eca8350aca66f17ab454e691170656d93221c0",
"pubkey": "c043dd0dc7eb1f350a58d13a3e6fd67cf6bb5bb56f81d8466d23e000c9222f1f",
"created_at": 1745087781,
"kind": 1,
"tags": [
[
"proxy",
"https://notnow.dev/objects/0684974f-9a04-4eca-9943-8982ef60ebee",
"activitypub"
],
[
"client",
"Mostr",
"31990:6be38f8c63df7dbf84db7ec4a6e6fbbd8d19dca3b980efad18585c46f04b26f9:mostr",
"wss://relay.mostr.pub"
]
],
"content": "I spent all morning trying to decode the Apple Positional Audio Codec (APAC)’s GlobalConfig from its MPEG4 Sample Description Box (stsd).\n\nIf you want to follow along:\n\nthe codec is in /System/Library/Frameworks/AudioToolbox.framework/AudioCodecs\nSee apac::GlobalConfig::Serialize and apac::GlobalConfig::Deserialize\nIf you need a sample file:\nafconvert -o sound.m4a -d apac -f mp4f sound.wav\nOr grab a sample file from https://trac.ffmpeg.org/ticket/11480\nPull the stsd from the m4a with mp4extract --payload-only moov/trak[0]/mdia/minf/stbl/stsd/apac sound.m4a sound_config.bin\nThe config starts after dapa then 4 0x00 bytes\nFirst two bytes of the apac bitstream are 0x08 0x00 (see IsAPACBitstreamVersionValid / ACAPACBaseEncoder::GetMagicCookie)\nfollowed by the GlobalConfig",
"sig": "b0a7880b1c6ac119ad498f061d19b46af3baa75780d4dadd263b9833cc0114f22d313327a5ed674668ae27cf609c2da6b7033a1c2b50d9d61700332ac64b53cd"
}