HardCoding/Coding
mp3 tag v1 and v2
싸이on
2009. 3. 16. 15:01
MP3 테그를 수정할 일이 있어 작업 했던 내용을 정리한번 할까합니다.
뭐 특별한건 없고 다큐먼트 웹페이지가 있길래~~ 끄적끄적 카피해서 올려놓습니다. ㅅㅅ;;
TAG is name for data space in MP3 file where some text informations (song name, artist, album...) can be stored.
is old and simple. It takes always 128 Bytes at the very end of file (after the last audio frame).
Structure:
Bytes | Length | Content | ||
0-2 | 3 | Tag identifier. Must contain "TAG" string if Tag is valid. | ||
3-32 | 30 | Song Name | ||
33-62 | 30 | Artist | ||
63-92 | 30 | Album | ||
93-96 | 4 | Year | ||
97-126 | 30 | Comment | ||
127 | 1 | Genre |
126. Byte can also be used as the number of song. Items should be padded with NULL (ASCII 0) or with a space (ASCII 32).
Values for Genre are predefined, you can find them eg. in WinAmp. Only the most important ones:
22 | Death Metal | |
138 | Black Metal | |
144 | Thrash Metal | |
9 | Metal | |
43 | Punk | |
129 | Hardcore |
Problems with TAG v1 are obvious: you can store only a few items (you have a bad luck for eg. country of an artist, used codec, author of lyric...) and there is only a limited space for items (you also have a bad luck if song name has more than 30 chars).
But despite that is TAG v1 commonly used by most of "MP3 release" groups.
is newer, bigger and uncut. And... much more complicated.
Is placed at the very beginning of file (before all audio frames).
Structure:
TAG v2 contains of header and frames (dont mismatch it with audio frames and their headers!!!).
Header (10 Bytes)
Bytes | Content | |
0-2 | TAG identifier. It contains of string "ID3" | |
3-4 | TAG version. Can be eg. 03 00 | |
5 | Flags | |
6-9 | Size of TAG |
Flags Byte has this structure (in bits):
abc00000
where the first 3 bits indicate Unsynchronization, Extended header and Experimental indicator.
Flags normally dont have special meaning, can be set to 00.
Size of TAG is encoded into 4 Bytes. But not to be so easy, the most significant bit in each Byte is set to 0 and ignored. Only remaining 7 bits are used. The reason is to avoid mismatch with audio frame header which has the first synchro Byte FF).
Eg. TAG len 257 is encoded as 00 00 02 01.
Size of TAG doesnt contain header itself so total lenght of previous TAG is 257 + 10 Bytes.
Frames
Each frame is used for storing one information - eg. Artist or Album.
Frame consists of header and body.
Header(10 Bytes)
Bytes | Content | |
0-3 | Frame identifier | |
4-7 | Size | |
8-9 | Flags |
Frame identifier consist of four characters. There are many predefined values you can use. But eg. current version of WinAmp displays only these ones:
Iden. | Description | |
TRCK | Track number | |
TENC | Encoded By | |
WXXX | URL | |
TCOP | Frame identifier | |
TOPE | Original Artist | |
TCOM | Composer | |
TCON | Genre | |
COMM | Comments | |
TYER | Year | |
TALB | Album | |
TPE1 | Artist | |
TIT2 | Song name |
You can freely define you own frame, eg. with identifier "CUNT" but you cant expect thet some player will be able to diaplay that. Anyway you can store any information into MP3 file without limits.
Size is stored from the most significant Byte to the least. It doesnt include frame header, so total length of frame is Size + 10. Warning: After the header always one Byte with value 00 follows and then begins frame body. Size has to include this Byte.
Flags in most cases are set to 00 00. But they have this structure (in bits):
abc00000 ijk00000 //why they are not stored in one Byte???
Flag | Description | |
a | TAG alter preservation | |
b | File alter preservation | |
c | Read only | |
i | Compression | |
j | Encryption | |
k | Grouping identity |
Example of frame:
54 | 50 | 45 | 31 | 00 | 00 | 00 | 07 | 00 | 00 | 00 | 53 | 53 | 6C | 61 | 79 | 65 | 72 |
T | P | E | 1 | 7 | S | l | a | y | e | r |
To be even more complicated, some frames can have special structure. Eg. COMM (comments) aslo contains language version which is not normally displayed:
43 | 4F | 4D | 4D | 00 | 00 | 00 | 0C | 00 | 00 | 00 | 65 | 6E | 67 | 00 | 63 | 6F | 6D | 6D | 65 | 6E | 74 |
C | O | M | M | 0C | e | n | g | c | o | m | m | e | n | t |
For TCON (genre or style) you can use predefined values as in TAG v1. Then frame body looks like "(144)Thrash Metal" and the number corresponds with TAG v1. Or you can simply write your own style and then body is "Brutal Black" and is stored like normal frame body.
Complete description of TAG v2 you can find here.