MP3文件格式

MPEG Audio Layer I/II/III frame header

An MPEG audio file is built up from smaller parts called frames. Generally, frames are independent items. Each frame has its own header and audio informations. 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). However, for Layer III, this is not 100% correct. 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.

????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. 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. 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. 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". 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. 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. The CRC is 16 bits long and, if it exists, it follows the frame header. After the CRC comes the audio data. You may calculate the CRC of the frame, and compare it with the one you read from the file. This is actually a very good method to check the MPEG frame validity.

????Here is a presentation of the header content. Characters from A to M are used to indicate different fields. In the table below, you can see details about the content of each field.

AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM

SignLength
(bits)
Position
(bits)
Description
A11(31-21)Frame sync (all bits set)
B2(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.

C2(18,17)Layer description
00 - reserved
01 - Layer III
10 - Layer II
11 - Layer I
D1(16)Protection bit
0 - Protected by CRC (16bit crc follows header)
1 - Not protected
E4(15,12)

Bitrate index

bitsV1,L1V1,L2V1,L3V2,L1V2, L2 & L3
0000freefreefreefreefree
0001323232328
00106448404816
00119656485624
010012864566432
010116080648040
011019296809648
01112241129611256
100025612811212864
100128816012814480
101032019216016096
1011352224192176112
1100384256224192128
1101416320256224144
1110448384320256160
1111badbadbadbadbad

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

F2(11,10)Sampling rate frequency index (values are in Hz)
bitsMPEG1MPEG2MPEG2.5
00441002205011025
01480002400012000
1032000160008000
11reserv.reserv.reserv.
G1(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.
H1(8)Private bit. It may be freely used for specific needs of an application.
I2(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

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

lanstar200

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值