MP3 ID3v2标签说明

MP3文件一般由三部分组成:

TAG_V2(ID3V2)   //ID3v2 标签

Frames                   //标签帧

TAG_V1(ID3V1)   //ID3v1 标签


本文主要说明ID3v2标签,翻译来源:http://id3.org/

以下将按顺序以两列来说明数据,第一列表示ID3v2各部分含义,第二列为其对应的值($表示后面跟随的是字节,%表示后面跟随的是单字节中的位)


ID3v2.2:

ID3v2 header  //标签头部
ID3/file identifier      "ID3"
ID3 version              $02 00
ID3 flags                %ab000000  
a: whether or not unsynchronisation is used
 非同步标志:用于兼容旧软件,该标志只在MPEG 2 Layer I,II,III,以及MPEG2.5 文件中产生,如果设置该位,则要在后面填充一个0x00字节
 根据Android源码ID3.cpp removeUnsynchroization() 处理非同步标志
  2.2 或 2.3: 设置unsynchronisation位表示编码时在ID3标签所有包含0xff00后有一个字节填充,解析时将所有0xff00后面一个字节移除
b: whether or not compression is used

注:先解析unsynchronisation再解析compression
ID3 size             4 * %0xxxxxxx(每个字节最高位为0,总共只用到28位,组成的整数称为“synchsafe integer”)
size = total size - 10(header size)
The reason to use 28 bits (representing up to 256MB) for size description is that we don't want to run out of space here.

A ID3v2 tag can be detected with the following pattern:
     $49 44 33 yy yy xx zz zz zz zz
   Where yy is less than $FF, xx is the 'flags' byte and zz is less than $80.
   
标签帧(Frame):
帧头:
  帧标识(3 bytes) 
 大小(3 bytes,不包括头大小)
帧数据

一个Tag至少要包含一个Frame,一个Frame至少要有一个字节(不包括帧头大小)


ID3v2.3:

ID3v2 header://标签头部
ID3v2/file identifier   "ID3"
ID3v2 version           $03 00
ID3v2 flags             %abc00000
a - Unsynchronisation
b - Extended header   //指示该Header后面是否有扩展Header
c - Experimental indicator //是否为测试标签
ID3v2 size              4 * %0xxxxxxx  //每个字节最高位为0,共28位,size不包括头大小,但包括扩展头大小

注:Header patten: 49 44 33 yy yy xx zz zz zz zz

ID3v2 extended header://标签扩展头部
Extended header size   $xx xx xx xx //扩展头大小,不包括此4个字节
Extended Flags         $xx xx   //%x0000000 00000000, x表示是否有4字节的CRC校验
Size of padding        $xx xx xx xx

Frame:  //标签帧,包括帧头(10个字节)和帧数据
Frame ID       $xx xx xx xx (four characters)
Size           $xx xx xx xx //帧数据大小,不包括头大小
Flags          $xx xx
格式:%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
 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
 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.

i - Compression  //压缩标志,设置时一个字节存放两个 BCD 码表示数字。This flag indicates whether or not the frame is compressed. 如果为1则帧头后跟一个4字节表明解压大小
 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. 如果为1则帧头后跟一个1字节表明使用哪个加密方法
 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. 
  //如果为1则帧头后跟1字节表明组id,组id相同的帧为同一组
 0    Frame does not contain group information
 1    Frame contains group information
 
注:i,j,k位标志表明帧头后有追加额外数据,如果几个同时存在时数据追加顺序按标志的顺序进行,这些数据大小不在header size内但在frame size内


Data           $xx xx ......  //帧数据
标签帧内容第一个字节表明编码方法:(如果是unicode编码,则后面要再跟两个字节表明字节序)
0x00: ISO8859-1
0x01: UCS-2
0x02: UTF-8
0x03: UCS-4

注:一个Tag至少要包含一个Frame,一个Frame至少要有一个字节(不包括帧头大小)


ID3v2.4:

Overall tag structure:

     +-----------------------------+
     |      Header (10 bytes)      |
     +-----------------------------+
     |       Extended Header       |
     | (variable length, OPTIONAL) |
     +-----------------------------+
     |   Frames (variable length)  |
     +-----------------------------+
     |           Padding           |
     | (variable length, OPTIONAL) |
     +-----------------------------+
     | Footer (10 bytes, OPTIONAL) |
     +-----------------------------+
In general, padding and footer are mutually exclusive. (padding和footer一般不同时出现)

ID3v2 header://标签头部
ID3v2/file identifier      "ID3"
ID3v2 version              $04 00
ID3v2 flags                %abcd0000
a - Unsynchronisation  //非同步标志:用于兼容旧软件,该标志只在MPEG 2 Layer I,II,III,以及MPEG2.5 文件中产生,如果设置该位,则表明后面所有标签帧都需要非同步处理
b - Extended header   //指示该Header后面是否有扩展Header
c - Experimental indicator //是否为测试标签
d - Footer present    //指示该TAG末尾是否存在尾部数据

ID3v2 size             4 * %0xxxxxxx //每个字节最高位为0,共28位,size不包括头大小及尾大小,但包括扩展头大小

注:Header patten: 49 44 33 yy yy xx zz zz zz zz

ID3v2 extended header://标签扩展头部
Extended header size   4 * %0xxxxxxx  //synchsafe integer,is the size of the whole extended header 表示整个扩展头的大小,不小于6字节
Number of flag bytes       $01
Extended Flags         $xx //格式:%0bcd0000
b - Tag is an update
c - CRC data present
d - Tag restrictions //标签限制信息

