Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:MPEG audio

From ReverseEngineering.wiki
Format
Developer Fraunhofer / MPEG
Magic FF Fx (frame sync, 11 set bits) or 49 44 33 ("ID3") first
Extensions .mp3, .mp2, .mpa
Endianness big
On this wiki Facts · Code · Notes · Topics

MPEG-1/2 audio layers I-III (.mp3, .mp2): a stream of frames, each starting with an 11-bit sync and a 4-byte header giving version, layer, bitrate, sample rate, padding and channel mode, optionally preceded by an ID3v2 tag ('ID3' + synchsafe size) and followed by a 128-byte ID3v1 'TAG' block.

Overview

MP3 files have no file header: a stream of independent frames, each beginning with a 4-byte header. Players find the first frame by scanning for the 11-bit sync (FF followed by a byte whose top 3 bits are set) and validating several consecutive frame lengths. In RIFF containers the codec is wFormatTag 0x0055 (layer 3) or 0x0050 (layers 1-2) (Format:RIFF WAVE).

Frame header (32 bits, big endian)

Bits Field
11 sync, all ones
2 version: 3 = MPEG-1, 2 = MPEG-2, 0 = MPEG-2.5, 1 reserved
2 layer: 1 = layer III, 2 = layer II, 3 = layer I, 0 reserved
1 protection bit (0 = a 16-bit CRC follows the header)
4 bitrate index (0 free format, 15 invalid)
2 sample rate index (MPEG-1: 44100, 48000, 32000; MPEG-2: 22050, 24000, 16000; MPEG-2.5: 11025, 12000, 8000; 3 invalid)
1 padding
1 private
2 channel mode (0 stereo, 1 joint stereo, 2 dual channel, 3 mono)
2 mode extension
1 copyright
1 original
2 emphasis

Frame length for layer III, MPEG-1: floor(144 x bitrate / sample rate) + padding bytes, with 1152 samples per frame (576 for MPEG-2/2.5 layer III). Layer I frames carry 384 samples with 4-byte slots. Unverified: this whole table is from the standard, not from a source file read for this page.

VBR headers

The first frame of a variable-bitrate file carries a Xing (VBR) or Info (CBR) tag at a fixed offset after the 4-byte frame header: FFmpeg libavformat/mp3dec.c (c2bbf2b83d, lines 180-186) skips 32 bytes for MPEG-1 stereo, 17 for MPEG-1 mono and MPEG-2 stereo, 9 for MPEG-2 mono, i.e. tag offset 36 / 21 / 21 / 13 from the frame start, then reads the tag name, a flags word (0x01 frame count, 0x02 byte count, 0x04 table of contents of 100 entries, 0x08 quality) and those fields in that order (lines 41-46, 188-215). Fraunhofer's VBRI tag is looked for 32 bytes after the end of the frame header, offset 36 (line 305). Unverified: that the carrier frame is silent, and the LAME encoder string layout (e.g. LAME3.99). The encoder delay and padding in the LAME tag matter for gapless looping.

ID3v2

A tag at the start of the file: 49 44 33 ("ID3"), major version, revision, flags byte, then a 4-byte synchsafe size (7 bits per byte, top bit 0) that excludes the 10-byte header. The frames inside have a 10-byte header: 4-character id (TIT2 title, TPE1 artist, APIC picture, TXXX ...), size (synchsafe in v2.4, plain in v2.3), 2 flag bytes. FFmpeg's id3v2.h defines the frame format flags: data length indicator 0x0001, unsynchronisation 0x0002, encryption 0x0004, compression 0x0008 (ID3v2_HEADER_SIZE 10, default magic "ID3"). A footer ("3DI") may follow when the header flag says so. Players skip the tag using the size; a reverser must do the same before looking for the first MP3 frame or for Format:FLAC data.

ID3v1

A fixed 128-byte block at the end of the file starting with TAG (title 30, artist 30, album 30, year 4, comment 30, genre 1 bytes); v1.1 uses the last two comment bytes as a zero and a track number. FFmpeg libavformat/id3v1.c (c2bbf2b83d) reads it from filesize - 128 (line 288) and parses it at offsets 3, 33, 63, 93 (4 bytes), 97 and the genre at 127, taking the track from byte 126 when byte 125 is 0 (lines 261-272).

Reversing notes

  • Many game audio systems store MP3 frames with the ID3 tag stripped; look for sync plus consistent frame lengths rather than for "ID3".
  • Encoders such as LAME and decoders such as minimp3 are commonly statically linked, so version strings like LAME3.100 identify them in a binary.

Code & repositories

See Library:FFmpeg (libavformat/id3v2.h).

  • https://github.com/FFmpeg/FFmpeg @ 7045cc9b8020ebaae156f4947baa752625056f90 · license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
    FFmpeg libavformat demuxers: riff.c (wFormatTag and FourCC tables), wavdec.c, avidec.c/avi.h, matroska.h (element ids), id3v2.h, isom.h/mov.c.
    Tested on: source read, not run: Read riff.c tag table, wavdec.c probe, avi.h, matroska.h and id3v2.h at this commit (sparse checkout). Not built. · checked 2026-10-18