Introduction
MP3 is MPEG-1 Audio Layer III, the lossy audio coding of the MPEG-1 standard (ISO/IEC
11172-3, 1993), developed largely at the Fraunhofer Institute in Germany. MPEG-2 (ISO/IEC
13818-3) added lower sample rates, and Fraunhofer’s MPEG-2.5 added lower ones still. It
shrinks audio to a small fraction of its uncompressed size by discarding sound the ear
is unlikely to notice. A file with the extension .mp3 nearly always holds
Layer III, but the same frame format also carries Layers I and II.
MP3 became the format of digital music downloads and portable players, and nearly every device and program that plays audio can play it.
A file dropped on any page of this site opens in the explorer, which shows every frame, field and tag, the waveform, which can be played, and the cover art.
Structure
An MP3 file has no file header. It is a run of frames, each a self-contained unit that starts with a sync word, with tags before and after. A player finds the first frame and steps from frame to frame by each header’s length.
An ID3v2 tag at the start, beginning
ID3, holds the title, artist, cover art and other details. A
Xing, Info or VBRI header often fills the
first frame, with the frame count and a seek table. After the audio, in this order from
the end of the file, may come an ID3v1 tag in
the last 128 bytes, an APE tag, and a
Lyrics3 tag.
Each frame has a four-byte header: an 11-bit sync word of ones, then the MPEG version, layer, bit rate, sample rate, padding flag and channel mode. What follows depends on the layer. A Layer I or II frame holds a bit allocation, scalefactors and samples. A Layer III frame holds side information and main data, which can start in the bytes of earlier frames.
0ID3v2 tag optional: title, artist, picturesvaries…Frames 4-byte header, then the layer’s data; the first may be a Xing, Info or VBRI headerrepeated…APE tag optional, ends in APETAGEXvaries…Lyrics3 optional, ends in LYRICS200variesendID3v1 tag optional, begins TAG128 bytes
A Layer III frame at 44,100 Hz holds 1152 samples per channel, in two granules of 576; at MPEG-2’s lower rates a frame holds one granule of 576. See samples per frame.
Telling it apart
The explorer accepts a file that begins with an ID3v2 tag, or with a frame header, and that goes on to a run of frames whose headers agree with each other: same version, layer and sample rate, each header found where the last frame’s length says it should be. Bytes between frames that fit neither a frame nor a tag are reported where they occur, and reading resumes at the next good frame.
Browsers play MPEG-1 and 2 Layer III themselves, and the explorer draws the waveform
of a long Layer III file from peaks. Its own decoder, in
explorer/formats/shared/audio/mpeg.js, handles all three layers of MPEG-1,
MPEG-2 and MPEG-2.5; its output matches mpg123 sample for sample on the streams tested.
MPEG-2’s backwards-compatible multichannel extension is not decoded: its extra
channels sit in the ancillary data, which the viewer shows as bytes.
Not described
Known, not yet covered
- Reference and viewer: the MPEG-2 multichannel extension, which is specified in ISO/IEC 13818-3 (a paid specification). Its data is shown as bytes and not decoded; the stereo base plays.
Unknown
- Reference and viewer: the MusicMatch tag, which was never documented. Shown as labelled bytes.
- Viewer: the contents of encrypted ID3v2 frames, since the key is not in the file. Shown as bytes.
Links
Software
- VLC media player – free player for almost any audio or video file (Windows, macOS, Linux, mobile)
- foobar2000 – free music player, tagger and converter (Windows, macOS, mobile)
- Audacity – free audio editor that opens and exports MP3 (Windows, macOS, Linux)
- MusicBee – free music player and library manager (Windows)
- LAME – the best-known free MP3 encoder (Windows, macOS, Linux)
- FFmpeg – command-line tool that converts MP3 to and from other formats (Windows, macOS, Linux)
Developers
- libmpg123 – decoding library from the mpg123 project (C)
- libmp3lame – encoding library from LAME (C)
- minimp3 – small single-header decoder (C)
- Mutagen – library that reads and writes ID3 tags (Python)
Reference
- ISO/IEC 11172-3 – the MPEG-1 audio standard, Layers I, II and III
- ISO/IEC 13818-3 – MPEG-2 audio: lower sample rates and multichannel
- ID3.org – the ID3v1 and ID3v2 tag specifications
- The Xing/LAME info tag – Gabriel Bouvigne’s description of the LAME extension to the Xing header
- APEv2 specification – Hydrogenaudio’s write-up of the APE tag format