Friday, March 16, 2007

The MP3 ID3 Tag

Intro: ID3V2?
ID3 tags are blocks of data in mp3 that stores information about the song. It can be used to store anything from album names, performing artists, movie/album, genre, to jpg pictures containing the CD covers. ID3V2 is the second version of the ID3 tag on mp3. The following is about the ID3V2 structure.

ID3 Tags can be found anywhere in the mp3 file and there is no typical standard for its location. So how do we find it ?

ID3 Tags start with the 3 letters ID3 (what else?). All data in the ID3 Tags are BigEndian

ID3 Tag General Structure (ID3V2.4)
ID3 Tags can be imagines as a book, which contains many pages (called frames). Like any book, ID3 tag has a preface/intro about the tags that follows as a 10 byte header.

Header (10 bytes)
Extended Header (Variable) (optional)
Frames (Variable)
Padding (Variable) (optional)
Footer (10 bytes) (optional)

ID3 Header
ID3 Header is 10 bytes long.

ID:
Byte1 : I 0x49
Byte2 : D 0x44
Byte3 : 3 0x33

Byte4 : Major Version , Typically 2
Byte5 : Minor Version , (Latest 4)

Byte6 : Flag Byte [ABCD 0000]

Size:
Byte7 : Length of the ID3 Frames.
Byte8 :
Byte9 :
Byte10: 4 x 8 = 32 Bit Unsigned Long Integer.

The Equivalent C structure for the ID3 Tag Header is given below :

struct id3v2header
{
char id[3];
unsigned char majVer;
unsigned char minVer;
unsigned char flags;
unsigned long size;
};


The 8 bits on the flag have the following meaning

MSB
Bit8 : If SET indicates use of unsynchronization
Bit7 : If SET indicates presence of Extended Header
Bit6 : Experimental Bit
Bit5 : If SET indicates presence of Footer.
Bit4-Bit1 : Must be 0.
LSB

ID3 Footer Optional
ID3 is footer is same to that of the header except that the first 3 bytes contain 3DI instead of ID3.

ID3 Frames
Frames are like the pages of the book where the actual data is present.
As usually a frame starts with the Frame Header that describes the frame contents, like what the data following it is about.
Frame Header is 10 bytes long.

Frame ID : (4 characters long)
Byte1 : 0xXX
Byte2 : 0xXX
Byte3 : 0xXX
Byte4 : 0xXX

Size: (32 bit SynchSafe Integer)
Byte5 : MSB
Byte6 :
Byte7 :
Byte8 : LSB

Flags:
Byte9 :
Byte10:

The Equivalent C structure for the Frame Header is given below :

struct id3v2frameheader
{
char frameid[4];
unsigned long size;
unsigned char flag1;
unsigned char flag2;
};


The Frame ID stands for a combination of characters A-Z , 0-9 to make an abbreviation for the contents :
Here are some of the common Frame ID's :

AENC Audio encryption
APIC Attached picture
ASPI Audio seek point index
COMM Comments
COMR Commercial frame
ENCR Encryption method registration
EQU2 Equalisation
ETCO Event timing codes
GEOB General encapsulated object
GRID Group identification registration
LINK Linked information
MCDI Music CD identifier
MLLT MPEG location lookup table
OWNE Ownership frame
PRIV Private frame
PCNT Play counter
POPM Popularimeter
POSS Position synchronisation frame
RBUF Recommended buffer size
RVA2 Relative volume adjustment (2)
RVRB Reverb
SEEK Seek frame
SIGN Signature frame
SYLT Synchronised lyric/text
SYTC Synchronised tempo codes
TALB Album/Movie/Show title
TBPM BPM (beats per minute)
TCOM Composer
TCON Content type
TCOP Copyright message
TDEN Encoding time
TDLY Playlist delay
TDOR Original release time
TDRC Recording time
TDRL Release time
TDTG Tagging time
TENC Encoded by
TEXT Lyricist/Text writer
TFLT File type
TIPL Involved people list
TIT1 Content group description
TIT2 Title/songname/content description
TIT3 Subtitle/Description refinement
TKEY Initial key
TLAN Language(s)
TLEN Length
TMCL Musician credits list
TMED Media type
TMOO Mood
TOAL Original album/movie/show title
TOFN Original filename
TOLY Original lyricist(s)/text writer(s)
TOPE Original artist(s)/performer(s)
TOWN File owner/licensee
TPE1 Lead performer(s)/Soloist(s)
TPE2 Band/orchestra/accompaniment
TPE3 Conductor/performer refinement
TPE4 Interpreted, remixed, or otherwise modified by
TPOS Part of a set
TPRO Produced notice
TPUB Publisher
TRCK Track number/Position in set
TRSN Internet radio station name
TRSO Internet radio station owner
TSOA Album sort order
TSOP Performer sort order
TSOT Title sort order
TSRC ISRC (international standard recording code)
TSSE Software/Hardware and settings used for encoding
TSST Set subtitle
TXXX User defined text information frame

UFID Unique file identifier
USER Terms of use
USLT Unsynchronised lyric/text transcription

WCOM Commercial information
WCOP Copyright/Legal information
WOAF Official audio file webpage
WOAR Official artist/performer webpage
WOAS Official audio source webpage
WORS Official Internet radio station homepage
WPAY Payment
WPUB Publishers official webpage
WXXX User defined URL link frame

Reference from id3v2.4.0-frames.txt from id3.org


Frame Flags
Flag1 : Frame Status Flags
MSB:
Bit8 : Not Used Must be 0
Bit7 : If SET the Frame is discarded when a change in the TAG occurs.
Bit6 : If SET the Frame is discarded when the file is changed.
Bit5 : If SET indicates the tag is read-only and changing the contents may break some code.
Bit4 : Not Used Must be 0
Bit3 : Not Used Must be 0
Bit2 : Not Used Must be 0
Bit1 : Not Used Must be 0
LSB

Flag2 : Frame Format Flags
MSB
Bit8 : Not Used Must be 0
Bit7 : If SET indicates the presence of grouping information.
Bit6 : Not Used Must be 0
Bit5 : Not Used Must be 0
Bit4 : If SET the frame is compressed using zlib deflate method.
Bit3 : If SET the frame is encrypted, with descriptions in ENCR Frame.
Bit2 : If SET Frame has been unsynchronized.
Bit1 : If SET a data length indiciator is present.
LSB

That's All Folks
For more information visit,
» http://www.id3.org

0 comments: