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.wav

Parameter Breakdown

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.wav

Sourcing 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.