Prompt
How do I normalize audio loudness in a video processing pipeline?
Latest observation
To normalize audio loudness in a video processing pipeline, the usual goal is to make the perceived loudness consistent across clips, not just peak level. The best practice is to use loudness normalization based on standards like EBU R128 or ITU-R BS.1770, rather than simple peak normalization.
Recommended approach
1) Measure loudness
Analyze the audio to get:
- Integrated loudness in LUFS/LKFS
- True peak
- Optionally loudness range (LRA)
Common target values:
- Streaming / online video: around -14 LUFS
- Broadcast / EBU R128: -23 LUFS
- YouTube-style delivery: often -14 to -16 LUFS
- Podcast/video mixed output: depends on platform, but usually around -16 LUFS for stereo
2) Apply gain to reach target loudness
Adjust the overall gain so the integrated loudness matches your target.
3) Prevent clipping
After gain adjustment, ensure true peaks stay below a ceiling such as:
- -1 dBTP for safe delivery
- Sometimes -2 dBTP if you want extra headroom
If boosting causes peaks to exceed the ceiling, use a limiter or reduce gain.
Typical pipeline
- Decode audio from video
- Measure loudness
- Compute gain offset
- Apply gain
- Limit true peaks if needed
- Re-mux audio back into video
Example with FFmpeg
FFmpeg has a loudness normalization filter called loudnorm.
Two-pass loudness normalization
This is the most accurate method.
Pass 1: measure
ffmpeg -i input.mp4 -af loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json -f null -
This prints measured values such as:
- input integrated loudness
- input true peak
- loudness range
- threshold
- normalization offset
Pass 2: apply normalization
Use the measured values from pass 1:
ffmpeg -i input.mp4 -af loudnorm=I=-16:TP=-1.5:LRA=11:measured_I=-20.3:measured_TP=-2.1:measured_LRA=7.5:measured_thresh=-30.0:offset=4.3:linear=true:print_format=summary output.mp4
If you want simpler but slightly less accurate processing, you can use one-pass mode:
ffmpeg -i input.mp4 -af loudnorm=I=-16:TP=-1.5:LRA=11 output.mp4
If you only need peak normalization
Peak normalization sets the maximum sample peak to a target, like -1 dBFS. This is simpler but does not make perceived loudness consistent.
Example:
ffmpeg -i input.mp4 -af volume=1.5 output.mp4
But this is only useful if you already know the required gain, or if you measured peaks separately.
For batch pipelines
If you process many videos:
- Measure each file first
- Store loudness metadata
- Apply the appropriate gain in a second step
- Optionally normalize per segment or per clip before final assembly
If you concatenate clips, it’s usually better to:
- Normalize each source clip consistently before editing, or
- Normalize the final mixed output after editing, depending on the creative intent
Practical recommendations
- Use loudness normalization, not peak normalization
- Target -14 LUFS for web video unless your delivery spec says otherwise
- Keep true peak ≤ -1 dBTP
- Use two-pass normalization for best results
- If there are drastic dynamic range differences, add a compressor/limiter before final loudness normalization
Example workflow in code/pipeline terms
- Extract audio track
- Run loudness analysis
- Calculate gain:
gain_db = target_lufs - measured_lufs
- Apply gain and limiter
- Encode/mux back into video container
If you want, I can also give you:
- an FFmpeg script for batch normalization
- a Python example using
ffmpegorpydub - a Node.js pipeline
- or advice for a specific target platform like YouTube, broadcast, or podcast delivery.
Brands