MP3 File Structure Overview
Layer-3 audio files, MPEG (movingpicture Experts Group) in Chinese translation into the active image of the expert group, especially the active video compression standard, MPEG audio file is the MPEG1 standard sound part, also called the MPEG Audio layer, It is divided into three layers according to the compression quality and coding complexity, namely Layer-1, Layer2, Layer3, and corresponding to MP1, MP2, MP3 Three kinds of sound files, and according to different uses, use different levels of coding. The higher the level of MPEG audio coding, the more complex the encoder, the higher the compression rate, the compression rate of MP1 and MP2 is 4:1 and 6:1-8:1 respectively, and the MP3 compression rate is up to 10:1-12:1.
The MP3 file is broadly divided into three parts: Tag_v2 (ID3v2), audio data, TAG_V1 (ID3V1), where ID3v2 is a supplement to ID3v1, not all MP3 have ID3v2 supplements, that is, not all MP3 files have ID3v2. ID3v2
If the MP3 file exists ID3v2, it must be in the head of the file, the ID3V2 structure is divided into the head (header) and a number of label frames, where the head length is 10 bytes, 10 byte structure as table 1:
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
Content is "ID3" |
Version number |
Sub-version number |
Bytes holding the flag |
ID3v2 total size (sum of several label frames after the frame header and after) |
Table 1
Since the meaning of 3, 4, 5 bytes is not the focus of MP3 decoding, it only explains the first three bytes and the last four bytes:
From table 1 can be seen to determine whether the MP3 file exists ID3v2, only need to determine whether the first three bytes of the file is "ID3";
ID3v2 Data size Calculation company:
Total_size = (size[0]&0x7f) *0x200000+ (size[1]&0x7f) *0x400 + (size[2]&0x7f) *0x80 + (Size[3]&0x7F) |
where Size[0~3], respectively, is the 6~9 byte in table 1. It should be noted that the length of the company's calculations does not include the 10-byte head of ID3v2.
ID3v2 several label frames after the head each frame structure is divided into the label ID (4 bytes), the frame content size (4 bytes, excluding the label frame header), the holding flag bit (2 bytes), the content. Where the label ID has the following meanings:
TEXT: Lyrics author Tenc: encoded Wxxx:url link (URL) TCOP: Copyright (Copyrights) TOPE: original artist Tcom: Composer Tdat: Date TPE3: Conductor TPE2: Orchestra TPE1: Artist equals ID3v1 artist TPE4: Translator (recorder, modifier) Tyer: ID3v1 's year USLT: Lyrics tsiz: Size Talb: Album equivalent to ID3v1 album TIT1: Content Group description TIT2: Title equivalent to ID3V1 title TIT3: subtitle TCON: Genre (Style) equivalent to ID3v1 's genre Aenc: Audio encryption technology TBPM: Number of beats per minute Comm: note equivalent to id3v1 comment tdly: Playlist Trck: Track (song) equivalent to ID3v1 Tflt: File Type: Time TKEY: First keyword Tlan: language TLEN: Length tmed: Media type Toal: Original album tofn: Original file name TOLY: Original lyric author TORY: Year of initial release TOWM: File owner (license holder) TPOS: Folio section Tpub: Issuer Trda: Recording date Trsn:intenet Station name Trso:intenet station owner UFID: Unique file identifier TSRC:ISRC (International standard Record Code) Tsse: Software used for encoding (Hardware setup) |
The functions to read the MP3 file ID3v2 information are as follows:
Defining head and label frames typedef |