Search code examples
pythonmp3id3

How to unpack ID3 header's size


I am trying to unpack the ID3v2.3 header with Python 2.7. However, I do not fully understand the first 10 bytes of the MP3 format. For example:

49 44 33 03 00 00 | 00 00 21 76 | 54 41 4C 42
.I .D .3 .3 .0    | RawSize     | Size

Using Synalyze it! I can see that RawSize is 0x2176 and Size is 4342.

At offset 4352 is where the MPEG data frames begin. I need to know how 54 41 4C 42 gets converted to 4342 because when I tried:

>>> unpack('i', '\x54\x41\x4C\x42')
(1112293716,)

which does not look in anyways like 4352!

How should I read them in general?


Solution

  • Firstly, you give 14 bytes there, not 10.

    Secondly, you've botched reading the size completely. The size uses unpacked 7-bit values rather than 8-bit values.

    >>> 0x00 << 21 | 0x00 << 14 | 0x21 << 7 | 0x76
    4342