Skip to content
@deckyard/mp3

The MPEG frame header

Four bytes open every frame.

AAAAAAAA  AAABBCCD  EEEEFFGH  IIJJKLMM
BitsFieldMeaning
A (11)syncall ones
B (2)version00 MPEG-2.5, 01 reserved, 10 MPEG-2, 11 MPEG-1
C (2)layer00 reserved, 01 Layer III, 10 Layer II, 11 Layer I
D (1)protection0 means a 16-bit CRC follows the header
E (4)bitrate index0 free format, 15 invalid
F (2)sampling rate index3 reserved
G (1)paddingthe frame carries one extra slot
H (1)private
I (2)channel mode00 stereo, 01 joint, 10 dual, 11 mono
J (2)mode extensionjoint stereo only
K (1)copyright
L (1)original
M (2)emphasis

The protection bit is inverted: 0 means a CRC is present.

The deck treats a header with version 01, layer 00, bitrate index 0 (free format) or 15, or sampling-rate index 3 as no header at all.

Sampling rates, Hz

IndexMPEG-1MPEG-2MPEG-2.5
0441002205011025
1480002400012000
232000160008000
3reservedreservedreserved

Bitrates, kbit/s

IndexV1 L1V1 L2V1 L3V2 L1V2 L2/L3
0freefreefreefreefree
1323232328
26448404816
39656485624
412864566432
516080648040
619296809648
72241129611256
825612811212864
928816012814480
1032019216016096
11352224192176112
12384256224192128
13416320256224144
14448384320256160
15invalidinvalidinvalidinvalidinvalid

MPEG-2.5 uses the MPEG-2 tables.

Samples per frame

LayerMPEG-1MPEG-2 and MPEG-2.5
I384384
II11521152
III1152576

Frame length

Layer I counts in four-byte slots and divides before it multiplies:

frameSize = (12 * bitrate // sampleRate + padding) * 4

Layer II and III count in bytes:

frameSize = (samples // 8) * bitrate // sampleRate + padding

bitrate is bits per second and padding is 1 or 0. The divisions are floor divisions: a 128 kbit/s 44100 Hz Layer III frame is 417 bytes, not 417.96.

Side information

Bytes between the end of the four-byte header and the Xing or Info identifier.

monostereo
MPEG-11732
MPEG-2 and MPEG-2.5917

Xing and Info

At the frame header plus 4 plus the side information size.

OffsetLengthField
04Xing or Info
44flags
84frame count, if flag 0x01
4stream bytes, if flag 0x02
100table of contents, if flag 0x04
4quality 0-100, if flag 0x08

The optional fields appear in that order, each only if its flag is set. Info is the same structure in a constant-bitrate file.

VBRI

At frame start plus 36 (32 bytes after the header), independent of the side information size. The deck reads quality, stream bytes, frame count and whether the table of contents has entries; a VBRI header shorter than 26 bytes yields kind "VBRI" with nothing else stated.

OffsetLengthField
04VBRI
42version
62delay
82quality
104stream bytes
144frame count
182table-of-contents entries
202scale
222bytes per entry
242frames per entry

Written by the Fraunhofer encoder; Xing is more common.