Downmix 5.1 to Stereo with FFmpeg Pan Filter
This article explains how to use the FFmpeg pan audio
filter to downmix 5.1 surround sound to a 2-channel stereo format. You
will learn the syntax of the pan filter, how the audio
channels are mapped, and how to apply custom weights to control the
exact volume distribution of the center, surround, and subwoofer
channels into the left and right stereo outputs.
Understanding the Pan Filter Syntax
The pan filter allows you to reroute and mix audio
channels with precise control. To downmix 5.1 to stereo, you define a
stereo output layout and specify how the original six channels are
combined into the two output channels: c0 (Left) and
c1 (Right).
The basic syntax for the filter is:
pan=layout|output_channel_0=specification|output_channel_1=specification
In a 5.1 audio track, the input channels are typically defined as: * FL: Front Left * FR: Front Right * FC: Front Center * LFE: Low Frequency Effects (Subwoofer) * BL: Back Left (or SL: Surround Left) * BR: Back Right (or SR: Surround Right)
Applying Custom Weights
When downmixing, you must assign a coefficient (weight) between
0.0 and 1.0 to each input channel to determine
how much of its signal goes into the stereo channels.
A common balanced custom downmix configuration allocates: * Full
strength to the Left/Right channels (1.0). * Reduced
strength to the Center channel (0.707 or -3dB)
so dialogue does not overpower the stereo field. * Reduced strength to
the Surround channels (0.707 or -3dB) to
maintain a sense of space without muddying the mix. * Moderate strength
to the Subwoofer (0.5 or -6dB) to retain bass
response without causing distortion.
The FFmpeg Command
Use the following command to apply these custom weights:
ffmpeg -i input.mkv -c:v copy -af "pan=stereo|c0=1.0*FL + 0.707*FC + 0.707*BL + 0.5*LFE|c1=1.0*FR + 0.707*FC + 0.707*BR + 0.5*LFE" output.mp4Command Breakdown
-i input.mkv: Specifies the input multi-channel video file.-c:v copy: Copies the video stream directly without re-encoding to save time and preserve video quality.-af: Applies the audio filter.pan=stereo: Sets the output to a standard stereo layout.c0=1.0*FL + 0.707*FC + 0.707*BL + 0.5*LFE: Creates the Left stereo channel by combining 100% of Front Left, 70.7% of Center, 70.7% of Back Left, and 50% of the LFE channel.c1=1.0*FR + 0.707*FC + 0.707*BR + 0.5*LFE: Creates the Right stereo channel using the corresponding right-side inputs.
Managing Audio Clipping
If the sum of the coefficients in your formula exceeds
1.0, the resulting audio might exceed the maximum digital
volume limit, causing clipping (distortion).
FFmpeg’s pan filter automatically scales down all inputs
proportionally if the sum of the weights for a channel is greater than
1.0. If you want to bypass this automatic normalization and
force your exact custom volume levels, you can prefix the layout with a
pseudo channel layout or manually lower your coefficients
so that their sum equals 1.0 (for example, using
0.5*FL + 0.3*FC + 0.2*BL).