在播放歌曲的时候,在播放器上显示的“标题”、“专辑”、“演唱者”等信息,这些可以让听众更好地了解歌曲。这些信息通常都是来自于音频文件自身存储的ID3信息里。
通常ID3位于MP3文件中,到目前为止有两个版本ID3v1和ID3v2,其中ID3v2里有若干个子版本,现在仍然能在很多音频文件中看到ID3v1版本的信息。
ID3使用已经很广泛了,至今没有国际统一的ID3规范标准发布,协议本身成了开发者约定的标准。
ID3官网:http://id3.org/
ID3最初是由Eric Kemp在1996年发明的,当时MP3音频很流行了,Kemp在MP3文件尾部加入了一些数据,这就是后的ID3v1。当时的播放器不知道ID3信息,避免播放器把带有ID3信息的音频文件判断为“损坏”或者“无效”的文件,只能加到尾部了。后来播放器都识别ID3信息了,就没有这个问题了。但是标记在文件尾部也会造成一个问题,那就是如果还没有读到文件末尾,什么信息也看不到。对硬盘和闪存里面的歌曲这当然不是问题,但是如果通过流媒体方式直接在网络上收听,就会发现它的缺陷了
ID3v1
Song Title | 30 characters |
Artist | 30 characters |
Album | 30 characters |
Year | 4 characters |
Comment | 30 characters |
Genre | 1 byte |
其中Album是专辑信息。
ID3v1.1
ID3v1扩展
Header | 4 byte | 扩展标志,即“TAG+” |
Song Title | 60 byte | “TAG+”并不覆盖“TAG”中的信息,而是在前述的基础上进行合并扩展,也就是一共有30+60字节用于标题描述,以下的扩展也是类似的。 |
Artist | 60 byte | 演唱者信息 |
Album | 60 byte | 专辑信息 |
Speed | 1 byte | 速度,0=unset, 1=slow, 2=medium, 3=fast, 4=hardcore |
Genre | 30 byte |
|
Start Time | 6 byte | 格式mmm:ss |
End Time | 6 byte | 格式mmm:ss |
ID3v2
到1998年,ID3v2出现,和ID3v1相比,在所描述的信息以及采用的数据记录格式等多个方面都有改动。- 数据存储位置差异
- 数据长度大小可变
- 文本编码格式
ID3v2 Header
ID3v2/file identifier "ID3" // 三个字节固定,表明是ID3v2版本 ID3v2 version $03 00 // 两个字节,十六进制,主版本好,和修正版本号 ID3v2 flags %abc00000 // 一个字节,二进制,是否有同步或者是压缩 ID3v2 size 4 * %0xxxxxxx // 4个字节,用于整个Tag的大小(包括padding,但不包括头部10个字节),最大可以到256M。例如257个字节长的Tag,$00 00 02 01
Bit 7 in the 'ID3v2 flags' indicates whether or not unsynchronisation is used (see section 5 for details); a set bit indicates usage.
The second bit (bit 6) indicates whether or not the header is followed by an extended header. The extended header is described in section 3.2.
ID3v2 extended header
ID3v2 Frames
Frame ID $xx xx xx xx (four characters) Size $xx xx xx xx Flags $xx xx
The frame ID is followed by a size descriptor, making a total header size of ten bytes in every frame. The size is calculated as frame size excluding frame header (frame size - 10).
In the frame header the size descriptor is followed by two flags bytes. These flags are described in section 3.3.1.
%abc00000 %ijk00000
-
a - Tag alter preservation
-
This flag tells the software what to do with this frame if it is unknown and the tag is altered in any way. This applies to all kinds of alterations, including adding more padding and reordering the frames.
0 Frame should be preserved. 1 Frame should be discarded.
b - File alter preservation
-
This flag tells the software what to do with this frame if it is unknown and the file, excluding the tag, is altered. This does not apply when the audio is completely replaced with other audio data.
0 Frame should be preserved. 1 Frame should be discarded.
c - Read only
- This flag, if set, tells the software that the contents of this frame is intended to be read only. Changing the contents might break something, e.g. a signature. If the contents are changed, without knowledge in why the frame was flagged read only and without taking the proper means to compensate, e.g. recalculating the signature, the bit should be cleared. i - Compression
-
This flag indicates whether or not the frame is compressed.
0 Frame is not compressed. 1 Frame is compressed using [#ZLIB zlib] with 4 bytes for 'decompressed size' appended to the frame header.
j - Encryption
-
This flag indicates wether or not the frame is enrypted. If set one byte indicating with which method it was encrypted will be appended to the frame header. See section 4.26. for more information about encryption method registration.
0 Frame is not encrypted. 1 Frame is encrypted.
k - Grouping identity
-
This flag indicates whether or not this frame belongs in a group with other frames. If set a group identifier byte is added to the frame header. Every frame with the same group identifier belongs to the same group.
0 Frame does not contain group information 1 Frame contains group information