Skip to content

Normalizing Audio in a Video

Adjust the audio levels in a video file to a standard volume using FFmpeg, improving the listening experience by ensuring consistent audio playback levels.

VideoAlchemy Compose File

version: 1

generate_path: "./generated"

tasks:
  - name: Normalizing Audio in a Video
    command: ffmpeg
    inputs:
      - id: input_1
        source: 'input.mp4'
    codecs:
      - audio_filters:
          - name: loudnorm
    outputs:
      - id: output_1
        overwrite: true
        source: 'output.mp4'

Command

ffmpeg -i input.mp4 -filter:a loudnorm output.mp4

Parameters

  • -i input.mp4: Specifies the input video file. Replace input.mp4 with the path to your source video file.
  • -filter:a loudnorm: Applies the loudness normalization audio filter. This filter analyzes the audio to adjust its loudness to a target level.

Possible Errors

  • File not found: Occurs if FFmpeg cannot locate the input file. Ensure the path to the file is correct.
  • Unsupported codec: May occur if the input or output format does not support the audio stream's codec. Ensure compatibility or consider transcoding the audio stream.
  • Permission denied: Occurs if FFmpeg does not have the necessary permissions to read the input file or write to the output file. Ensure that the files and directories have the correct permissions.

GPU Acceleration Command

Audio normalization is a CPU-bound process, focusing on analyzing and adjusting audio levels. Therefore, GPU acceleration does not directly apply to this operation. However, if you're also performing video processing tasks that benefit from GPU acceleration, you can combine them as follows:

For Nvidia GPUs:

ffmpeg -i input.mp4 -filter:a loudnorm -c:v h264_nvenc output.mp4

Additional Information

  • Loudnorm Filter: The loudnorm filter performs loudness normalization according to the EBU R128 standard. It can be customized with various options (e.g., setting I, LRA, TP thresholds) to fine-tune the normalization process.
  • Two-Pass Mode: For optimal results, loudnorm can run in a two-pass mode. The first pass analyzes the audio to determine the normalization parameters, and the second pass applies these parameters. This approach requires running two separate FFmpeg commands, where the first pass generates a log of parameters to be used in the second.
  • Audio and Video Processing: While normalizing audio, you can simultaneously process the video track, including re-encoding, resizing, or applying filters. This consolidation can save processing time.
  • Quality Considerations: If re-encoding the audio or video, choose codecs and settings that balance quality and file size according to your needs. For audio, options like codec choice (-c:a) and bit rate (-b:a) are crucial.