mp3文件格式(frame header )
MPEG Audio Layer I/II/III frame header An MPEG audio file is built up from smaller parts called frames.MPEG audio文件是由称为frames的小部分组成的。 Generally, frames are independent items通常frames是由items决定的. Each frame has its own header and audio informations每一个frame有自己的头和audio信息. As there is no file header, you can cut any part of MPEG file and play it correctly (this should be done on frame boundaries but most applications will handle incorrect headers)如果没有文件头,你可以删减掉任何一个部分的MPEG文件来正常播放(这个…..). However, for Layer III, this is not 100% correct但是在Layer III,就不是完全这样了. Due to internal data organization in MPEG Layer III files, frames are often dependent of each other and they cannot be cut off just like that由于文件内部组织,frames之间是相互关联的,所以不能象前面一样剪裁出单独的部分播放. When you want to read info about an MPEG file, it is usually enough to find the first frame, read its header and assume that the other frames are the same 当你想要读MPEG文件,通常先读第一个头,然后假设其他头也是一样的. But this may not be always the case但是情况并不总是如此. Variable bitrate MPEG files may use so called bitrate switching, which means that bitrate changes according to the content of each frame可变比特率 MPEG文件使用比特率改变――比特率随着每一frame内容改变. This way lower bitrates may be used in frames where it will not reduce sound quality这样就可以减小文件尺寸,但是声音的质量却不会降低. This allows making better compression while keeping high quality of sound. 这样就可以在更大的压缩率下保持高音质。 The frame header is constituted by the very first four bytes (32bits) in a frame在frame开头有4个字节. The first eleven bits (or first twelve bits, see below about frame sync) of a frame header are always set and they are called "frame sync"开始11个比特位(或者是12位,见后面同步帧)被称为同步帧. Therefore, you can search through the file for the first occurence of frame sync (meaning that you have to find a byte with a value of 255, and followed by a byte with its three (or four) most significant bits set)这样你就可以搜索文件定位同步帧(). Then you read the whole header and check if the values are correct然后你就读入整个header然后检测是否有效. You will see in the following table the exact meaning of each bit in the header在后面的表你就可以看见每一位的意思. Each value that is specified as reserved, invalid, bad, or not allowed should indicate an invalid header. 每一个值分别表示保留、无效、坏、禁止 Frames may have a CRC check帧可能有CRC校验. The CRC is 16 bits long and, if it exists, it follows the frame header如果由,其长度为16bie,紧跟frame后. After the CRC comes the audio data.音频文件就在crc后面。 You may calculate the CRC of the frame你应该校验帧的CRC, and compare it with the one you read from the file然后与你读的文件校验. This is actually a very good method to check the MPEG frame validity. 这是检查MGEG帧的好办法 Here is a presentation of the header content一下是header的内容. Characters from A to M are used to indicate different fields字母A~M表示不同的Field. In the table below, you can see details about the content of each field. 你要仔细看下面的内容 AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM Sign Length (bits) Position (bits) Description A 11 (31-21) Frame sync (all bits set) B 2 (20,19) MPEG Audio version ID 00 - MPEG Version 2.5 (unofficial) 01 - reserved 10 - MPEG Version 2 (ISO/IEC 13818-3) 11 - MPEG Version 1 (ISO/IEC 11172-3) Note: MPEG Version 2.5 is not official standard. It is an extension of the standard used for very low bitrate files. If your decoder does not support this extension, it is recommended for you to use 12 bits for synchronization instead of 11 bits. C 2 (18,17) Layer description 00 - reserved 01 - Layer III 10 - Layer II 11 - Layer I D 1 (16) Protection bit 0 - Protected by CRC (16bit crc follows header) 1 - Not protected E 4 (15,12) Bitrate index bits V1,L1 V1,L2 V1,L3 V2,L1 V2, L2 & L3 0000 free free free free free 0001 32 32 32 32 8 0010 64 48 40 48 16 0011 96 56 48 56 24 0100 128 64 56 64 32 0101 160 80 64 80 40 0110 192 96 80 96 48 0111 224 112 96 112 56 1000 256 128 112 128 64 1001 288 160 128 144 80 1010 320 192 160 160 96 1011 352 224 192 176 112 1100 384 256 224 192 128 1101 416 320 256 224 144 1110 448 384 320 256 160 1111 bad bad bad bad bad NOTES: All values are in kbps V1 - MPEG Version 1 V2 - MPEG Version 2 and Version 2.5 L1 - Layer I L2 - Layer II L3 - Layer III
"free" means free format. If the correct fixed bitrate (such files cannot use variable bitrate) is different than those presented in upper table it must be determined by the application. This may be implemented only for internal purposes since third party applications have no means to findout correct bitrate. Howewer, this is not impossible to do but demands lots of efforts. "bad" means that this is not an allowed value MPEG files may have variable bitrate (VBR). Each frame may be created with different bitrate. It may be used in all layers. Layer III decoders must support this method. Layer I & II decoders may support it. For Layer II there are some combinations of bitrate and mode which are not allowed. Here is a list of allowed combinations. bitrate single channel stereo intensity stereo dual channel free yes yes yes yes 32 yes no no no 48 yes no no no 56 yes no no no 64 yes yes yes yes 80 yes no no no 96 yes yes yes yes 112 yes yes yes yes 128 yes yes yes yes 160 yes yes yes yes 192 yes yes yes yes 224 no yes yes yes 256 no yes yes yes 320 no yes yes yes 384 no yes yes yes
F 2 (11,10) Sampling rate frequency index (values are in Hz) bits MPEG1 MPEG2 MPEG2.5 00 44100 22050 11025 01 48000 24000 12000 10 32000 16000 8000 11 reserv. reserv. reserv.
G 1 (9) Padding bit 0 - frame is not padded 1 - frame is padded with one extra slot Padding is used to fit the bit rates exactly. For an example: 128k 44.1kHz layer II uses a lot of 418 bytes and some of 417 bytes long frames to get the exact 128k bitrate. For Layer I slot is 32 bits long, for Layer II and Layer III slot is 8 bits long. H 1 (8) Private bit. It may be freely used for specific needs of an application. I 2 (7,6) Channel Mode 00 - Stereo 01 - Joint stereo (Stereo) 10 - Dual channel (2 mono channels) 11 - Single channel (Mono)
Note: Dual channel files are made of two independant mono channel. Each one uses exactly half the bitrate of the file. Most decoders output them as stereo, but it might not always be the case. ????One example of use would be some speech in two different languages carried in the same bitstream, and and appropriate decoder would decode only the choosen language 另外一篇文章的描述 Mpeg 1.0/2.0 LayersI, II and III header and trailer formats ----------------------------------------------------------- Laurent.Clevy@alcatel.fr * HEADER
bits name comments -------------------------------------------------- 12 sync 0xFFF 1 version 1=mpeg1.0, 0=mpeg2.0 2 lay 4-lay = layerI, II or III 1 error protection 0=yes, 1=no 4 bitrate_index see table below 2 sampling_freq see table below 1 padding 1 extension see table below 2 mode see table below 2 mode_ext used with "joint stereo" mode 1 copyright 0=no 1=yes 1 original 0=no 1=yes 2 emphasis see table below -------------------------------------------------- - bitrate_index . mpeg1.0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 layer1 32 64 96 128 160 192 224 256 288 320 352 384 416 448 layer2 32 48 56 64 80 96 112 128 160 192 224 256 320 384 layer3 32 40 48 56 64 80 96 112 128 160 192 224 256 320 . mpeg2.0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 layer1 32 48 56 64 80 96 112 128 144 160 176 192 224 256 layer2 8 16 24 32 40 48 56 64 80 96 112 128 144 160 layer3 8 16 24 32 40 48 56 64 80 96 112 128 144 160
- sampling_freq . mpeg1.0 0 1 2 44100 48000 32000 . mpeg2.0 0 1 2 22050 24000 16000
- mode: 0 "stereo" 1 "joint stereo" 2 "dual channel" 3 "single channel"
- mode extension:
0 MPG_MD_LR_LR 1 MPG_MD_LR_I 2 MPG_MD_MS_LR 3 MPG_MD_MS_I jsbound : mode_ext 0 1 2 3 layer 1 4 8 12 16 2 4 8 12 16 3 0 4 8 16
- emphasis: 0 "none" 1 "50/15 microsecs" 2 "reserved" must not be used ! 3 "CCITT J 17"
* TRAILER at end of file - 128 bytes offset type len name -------------------------------------------- 0 char 3 "TAG" 3 char 30 title 33 char 30 artist 63 char 30 album 93 char 4 year 97 char 30 comments 127 byte 1 genre -------------------------------------------- - genre : 0 "Blues" 1 "Classic Rock" 2 "Country" 3 "Dance" 4 "Disco" 5 "Funk" 6 "Grunge" 7 "Hip-Hop" 8 "Jazz" 9 "Metal" 10 "New Age" 11 "Oldies" 12 "Other" 13 "Pop" 14 "R&B" 15 "Rap" 16 "Reggae" 17 "Rock" 18 "Techno" 19 "Industrial" 20 "Alternative" 21 "Ska" 22 "Death Metal" 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 "Sound Clip" 38 "Gospel" 39 "Noise" 40 "AlternRock" 41 "Bass" 42 "Soul" 43 "Punk" 44 "Space" 45 "Meditative" 46 "Instrumental Pop" 47 "Instrumental Rock" 48 "Ethnic" 49 "Gothic" 50 "Darkwave" 51 "Techno-Industrial" 52 "Electronic" 53 "Pop-Folk" 54 "Eurodance" 55 "Dream" 56 "Southern Rock" 57 "Comedy" 58 "Cult" 59 "Gangsta" 60 "Top 40" 61 "Christian Rap" 62 "Pop/Funk" 63 "Jungle" 64 "Native American" 65 "Cabaret" 66 "New Wave" 67 "Psychadelic" 68 "Rave" 69 "Showtunes" 70 "Trailer" 71 "Lo-Fi" 72 "Tribal" 73 "Acid Punk" 74 "Acid Jazz" 75 "Polka" 76 "Retro" 77 "Musical" 78 "Rock & Roll" 79 "Hard Rock" 80 "Unknown" - frame length : . mpeg1.0 layer1 : (48000*bitrate)/sampling_freq + padding layer2&3: (144000*bitrate)/sampling_freq + padding . mpeg2.0 layer1 : (24000*bitrate)/sampling_freq + padding layer2&3 : (72000*bitrate)/sampling_freq + padding
|