Use FFmpeg afir Filter for Audio Convolution

This article provides a practical guide on how to apply a convolver filter to an audio stream using FFmpeg’s afir (Audio Finite Impulse Response) filter. You will learn how to combine a primary audio track with an Impulse Response (IR) file to recreate acoustic spaces, cabinet simulations, or custom filter effects, along with the exact command-line syntax required.

Understanding the afir Filter

The afir filter in FFmpeg performs frequency-domain convolution. It takes two audio inputs: the primary audio signal you want to process, and a second audio stream containing the Impulse Response (IR). The IR represents the acoustic characteristics of a space (like a cathedral or a studio) or a piece of hardware (like a guitar amplifier cabinet).

Basic Command Syntax

To apply the convolution filter, you must pass both the target audio and the IR file as inputs, and then link them using filter_complex.

Here is the standard command structure:

ffmpeg -i input.wav -i impulse_response.wav -filter_complex "[0:a][1:a]afir=ginit=1[out]" -map "[out]" output.wav

Command Breakdown:

Adjusting Dry and Wet Mix

By default, the afir filter outputs only the wet (fully processed) signal. If you want to mix the original “dry” audio with the “wet” convolved audio, you can use the dry and wet parameters.

ffmpeg -i input.wav -i impulse_response.wav -filter_complex "[0:a][1:a]afir=dry=10:wet=10[out]" -map "[out]" output.wav

In this command, the values are represented in decibels (dB). Setting both to 10 (or 0 for no change) allows you to balance the level of the original sound against the strength of the convolution effect.

Handling Different Sample Rates

For the afir filter to work correctly, both the input audio and the impulse response file should share the same sample rate. If they do not, you can resample the impulse response on the fly using the aresample filter:

ffmpeg -i input.wav -i impulse_response.wav -filter_complex "[1:a]aresample=48000[ir];[0:a][ir]afir=ginit=1[out]" -map "[out]" output.wav

In this setup, the second input (the IR) is resampled to 48,000 Hz before being passed to the afir filter alongside the primary audio.