Home > Blockchain >  How do I read song meta information from an m4a file?
How do I read song meta information from an m4a file?

Time:07-17

I have code that reads ID3 tags from an mp3 file, but now I have some m4a files. I found some info on the structure of these files, but that doesn't mention ID3 tags.

What's the best resource for m4a file structure?

Is the song metadata in the m4a structure, or in the contained audio file (which appears to be AAC)?

CodePudding user response:

https://docs.fileformat.com/audio/m4a/ has some details

https://github.com/ahyattdev/M4ATools has example code

The song meta data is in nested m4a chunks.

CodePudding user response:

M4A is just a filename extension - it still remains an MP4 container. Which consists of atoms/boxes (not chunks). The best resource is usually the documentation of the vendor himself, followed by experts with long experience, followed by additional details, followed by simplified explanations:

Strictly by standard only the (MP4) container should have the overall metadata and any of the streams inside should not be searched for metadata. However, don't rely on this, and don't ignore potentially valuable metadata that can be in any/all of the streams (video, audio, subtitles, pictures...). Containers are like archives: they contain one or more files - and for each file you're back at where you began, because you have to recursively analyze that file again. AAC is by far not the only possible audio stream/codec - you could also run across an MP3 in an MP4 container.

ID3 can occur in MP4 as atom ID32, as mentioned here, but this is rare and only allows version 2.x, not version 1.

Additionally to the formats own metadata atoms other metadata formats (not specifically aiming at music) can be embedded in the following atoms:

system atom UUID with value other atoms
XMP 0xBE 7A CF CB 97 A9 42 E8 9C 71 99 94 91 E3 AF AC XMP_ or xml or xmlc
Exif 0x05 37 cd ab 9d 0c 44 31 a7 2a fa 56 1f 2a 11 3e or
JpgTiffExif->JP2
exif or exfc
IPTC 0x33 c7 a4 d2 b8 1d 47 23 a0 ba f1 a3 e0 97 ad 38 or
0x09 a1 4e 97 c0 b4 42 e0 be bf 36 df 6f 0c e3 6f
8BIM 0x2c 4c 01 00 85 04 40 b9 a0 3e 56 21 48 d6 df eb
360fly 0xef e1 58 9a bb 77 49 ef 80 95 27 75 9e b1 dc 6f
ID3 v2.x ID32

Mostly the atoms in an MP4 have this layout:

- ftyp
- free
- mdat
  moov
  - mvhd
    udta
    - cprt
    trak
    - tkhd
      udta
      - cprt
      edts
      - elst
      mdia
      - mdhd
      - hdlr
        minf
        - smhd
        - hdlr
          dinf
          - dref
          stbl
          - stsd
          - stts
          - stsc
          - stsz
          - stco
            meta
            - hdlr (mdta)
            - mhdr
              keys
              - mdta
              - mdta
              - mdta...
            > ilst
                (size, index)
                - data (type, locale, value)
                - itif
                - name
            - udta
            > ctry
            > lang
    trak
  • Related