Some files are whisper-quiet and the next one blows your ears off, and reaching for the volume button every few minutes gets old. ffmpeg has a filter for this, loudnorm, which brings audio to a target loudness using the EBU R128 standard that broadcasters use.
ffmpeg -i in.mp4 -c:v copy -af loudnorm=I=-23:TP=-2:LRA=7 -ar 48000 -c:a aac -b:a 192k out.mp4
I is the target integrated loudness in LUFS, TP the maximum true peak and LRA the loudness range. TP and LRA are the filter’s own defaults; I defaults to -24, and -23 is the usual EBU R128 target. -c:v copy leaves the video stream untouched, so only the audio gets processed.
The -ar 48000 is there for a reason. To catch true peaks, loudnorm upsamples the audio to 192 kHz, and the documentation tells you to set the output rate yourself with -ar. Without it you can end up with a 192 kHz audio track nobody needs.
I’d use this for recordings, home videos or a podcast you’re editing, rather than for your whole media library. A server like Jellyfin plays what’s in the file, and re-encoding the audio of hundreds of films for a bit more consistency isn’t worth it to me.
The caveat: this is the single-pass version, which adjusts the level on the fly (dynamic mode). For the most accurate result on a file, run it twice. The first pass with print_format=json measures the input, and the second pass gets those numbers through measured_I, measured_LRA, measured_TP and measured_thresh, so it can use a linear gain change instead. And since the audio is re-encoded, you can’t combine this with -c:a copy.
Further reading: FFmpeg filters: loudnorm