mp3文件格式
ID3V2 包含了作者,作曲,专辑等信息,长度不固定,扩展了ID3V1 的信息量。
Frame 一系列的帧,个数由文件大小和帧长决定
ID3V1 包含了作者,作曲,专辑等信息,长度为128BYTE。
校验值长度为2 个字节,紧跟在FRAMEHEADER 后面,接着就是帧的实体数据了,格式如下:
FRAMEHEADER
CRC(free)
MAIN_DATA
4 BYTE
0 OR 2 BYTE
长度由帧头计算得出
Byte Content
0-3 Standard audio frame header (as descripted above). Mostly it contains values FF
FB 30 4C, from which you can count FrameLen = 156 Bytes. And thats exactly enough
space for storing VBR info.
This header contains some important information valid for the whole file:
-MPEG (MPEG1 or MPEG2)
-SAMPLING rate frequency index
-CHANNEL (JointStereo etc.)
4-x Not used till string “Xing” (58 69 6E 67). This string is used as a main VBR file
identifier. If it is not found, file is supposed to be CBR. This string can be placed
at different locations according to values of MPEG and CHANNEL (ya, these from a
few lines upwards):
36-39 “Xing” for MPEG1 and CHANNEL != mono (mostly used)
21-24 “Xing” for MPEG1 and CHANNEL == mono
21-24 “Xing” for MPEG2 and CHANNEL != mono
13-16 “Xing” for MPEG2 and CHANNEL == mono
After “Xing” string there are placed flags, number of frames in file and a size
of file in Bytes. Each of these items has 4 Bytes and it is stored as ”int” number
in memory. The first is the most significant Byte and the last is the least.
Following schema is for MPEG1 and CHANNEL != mon
40-43 Flags
Value Name Description
00 00 00 01 Frames Flag set if value for number of frames in file is stored
00 00 00 02 Bytes Flag set if value for filesize in Bytes is stored
00 00 00 04 TOC Flag set if values for TOC (see below) are stored
00 00 00 08 VBR Scale Flag set if values for VBR scale are stored
All these values can be stored simultaneously.
44-47 Frames
Number of frames in file (including the first info one)
48-51 Bytes
File length in Bytes
52-151 TOC (Table of Contents)
Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately
solves problem with moving inside file.
Each Byte has a value according this formula:
(TOC[i] / 256) * fileLenInBytes
So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000
000 Bytes length) you can use:
TOC[(60/240)*100] = TOC[25]
and corresponding Byte in file is then approximately at:
(TOC[25]/256) * 5000000
If you want to trim VBR file you should also reconstruct Frames, Bytes and TOC
properly.
152-155 VBR Scale
I dont know exactly system of storing of this values but this item probably doesnt
have deeper meaning.
typedef struct tagID3V1{char Header[3]; /*标签头必须是"TAG"否则认为没有标签*/char Title[30]; /*标题*/char Artist[30]; /*作者*/char Album[30]; /*专集*/char Year[4]; /*出品年代*/char Comment[28]; /*备注*/char reserve; /*保留*/char track;; /*音轨*/char Genre; /*类型*/}ID3V1,*pID3V1;
ID3V1 的各项信息都是顺序存放,没有任何标识将其分开,比如标题信息不足30 个字节,则使用””
补足,否则将造成信息错误。Genre使用原码表示,对照表如下:
/* Standard genres */
0=”Blues”;
1=”ClassicRock”;
2=”Country”;
3=”Dance”;
4=”Disco”;
5=”Funk”;
6=”Grunge”;
7=”Hip-Hop”;
8=”Jazz”;
9=”Metal”;
10=”NewAge”;
11=”Oldies”;
12=”Other”;
13=”Pop”;
14=”R&B”;
15=”Rap”;
16=”Reggae”;
17=”Rock”;
18=”Techno”;
19=”Industrial”;
20=”Alternative”;
21=”Ska”;
22=”DeathMetal”;
23=”Pranks”;
24=”Soundtrack”;
25=”Euro-Techno”;
26=”Ambient”;
27=”Trip-Hop”;
28=”Vocal”;
29=”Jazz+Funk”;
30=”Fusion”;
31=”Trance”;
32=”Classical”;
33=”Instrumental”;
34=”Acid”;
35=”House”;
36=”Game”;
37=”SoundClip”;
38=”Gospel”;
39=”Noise”;
40=”AlternRock”;
41=”Bass”;
42=”Soul”;
43=”Punk”;
44=”Space”;
45=”Meditative”;
46=”InstrumentalPop”;
47=”InstrumentalRock”;
48=”Ethnic”;
49=”Gothic”;
50=”Darkwave”;
51=”Techno-Industrial”;
52=”Electronic”;
53=”Pop-Folk”;
54=”Eurodance”;
55=”Dream”;
56=”SouthernRock”;
57=”Comedy”;
58=”Cult”;
59=”Gangsta”;
60=”Top40″;
61=”ChristianRap”;
62=”Pop/Funk”;
63=”Jungle”;
64=”NativeAmerican”;
65=”Cabaret”;
66=”NewWave”;
67=”Psychadelic”;
68=”Rave”;
69=”Showtunes”;
70=”Trailer”;
71=”Lo-Fi”;
72=”Tribal”;
73=”AcidPunk”;
74=”AcidJazz”;
75=”Polka”;
76=”Retro”;
77=”Musical”;
78=”Rock&Roll”;
79=”HardRock”;
/* Extended genres */
80=”Folk”;
81=”Folk-Rock”;
82=”NationalFolk”;
83=”Swing”;
84=”FastFusion”;
85=”Bebob”;
86=”Latin”;
87=”Revival”;
88=”Celtic”;
89=”Bluegrass”;
90=”Avantgarde”;
91=”GothicRock”;
92=”ProgessiveRock”;
93=”PsychedelicRock”;
94=”SymphonicRock”;
95=”SlowRock”;
96=”BigBand”;
97=”Chorus”;
98=”EasyListening”;
99=”Acoustic”;
100=”Humour”;
101=”Speech”;
102=”Chanson”;
103=”Opera”;
104=”ChamberMusic”;
105=”Sonata”;
106=”Symphony”;
107=”BootyBass”;
108=”Primus”;
109=”PornGroove”;
110=”Satire”;
111=”SlowJam”;
112=”Club”;
113=”Tango”;
114=”Samba”;
115=”Folklore”;
116=”Ballad”;
117=”PowerBallad”;
118=”RhythmicSoul”;
119=”Freestyle”;
120=”Duet”;
121=”PunkRock”;
122=”DrumSolo”;
123=”Acapella”;
124=”Euro-House”;
125=”DanceHall”;
126=”Goa”;
127=”Drum&Bass”;
128=”Club-House”;
129=”Hardcore”;
130=”Terror”;
131=”Indie”;
132=”BritPop”;
133=”Negerpunk”;
134=”PolskPunk”;
135=”Beat”;
136=”ChristianGangstaRap”;
137=”HeavyMetal”;
138=”BlackMetal”;
139=”Crossover”;
140=”ContemporaryChristian”;
141=”ChristianRock”;
142=”Merengue”;
143=”Salsa”;
144=”TrashMetal”;
145=”Anime”;
146=”JPop”;
147=”Synthpop”;
联系客服