mp3binaryfilesfile-formatid3lame

How to read an MP3 file, separating metadata from audio?


I understand that the MP3 file format essentially consists of two segments, id3 metadata+audio frames. How can I read in binary form, all of the id3 segment and all of the audio frames as two binary blobs? I'm looking to simply perform a hash calculation on the metadata and the audio as two separate units in a file. How can I determine where the "split point" is in the file?


Solution

  • From the ID3 tag specification:

    +-----------------------------+
    |      Header (10 bytes)      |
    +-----------------------------+
    |       Extended Header       |
    | (variable length, OPTIONAL) |
    +-----------------------------+
    |   Frames (variable length)  |
    +-----------------------------+
    |           Padding           |
    | (variable length, OPTIONAL) |
    +-----------------------------+
    | Footer (10 bytes, OPTIONAL) |
    +-----------------------------+
    

    Note that there are several ID3 tag versions out there.

    Specification: http://www.id3.org/id3v2.4.0-structure