brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg's loudnorm filter evens out audio that is too quiet or too loud

Ffmpeg
~/tips/tip-ffmpeg-loudnorm-audio-level

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

Normalizes the loudness of audio or a video's soundtrack to a fixed target with ffmpeg.

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

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link