# MP3

Canonical URL: https://encode.wiki/codecs/audio/mp3/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): b2c8db27fb9ca3bc902d99f375414a2272746ea8dc288d463ecefbd5080eaeb8

MP3 (MPEG-1/2 Audio Layer III) is a lossy codec from the early 1990s. It is far less efficient than [AAC](/codecs/audio/aac/) or [Opus](/codecs/audio/opus/): at the same bitrate it sounds worse, and it cannot do surround. It stays relevant for one reason, which is that everything can play it — old hardware, car stereos, DJ gear, cheap players. Use it only when you need that. Otherwise use Opus or AAC.

The MP3 patent licensing program ended in 2017, so patents are no longer a practical concern.

MP3 is mono or stereo only. Sample rates run from 8 to 48 kHz, split across MPEG-1 (32, 44.1, 48 kHz), MPEG-2 (16, 22.05, 24 kHz) and an unofficial MPEG-2.5 extension (8, 11.025, 12 kHz) that some players reject. Bitrates run from 8 to 320 kbit/s depending on the generation.

## Encoding with LAME

LAME is the only MP3 encoder worth using. Always encode from a lossless source, with variable bitrate (VBR) quality mode:

```sh
lame -V 2 input.wav output.mp3
```

`-V` goes from 0 (best) to 9 (smallest). Without `-V`, `lame` encodes 128 kbit/s CBR, and `-V` without a number means 4; both are lower quality than most people want. Approximate averages for music, which vary with the material:

| Setting | Average bitrate | Use |
| --- | --- | --- |
| `-V 0` | ~245 kbit/s | Highest VBR quality; the sensible choice if you want margin. |
| `-V 2` | ~190 kbit/s | The usual recommendation: transparent for most listeners on most music. |

CBR 320 (`-b 320`) is the only fixed-rate setting worth using, and only when a device demands CBR. It is larger than `-V 0` for no audible benefit.

LAME reads WAV and AIFF directly. For FLAC and other formats, pipe the decode through:

```sh
ffmpeg -i input.flac -f wav - | lame -V 2 - output.mp3
```

## Encoding with FFmpeg

FFmpeg uses LAME through `libmp3lame` and needs no pipe. `-q:a` is the same scale as LAME's `-V`:

```sh
ffmpeg -i input.flac -c:a libmp3lame -q:a 2 output.mp3
```

For a fixed bitrate use `-b:a 320k`, and add `-abr 1` to ask for average-bitrate mode instead of CBR. FFmpeg's separate `-compression_level` (0–9) affects only encoder effort and speed, not bitrate. Don't copy options between `lame` and FFmpeg; the spellings differ.

## Pitfalls

- **Don't transcode.** Encoding a lossy file to MP3 stacks artifacts on artifacts. Keep a lossless master.
- **Gapless playback.** The encoder adds delay and padding at the start and end. Players need the LAME/Xing tag, which LAME and FFmpeg write, to trim it. Never join MP3s by byte-concatenating them for gapless albums.
- **VBR seeking.** Some old players seek or show duration incorrectly with VBR files because they ignore the Xing header. CBR avoids that.
- **Low-rate files.** Below ~128 kbit/s MP3 degrades quickly; switch to Opus or AAC.
- **Tags.** MP3 uses ID3v2. Cover art is stored in the tag, so it appears as a video stream when FFmpeg reads it.
