There is no main file header in an MPEG audio file. An MPEG audio file is built up from a succession of smaller parts called frames. A frame is a datablock with its own header and audio information.
In the case of Layer I or Layer II, frames are some totally independent items, so you can cut any part of MPEG file and play it correctly. The player will then play the music starting to the first plain valid frame founded. However, in the case of Layer III, frames are not always independant. Due to the possible use of the "byte reservoir", wich is a kind of buffer, frames are often dependent of each other. In the worst case, 9 frames may be needed before beeing able to decode one frame.When you want to read info about an MPEG audio file, it is usually enough to find the first frame, read its header and assume that the other frames are the same. But this is not always the case, as variable bitrate (VBR) files may be encountered. In a VBR file, the bitrate can be changed in each frame. It can be used, as an exemple to keep a constant sound quality during the whole file, by using more bits where the music need more to be encoded.
The frame header is 32 bits (4 bytes) length. The first twelve bits (or first eleven bits in the case of the MPEG 2.5 extension) of a frame header are always set to 1 and are called "frame sync".
Frames may have an optional CRC checksum. It is 16 bits long and, if it exists, follows the frame header. After the CRC comes the audio data. By re-calculating the CRC and comparing its value to the sored one, you can check if the frame has been altered during transmission of the bitstream.
Here is a presentation of the frame header content. Colors are used to indicate different fields. In the table below, you can see details about the content of each field.
Color | Length (bits) |
Position (bits) |
Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11 | (1-11) | Frame sync (all bits must be set) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | (12,13) | MPEG Audio version ID 00 - MPEG Version 2.5 (later extension of MPEG 2) 01 - reserved 10 - MPEG Version 2 (ISO/IEC 13818-3) 11 - MPEG Version 1 (ISO/IEC 11172-3) Note: MPEG Version 2.5 was added lately to the MPEG 2 standard. It is an extension used for very low bitrate files, allowing the use of lower sampling frequencies. If your decoder does not support this extension, it is recommended for you to use 12 bits for synchronization instead of 11 bits. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | (14,15) | Layer description 00 - reserved 01 - Layer III 10 - Layer II 11 - Layer I |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | (16) | Protection bit 0 - Protected by CRC (16bit CRC follows header) 1 - Not protected |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | (17,20) | Bitrate index
NOTES: All values are in kbps MPEG files may feature variable bitrate (VBR). Each frame may then be created with a 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | (21,22) | Sampling rate frequency index
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | (23) | Padding bit 0 - frame is not padded 1 - frame is padded with one extra slot Padding is used to exactly fit the bitrate.As an example: 128kbps 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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | (24) | Private bit. This one is only informative. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | (25,26) | 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 then an appropriate decoder would decode only the choosen language. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | (27,28) | Mode extension (Only used in Joint stereo)
Mode extension is used to join informations that are of no use for stereo effect, thus reducing needed bits. These bits are dynamically determined by an encoder in Joint stereo mode, and Joint Stereo can be changed from one frame to another, or even switched on or off. Complete frequency range of MPEG file is divided in subbands
There are 32 subbands. For Layer I & II these two bits determine
frequency range (bands) where intensity stereo is applied.
For Layer III these two bits determine which type of joint
stereo is used (intensity stereo or m/s stereo). Frequency
range is determined within decompression algorithm.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | (29) | Copyright 0 - Audio is not copyrighted 1 - Audio is copyrighted The copyright has the same meaning as the copyright bit on CDs and DAT tapes, i.e. telling that it is illegal to copy the contents if the bit is set. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | (30) | Original 0 - Copy of original media 1 - Original media The original bit indicates, if it is set, that the frame is located on its original media. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | (31,32) | Emphasis 00 - none 01 - 50/15 ms 10 - reserved 11 - CCIT J.17 The emphasis indication is here to tell the decoder that the file must be de-emphasized, ie the decoder must 're-equalize' the sound after a Dolby-like noise supression. It is rarely used. |