FFmpeg afir Filter Guitar Cabinet Simulation Guide

Applying a speaker cabinet impulse response (IR) to a direct-input (DI) electric guitar recording is essential for eliminating harsh frequencies and shaping a realistic, full-bodied guitar tone. This guide demonstrates how to apply a cabinet impulse response directly to your audio tracks using FFmpeg's built-in afir (Audio Finite Impulse Response) filter without opening a Digital Audio Workstation (DAW).

Prerequisites

To perform cabinet simulation via FFmpeg, you need two audio files:

  1. The Source Audio: A raw preamped or distorted guitar track (typically a WAV or FLAC file) lacking cabinet emulation.
  2. The Impulse Response (IR): A standard cabinet IR file, which is an uncompressed WAV file containing the acoustic profile of a guitar speaker cabinet and microphone setup.

Basic Cabinet Simulation Command

The afir filter takes two audio inputs: the primary audio track and the impulse response file. It performs mathematical convolution between the two signals.

ffmpeg -i guitar_input.wav -i cabinet_ir.wav -filter_complex "[0:a][1:a]afir=dry=0:wet=1[out]" -map "[out]" output_cab.wav

Command Breakdown

  • -i guitar_input.wav: Specifies your original guitar recording as input 0.
  • -i cabinet_ir.wav: Specifies the cabinet impulse response as input 1.
  • -filter_complex "[0:a][1:a]afir=dry=0:wet=1[out]":
    • [0:a][1:a]: Feeds the audio streams of both inputs into the afir filter.
    • dry=0: Mutes the direct, unprocessed guitar signal completely.
    • wet=1: Sets the processed cabinet-convolved signal to full volume (standard behavior for guitar cabinet simulation).
    • [out]: Labels the output stream.
  • -map "[out]": Ensures the output file contains the convolved audio stream.
  • output_cab.wav: The resulting audio file with the simulated cabinet applied.

Preventing Digital Clipping with Gain Adjustment

Convolution often dramatically increases the overall peak volume of the audio signal. To prevent digital distortion or clipping, apply gain reduction either within the afir filter or by chaining a volume filter.

Using the irgain parameter inside afir:

ffmpeg -i guitar_input.wav -i cabinet_ir.wav -filter_complex "[0:a][1:a]afir=dry=0:wet=1:irgain=0.5[out]" -map "[out]" output_cab.wav

Alternatively, chain the volume filter after convolution:

ffmpeg -i guitar_input.wav -i cabinet_ir.wav -filter_complex "[0:a][1:a]afir=dry=0:wet=1[cab];[cab]volume=-6dB[out]" -map "[out]" output_cab.wav

Handling Mono and Stereo Configurations

Guitar DI tracks are generally mono, while cabinet IRs may be mono or stereo. The afir filter automatically matches channel layouts, but if you want to apply a stereo IR to a mono guitar track to create a wider stereo image, convert the mono track to stereo prior to convolution:

ffmpeg -i mono_guitar.wav -i stereo_ir.wav -filter_complex "[0:a]aformat=channel_layouts=stereo[guitar_stereo];[guitar_stereo][1:a]afir=dry=0:wet=1[out]" -map "[out]" output_stereo_cab.wav