How to Use the FFmpeg Headphone Filter
This article provides a quick guide on how to use the
headphone filter in FFmpeg to convert multi-channel audio,
such as 5.1 or 7.1 surround sound, into a spatialized 3D binaural stereo
mix designed for headphones. You will learn the basic command structure,
how to map audio channels, and how to utilize Head-Related Impulse
Response (HRIR) files to achieve realistic spatial audio.
The headphone filter in FFmpeg uses Head-Related
Transfer Functions (HRTF) to simulate how sound from different
directions reaches human ears. To use this filter, you need two main
components: your multi-channel audio source and an HRIR audio file,
which contains the acoustic characteristics of the listening space.
Basic Command Syntax
The standard command structure for the headphone filter
requires mapping the channels of your input audio to the corresponding
channels in your HRIR file. Here is a basic example of converting a 5.1
surround sound file into a binaural headphone mix:
ffmpeg -i input_51.wav -i hrir.wav -filter_complex "[0:a][1:a]headphone=map=FL|FR|FC|LFE|SL|SR[out]" -map "[out]" output_binaural.wavParameter Breakdown
-i input_51.wav: The primary multi-channel audio input.-i hrir.wav: The HRIR coefficients file. This file must contain the impulse responses for each speaker position.-filter_complex: Used because the filter processes multiple input streams.[0:a][1:a]: Specifies that the filter takes the audio from the first input (index 0) and the HRIR coefficients from the second input (index 1).headphone=map=...: The filter name followed by the channel mapping. The map order (e.g.,FL|FR|FC|LFE|SL|SR) must match the order of the impulse responses present in yourhrir.wavfile.-map "[out]": Maps the processed binaural stereo output to the destination file.
Customizing the Gain
Binaural processing can sometimes result in a drop in volume. You can
adjust the output volume using the gain option within the
filter. For example, to apply a gain of 12 dB:
ffmpeg -i input_51.wav -i hrir.wav -filter_complex "[0:a][1:a]headphone=map=FL|FR|FC|LFE|SL|SR:gain=12[out]" -map "[out]" output_binaural.wavSourcing HRIR Files
To get the best results, you need high-quality HRIR files. These are widely available for free online from public acoustic databases such as the Listen Database, CIPIC, or MIT’s KEMAR project. They are typically distributed as multi-channel WAV files. Make sure the channel order of the HRIR WAV file you download matches the map parameter in your FFmpeg command.