Configure FFmpeg afir Filter Frequency Domain Convolution

This article explains how to configure the frequency-domain convolution settings in the FFmpeg afir (Finite Impulse Response) filter. You will learn how to adjust FFT partition sizes using the maxp and minp parameters to optimize the balance between CPU performance and audio latency, complete with practical command-line examples.

How the afir Filter Uses Frequency-Domain Convolution

The afir filter applies an impulse response (IR) to an audio stream using partitioned frequency-domain convolution (specifically, the overlap-save method). Instead of calculating convolution in the time domain—which is computationally expensive for long impulse responses—FFmpeg converts the audio into the frequency domain using Fast Fourier Transforms (FFTs).

By partitioning the impulse response into smaller blocks, FFmpeg can process audio with significantly lower latency while maintaining high computational efficiency.

Key Configuration Parameters

To control how the frequency-domain convolution is partitioned, you must configure two main parameters in the afir filter:

Choosing the Right Settings

1. Low-Latency Configuration

If you are using the filter for real-time audio processing (such as live streaming or monitoring), you should reduce the partition sizes. This forces FFmpeg to use smaller FFT blocks, reducing the time delay before audio is output.

2. High-Efficiency Configuration

If you are batch-processing files offline and want to minimize CPU usage, you should increase the partition sizes. Larger blocks allow the FFT algorithm to run much faster at the expense of latency.

Example Commands

To apply these settings, pass the parameters to the afir filter inside your FFmpeg command. The filter requires two inputs: the main audio stream (index 0:a) and the impulse response file (index 1:a).

Example: Low-Latency Setup

This command configures the convolution engine to use a minimum partition size of 1024 samples and a maximum partition size of 2048 samples:

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

Example: High-Efficiency Setup

This command configures the engine to use a uniform, large partition size of 16384 samples, maximizing CPU throughput during offline rendering:

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