An .m4a file is an MPEG-4 file (see the MP4
container page). Boxes hold everything: each is a 32-bit big-endian size, then a
four-byte type, then the content. This page covers the parts specific to AAC audio and
its tags. The AAC frames themselves are stored in mdat without ADTS headers,
one raw data block to a sample, and the
sample tables in moov say where each starts.
File type
The file starts with an ftyp box: a 4-byte major brand, a 4-byte minor
version and any number of 4-byte compatible brands. Brands seen on these files:
| Brand | Meaning |
|---|---|
M4A␠ | audio-only MPEG-4 (the last byte is a space) |
M4B␠ | audiobook, an audio file with chapters |
M4P␠ | protected audio, as once sold by the iTunes Store |
mp42, isom | the generic MP4 brands, which also appear as compatible brands |
The mp4a sample entry
In the track, at moov/trak/mdia/minf/stbl/stsd, the sample entry for AAC has
the type mp4a. All values are big-endian:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | size | the size of this box |
| 4 | 4 | type | mp4a |
| 8 | 6 | reserved | 0 |
| 14 | 2 | data reference index | which entry of dref |
| 16 | 8 | reserved | 0 |
| 24 | 2 | channel count | |
| 26 | 2 | sample size | 16 |
| 28 | 2 | pre-defined | 0 |
| 30 | 2 | reserved | 0 |
| 32 | 4 | sample rate | a 16.16 fixed-point number |
| 36 | varies | esds box | see below |
The channel count and sample rate here can disagree with the AudioSpecificConfig; the latter is the one to trust.
The esds box
esds is a full box: its first 4 bytes are the version (0) and flags (0).
Its content is a tree of MPEG-4 descriptors. Each descriptor is a 1-byte tag and an
expandable length: 1 to 4 bytes in which the top bit of each byte means another length
byte follows and the low 7 bits are data.
| Tag | Descriptor | Fields |
|---|---|---|
03 | ES_Descr | ES_ID (2 bytes), a flags byte (bit 7 stream dependence, bit 6 URL flag, bit 5 OCR stream flag, bits 4–0 stream priority), then the optional fields those flags call for, then the DecoderConfigDescr and SLConfigDescr |
04 | DecoderConfigDescr | objectTypeIndication (1 byte, below), a byte holding streamType (6 bits, 5 = audio), upStream (1 bit) and a reserved 1, bufferSizeDB (3 bytes), maxBitrate (4), avgBitrate (4), then DecSpecificInfo |
05 | DecSpecificInfo | the AudioSpecificConfig, usually 2 to 5 bytes |
06 | SLConfigDescr | one byte, 02, meaning the predefined MP4 layout |
| objectTypeIndication | Meaning |
|---|---|
40 | MPEG-4 Audio: the AudioSpecificConfig says which object type |
66 | MPEG-2 AAC Main |
67 | MPEG-2 AAC LC |
68 | MPEG-2 AAC SSR |
69 | MPEG-2 audio (ISO/IEC 13818-3) |
6B | MPEG-1 audio (ISO/IEC 11172-3) |
An example
A typical AAC LC esds:
00 00 00 00 version and flags
03 19 ES_Descr, 25 bytes
00 02 00 ES_ID 2, flags 0
04 11 DecoderConfigDescr, 17 bytes
40 15 MPEG-4 Audio, stream type 5, upstream 0, reserved 1
00 18 00 bufferSizeDB
00 01 F4 00 maxBitrate 128,000
00 01 F4 00 avgBitrate 128,000
05 02 DecSpecificInfo, 2 bytes
12 10 AAC LC, 44,100 Hz, stereo
06 01 SLConfigDescr, 1 byte
02 predefined MP4