Home > Tutorials > A Quick Study on MP3 file structure

A Quick Study on MP3 file structure


Just had a little time playing around with MP3 file and found it quite interesting.

Do you like “New Divide” by Linkin Park, which is the Original Sound Track on Transformer 2: The Revenge of the Fallen? I personally like it very much. Ah right, Transformer 3 – Dark of the Moon is coming tomorrow, certainly I’ll watch it :D.

If you have the MP3 file of the song, on Windows Explorer right click on it and select Properties, open tab Details:

Windows Explorer: MP3 File Properties

Windows Explorer: MP3 File Properties

You can see its information like: Title, Artists, Album, Year, Genre, Length ….

Ok, try to open it using Mp3tag (v2.49):

MP3Tag - File Info View

MP3Tag - File Info View

The tag version of MP3 file is: ID3v2.3, which is basically derived from v1 and v2.3. Let’s have a look at the internal structure of ID3v1:

Internal layout of an ID3v1 tagged file.

Internal layout of an ID3v1 tagged file.

At the description at original page about ID3v1,

Song Title 30 characters
Artist 30 characters
Album 30 characters
Year 4 characters
Comment 30 characters
Genre 1 byte

If you one sum the the size of all these fields we see that 30+30+30+4+30+1 equals 125 bytes and not 128 bytes. The missing three bytes can be found at the very beginning of the tag, before the song title. These three bytes are always “TAG” and is the identification that this is indeed a ID3 tag. The easiest way to find a ID3v1/1.1 tag is to look for the word “TAG” 128 bytes from the end of a file. ” – Quoted from ID3.org

Another pages on MP3 internal:

+ http://www.multiweb.cz/twoinches/mp3inside.htm

+ http://www.fortunecity.com/underworld/sonic/3/id3tag.html

So we can easily extract any MP3 file tag information by parsing its very last 128 bytes (128 bytes at the end).

Once again, I open the song in a hex editor:

Hex Editor: MP3 Binary Format

Hex Editor: MP3 Binary Format

That’s right, the info is there!

Generally, instead of reading MP3 file header structure at beginning, we can use the very last 128 bytes to extract its basic info. Interesting, isn’t it?

We’re gonna make a library to query MP3 basic info using Java on Android in next article 🙂

Just take a cup of coffee and enjoy the song “….give me reason …. connect the space between …” , lol :))

 

Cheers,

Pete Houston

 

Categories: Tutorials Tags: , , , , ,
  1. February 2, 2016 at 2:35 pm

    Hi Pete,
    I am developing an application , which requires mp3 files to be stored in sdcard.
    I am changing its extension so that it cant be played directly in other players.
    I used conceal from facebook to encrypt/decrypt the song so that it cant even be played after renaming extension.

    Conceal is taking more than 500ms for 8mb file. it is a visible time for user.
    I want ton encrypt only header of mp3 file and decrypt it before playing. Is it possible , can you post code to extract header and encrypt decrypt it? .. Thanks in advance.

  1. No trackbacks yet.

Leave a comment