GitHub

mp3rgain CLI Reference

Complete option reference for mp3rgain v3.1.0, plus exit codes, environment variables, output formats and the operational recipes that come up most often. The flag set is mp3gain-compatible, so anything you knew about mp3gain still applies.

The one-line mental model: mp3rgain [OPTIONS] <FILES>... โ€” with no options at all it only reports. Writing happens when you pass a gain action (-r, -a, -g, -l, -u, or -s d).

Options

OptionDescription
-rApply Track gain (per-file ReplayGain analysis).
-aApply Album gain โ€” one shared gain across all files given in the same invocation.
--rg2Analyse with ReplayGain 2.0: ITU-R BS.1770 gated loudness, โˆ’18 LUFS reference.
--r128Analyse with EBU R128: ITU-R BS.1770 gated loudness, โˆ’23 LUFS target.
-g <i>Apply a manual gain of i steps. One step is 1.5 dB; i may be negative.
-d <n>Modify the suggested/target gain by n dB, rounded to the nearest step. Used with -r / -a.
-m <i>Modify the suggested gain by an integer number of steps.
-l <c> <g>Apply gain g to one channel only: c = 0 for left, 1 for right.
-eSkip album analysis even when several files are passed.
-i <n>Select which audio track to process (default: 0).
-uUndo previous gain changes, restoring the file from its stored undo tag.
-xReport the maximum amplitude only; nothing is written.
-s <mode>Stored-tag handling: c check/show, d delete, s skip writing, i use ID3v2, a use APEv2 (default), r force recalculation (accepted for mp3gain compatibility; always on).
-pPreserve the original file timestamp.
-kPrevent clipping by automatically limiting the applied gain.
-cIgnore clipping warnings and apply the gain anyway.
-wWrap gain values instead of clamping them at the representable range.
-qQuiet mode โ€” less output.
-RRecurse into directories.
-n, --dry-runPreview what would change; nothing is written.
--skip-errorsKeep going past files that fail to analyse instead of aborting. Useful with -a on large libraries.
-j <n>, --threads <n>Worker threads for analysis. Default auto; 0 = auto, 1 = serial.
-o <fmt>Output format: text (default), json, or tsv.
-tWrite via a temp file. Always on; accepted for mp3gain compatibility.
-fAssume MPEG 2 Layer III. Accepted for compatibility; no effect.
-vPrint the version.
-hPrint help.

Analysis modes

ReplayGain 1.0 is the default and stays the default deliberately: it reproduces the original mp3gain's numbers exactly, so re-scanning a library that mp3gain already touched does not shift every file. The BS.1770 modes are opt-in.

ModeFlagAlgorithmReferenceUse when
ReplayGain 1.0defaultReplayGain 1.089 dBMigrating from mp3gain / aacgain, or matching an existing library
ReplayGain 2.0--rg2ITU-R BS.1770 (gated)โˆ’18 LUFSMatching modern taggers โ€” rsgain, loudgain, foobar2000
EBU R128--r128ITU-R BS.1770 (gated)โˆ’23 LUFSBroadcast delivery targets

The BS.1770 measurements agree with ffmpeg ebur128 and other libebur128-based tools to within 0.05 LU. Values from RG 1.0 and the BS.1770 modes are not interchangeable โ€” that is expected, not a bug.

Track gain vs album gain

-r gives every file its own gain, so each track hits the reference level on its own. -a computes one gain for the whole set and applies it to every file, which preserves the relative dynamics an album was mixed with. Album mode operates on the files passed in a single invocation, so glob carefully:

# Correct: one album at a time
mp3rgain -a "Artist/Album/"*.mp3

# Wrong: treats an entire library as one album
mp3rgain -a -R /music

Tags written

Applying gain writes standard ReplayGain metadata as well as the undo state, so the file stays useful to ReplayGain-aware players. The container decides the tag format: APEv2 for MP3 by default, ID3v2 TXXX with -s i, MP4 freeform atoms for AAC/M4A.

TagWritten whenMeaning
REPLAYGAIN_TRACK_GAIN / _PEAKAny applyResidual track gain remaining after the bitstream rewrite, following mp3gain's convention
REPLAYGAIN_ALBUM_GAIN / _PEAK-aSame, for the album pass
REPLAYGAIN_ALGORITHM--rg2 / --r128ITU-R BS.1770 โ€” records which measurement produced the values (v3.1+)
MP3GAIN_UNDO, MP3GAIN_MINMAXAny applymp3gain-compatible undo state, read back by -u

Because the ReplayGain values are residuals, a ReplayGain-blind player and a ReplayGain-aware one end up at the same loudness. -s c prints the stored tags, -s d deletes them, and -s s applies gain without writing any.

Exit codes

CodeMeaning
0Success. Also returned by -h and -v.
1Failure โ€” invalid arguments, unreadable or undecodable input, or a write error.

In a batch, one unreadable file aborts the run by default. Add --skip-errors to report and continue, which is what you usually want for scheduled library sweeps.

Environment variables

VariableEffect
MP3RGAIN_THREADSDefault worker-thread count for analysis, equivalent to -j. An explicit -j / --threads flag wins; 0 means auto.

Useful for capping CPU use in containers or cron jobs without editing every command:

MP3RGAIN_THREADS=2 mp3rgain -r -R /music

Output formats

-o text is the human-readable default. -o tsv emits the tab-separated layout mp3gain produced, so existing parsers โ€” beets among them โ€” keep working unchanged. -o json is the option to reach for in new automation:

mp3rgain -o json -r song.mp3 | jq '.'

An unrecognised format argument falls back to TSV, matching how mp3gain behaved.

Recipes

Preview before touching anything

mp3rgain -n -r -R /music

Normalise a whole library, tolerating bad files

mp3rgain -r -R -k --skip-errors /music

-k limits the gain where a full correction would clip.

Roll back a mistake

mp3rgain -u -R /music

Undo works from the stored tag, so it restores the exact original bitstream regardless of how the gain was applied โ€” including AAC/M4A.

Audit what is already stored

mp3rgain -s c -R /music

Keep mtime stable for sync tools

mp3rgain -r -p -R /music

Without -p, rewriting a file updates its mtime, which makes rsync, Syncthing and most backup tools re-transfer the entire library.

Next