ID3信息

在播放歌曲的时候,在播放器上显示的“标题”、“专辑”、“演唱者”等信息,这些可以让听众更好地了解歌曲。这些信息通常都是来自于音频文件自身存储的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

ID3v1记录的信息很简单,占有固定的128字节,以TAG字符开头。

ID3v1版本的标志,及“TAG”,它的后面就是以下的一系列信息:

Song Title

30 characters

Artist

30 characters

Album

30 characters

Year

4 characters

Comment

30 characters

Genre

1 byte


其中Album是专辑信息。
Genre是流派信息。其中流派一共定义了79种,流行的播放软件Winamp则把它扩展到了125种,从Blues到Noise到Dance Hall,非常丰富,在许多支持ID3编辑的软件中都可以看到这个列表,但是国内用户似乎不太在意这个标记,大多数人甚至不知道自己的歌曲到底属于哪一个分类。

ID3v1.1

细心的人会注意到ID3V1.0没有包括曲目序号的定义,所以Michael Mutschler在1997年进行了改进,引入了版本1.1。通过占用备注字段的最后两个字节,用一个00字节作标记,另一个字节改为序号,可以让ID3支持曲目编号了。一个字节的空间让ID3 V1.1支持最高到255的曲目序号,考虑到一张唱片超过256个曲目的可能性极小,这个改进还是相当合理的。
id3v1.1_blocks.gif
Internal layout of an ID3v1.1 tagged file.

ID3v1扩展


后来改进的一些版本主要是基于ID3v1容量太小的问题,主要是将各个主要“域”进行扩展,共有227字节。

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不再放在尾部,而是头部。解决了网络流媒体播放的缺陷。不再需要读完整个文件后再显示它的信息。以“ID3"开头。

  • 数据长度大小可变
     V1版本的大小都是固定的,超过了所规定的空间就完全容纳不了。而填不满那么多信息,又会造成空间的浪费。V2版本中采用了变长的存储方式。

  • 文本编码格式
     ID3使用已经很广泛,遍布全球,考虑了国际化的因素。涉及到了文本格式的编码的问题。

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

a - Unsynchronisation

Bit 7 in the 'ID3v2 flags' indicates whether or not unsynchronisation is used (see section 5 for details); a set bit indicates usage.

b - Extended header

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.

c - Experimental indicator
The third bit (bit 5) should be used as an 'experimental indicator'. This flag should always be set when the tag is in an experimental stage.

ID3v2 extended header

可选项,目前大多数都没有扩展头。

ID3v2 Frames

ID3 Tag是由一系列Frame来描述的,每个Frame最大可达16MB,这个Tag的大小限制在256MB。目前最新的ID3v2中已有多达84种Frame,应用程序也可以自定义Frame信息。

Frame Header:
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.


Flags的第一个字节表示“Status Message", 第二个字节则用于编码说明。

%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

一般情况下,会以优先级顺序对Frame来排序,协议没有强制要求这么做。一个Tag至少一个Frame,而每个Frame至少要有一个字节大小,不包括头信息。

通常ID3数据编码采用的是ISO-88591-1,当然也可以使用Unicode,在Flag结束的第一个字节,就用于表示这个Frame中数据采用的编码方式。
0: ISO-88591-1
1: UTF-16

ID3v2.4版本中,还支持使用UTF-16和UTF-8等编码格式。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值