A variable bit rate MP3 needs more than its first frame to tell how long it is, so encoders store the total in a header placed inside the first frame, where a decoder that does not know it just plays a frame of silence. There are two kinds: Xing and Info (with LAME’s extension) and VBRI. A frame holding one of them has no audio; a player should skip it.
Xing and Info
The header sits after the frame header and side information, so at offset 36 in a
stereo MPEG-1 frame, 21 in mono, 21 in a stereo LSF frame and 13 in mono (add 2 if the
frame has a CRC). Xing marks a VBR file; Info, written by the
same encoders, marks a CBR file. Its integers are big-endian.
| Field | Size | Present when | Meaning |
|---|---|---|---|
| Identifier | 4 | always | Xing or Info |
| Flags | 4 | always | bit 0 frames, bit 1 bytes, bit 2 table of contents, bit 3 quality |
| Frames | 4 | flag 0 | frames in the stream (usually leaving this frame out) |
| Bytes | 4 | flag 1 | bytes of audio |
| Table of contents | 100 | flag 2 | one byte per percent of the stream: the file position as a fraction of the bytes, in 256ths |
| Quality | 4 | flag 3 | a quality indicator from 0 to 100. LAME writes 100 − 10 × V − q, from its -V and -q settings, so higher means better: -V 0 -q 0 gives 100 and -V 4 -q 3 gives 57 |
The explorer checks the frame count against the frames it found, and reports a mismatch.
The LAME tag
Immediately after the Xing or Info header, LAME and encoders that copy it write 36 more bytes. Tag fields follow in this order.
| Field | Size | Meaning |
|---|---|---|
| Encoder | 9 | a version string, such as LAME3.100 |
| Revision and VBR method | 1 | top 4 bits: tag revision. Low 4: 0 unknown, 1 CBR, 2 ABR, 3 VBR method 1 (old/rh), 4 VBR method 2 (mtrh), 5 VBR method 3 (mt), 6 VBR method 4, 8 CBR 2 pass, 9 ABR 2 pass, 15 reserved |
| Lowpass | 1 | lowpass frequency in hundreds of hertz; 0 unknown |
| Peak signal amplitude | 4 | big-endian unsigned 32-bit fixed point with 23 fraction bits (9.23): the peak sample as a fraction of full scale (32767) times 223, so 8388608 is full scale; 0 means not measured. It is not a float |
| Radio replay gain | 2 | replay gain for the radio (track) level |
| Audiophile replay gain | 2 | the same for the audiophile (album) level |
| Encoding flags and ATH type | 1 | top 4 bits: 1 nspsytune, 2 nssafejoint, 4 no-gap continued, 8 no-gap continuation. Low 4: ATH type |
| Bitrate | 1 | the ABR or CBR bit rate; the lowest for VBR; 255 or more stored as 255 |
| Encoder delay and padding | 3 | 12 bits each: samples of delay at the start and of padding at the end, for gapless playback |
| Misc | 1 | bits 0–1 noise shaping (0–3); bits 2–4 stereo mode (0 mono, 1 stereo, 2 dual, 3 joint, 4 forced, 5 auto, 6 intensity, 7 other); bit 5 unwise settings used; bits 6–7 source sample rate (0 ≤ 32 kHz, 1 44.1, 2 48, 3 above 48) |
| MP3 gain | 1 | signed, in steps of 1.5 dB, applied through the frames’ global gain |
| Surround and preset | 2 | bits 13–11: surround (0 none, 1 DPL, 2 DPL2, 3 ambisonic); low 11 bits: the preset (8 to 320 ABR rate; 410 to 490 are V9 to V1 (--preset vbr), 500 is V0; 1000 r3mix, 1001 standard, 1002 extreme, 1003 insane, 1004 fast standard, 1005 fast extreme, 1006 medium, 1007 fast medium) |
| Music length | 4 | bytes of audio including this frame |
| Music CRC | 2 | CRC-16 of the audio frames that follow, from the first audio frame on |
| Tag CRC | 2 | CRC-16 of the frame up to this field |
Both CRCs use the polynomial 0xA001 (reflected form of 0x8005) starting
at 0. The explorer checks the tag CRC of files made by LAME and the music CRC.
Replay gain
Each replay-gain field is 16 bits: name (3 bits, 0 not set, 1 radio, 2 audiophile), originator (3 bits, 0 not set, 1 artist, 2 user, 3 automatic, 4 RMS-based automatic), sign (1 bit, 1 negative), and value (9 bits, in tenths of a decibel).
mpg123 (parse.c, check_lame_tag) ignores a field whose name or originator is 0, and for an automatic value (originator 3) written by LAME older than 3.95 it adds 6 dB, because those versions measured against 83 dB instead of 89 dB. It cannot tell LAME 3.95 from 3.95.1, which carry the same version string. One program says this, so treat it as a single source. mpg123 also reads the tag at the same offsets as this page (32, 17, 17 or 9 bytes after the frame header, by MPEG version and channel mode) and the 12-bit delay and padding the same way; it does not use the peak field at all, and its comment calls the field a float, which LAME, FFmpeg and Symphonia contradict.
VBRI
Fraunhofer’s header sits at a fixed offset of 32 bytes after the frame header, so at offset 36 in the frame. Integers are big-endian.
| Field | Size | Meaning |
|---|---|---|
| Identifier | 4 | VBRI |
| Version | 2 | 1 |
| Delay | 2 | encoder delay, a fixed-point value |
| Quality | 2 | a quality setting |
| Bytes | 4 | bytes of audio |
| Frames | 4 | frames of audio |
| Table entries | 2 | entries in the seek table |
| Scale | 2 | each entry times this is a number of bytes |
| Entry size | 2 | 1 to 4 bytes |
| Frames per entry | 2 | frames each entry covers |
| Table of contents | entries × size | the size of each run of frames |