Data(flag b) $00         //无数据
Data(flag c) $xx xx ...  //第一个字节为长度,范围0-128即0x00-0x7f,第2-n字节为数据内容,如果数据为空则长度为0x00
Flag data length       $05
    Total frame CRC    5 * %0xxxxxxx
Data(flag d) //同上
Flag data length       $01
Restrictions           %ppqrrstt
p - Tag size restrictions //标签大小限制
00   No more than 128 frames and 1 MB total tag size.
01   No more than 64 frames and 128 KB total tag size.
10   No more than 32 frames and 40 KB total tag size.
11   No more than 32 frames and 4 KB total tag size.
q - Text encoding restrictions //编码限制
0    No restrictions
1    Strings are only encoded with ISO-8859-1 [ISO-8859-1] or UTF-8 [UTF-8].
r - Text fields size restrictions //文本大小限制,注意这里大小不是指字节,实际字节数与编码方式有关
00   No restrictions
01   No string is longer than 1024 characters.
10   No string is longer than 128 characters.
11   No string is longer than 30 characters.
s - Image encoding restrictions  //图片格式限制
0   No restrictions
1   Images are encoded only with PNG [PNG] or JPEG [JFIF].
t - Image size restrictions  //图片大小限制
00  No restrictions
01  All images are 256x256 pixels or smaller.
10  All images are 64x64 pixels or smaller.
11  All images are exactly 64x64 pixels, unless required
  otherwise.

Padding //补白,填充数据
Padding是可选项,位于ID3 TAG的末尾;
Padding的作用是可以在不重写整个文件的情况下额外增加帧或扩展现有帧大小;
Padding的内容必须全部为0x00;
Padding不能存在于帧于帧之间,以及标签头与帧之间;
当有footer存在时,不能有Padding数据;


ID3v2 footer://与header一样,除了identifier
ID3v2 identifier           "3DI"
ID3v2 version              $04 00
ID3v2 flags                %abcd0000
ID3v2 size             4 * %0xxxxxxx

注:footer的作用,当从文件尾定位标签时,使用footer可以加快查找速度

ID3v2 frame: //标签帧
Frame ID       $xx xx xx xx (four characters)  //由A-Z 及 0-9 组成的4个字符,以"X","Y","Z"开头的帧表示测试帧
Size           4 * %0xxxxxxx //帧数据大小,不包括头大小
Flags          $xx xx
格式:%0abc0000 %0h00kmnp  //第一个字节表明状态消息(如果设置了未知标志,表明该帧不能被修改除非清除此标志),第二个字节为格式描述(如果设置了未知标志,可能不可读)
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
//当标签Tag发生变化时(包括增加填充数据,以及帧之间顺序变化),该使用何种操作
 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
//文件发生变化时(不包含标签Tag的变化,当整个audio数据替换成另一个audio数据时也不适用),该使用何种操作
 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.

h - Grouping identity  //组标志,设置时说明此帧和其他的某帧是一组。This flag indicates whether or not this frame belongs in a group with other frames. 
  //如果为1则帧头后跟1字节表明组id,组id相同的帧为同一组
 0    Frame does not contain group information
 1    Frame contains group information
k - Compression  //压缩标志,设置时一个字节存放两个 BCD 码表示数字。This flag indicates whether or not the frame is compressed. 如果为1则帧头后跟一个4字节表明解压大小
 0    Frame is not compressed.
 1    Frame is compressed using [#ZLIB zlib] with 4 bytes for 'decompressed size' appended to the frame header.
 
m - Encryption  //加密标志。This flag indicates wether or not the frame is enrypted. 如果为1则帧头后跟一个1字节表明使用哪个加密方法
 0   Frame is not encrypted.
 1    Frame is encrypted.
n - Unsynchronisation  //指示该帧是否使用非同步处理。
 0     Frame has not been unsynchronised.
      1     Frame has been unsyrchronised.
p - Data length indicator
 0      There is no Data Length Indicator.
      1      A data length Indicator has been added to the frame.


Data           $xx xx ......
标签帧内容第一个字节表明编码方法:(如果是unicode编码,则后面要再跟两个字节表明字节序)
0x00: ISO8859-1     //以0x00结束
0x01: UTF-16        //带BOM,以$00 00结束,如果字符串是空的则内容可能为$FE FF 00 00 或 $FF FE 00 00
0x02: UTF-16        //不带BOM,以$00 00结束
0x03: UTF-8         //以0x00结束




注:
一个Tag至少要包含一个Frame,一个Frame至少要有一个字节(不包括帧头大小);
Unicode BOM,即Byte of order,表明字节序,$FE FF表示大端big endian,$FF FE表示小端little endian;
标签帧可以有3个字节表示语言,如果未知则使用"xxx";
所有的URL都是相对路径;


标签定位(Tag location)
默认情况下,ID3v2 tag位于audio数据的前面,不过tag也可以加到文件尾。
当要决定放置tag时,要根据以下顺序考虑:
1.将tag放在文件前面;
2.将包含重要信息的tag放在文件前面,再在文件尾加一个tag,第一个tag要有一个seek帧;
3.在文件尾加一个tag


在2和3情况下,建议用以下方法来寻找tags:
1.使用"ID3"标志查找文件前tag;
2.如果找到seek帧,则根据它来引导后面的搜索;
3.从文件尾开始扫描找到标签footer;
当找到新的tag时,旧的tag将不再使用,除非其扩展头的更新标志被设置过

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值