How to Upmix Stereo to 5.1 in FFmpeg Using Pan

This guide explains how to use the FFmpeg pan audio filter to upmix a stereo (2.0) audio track into a 5.1 surround sound channel layout. You will learn the command syntax, the channel mapping configurations, and how to apply custom weight coefficients to distribute the left and right stereo inputs across the six target surround sound channels.

Understanding the 5.1 Channel Layout

A standard 5.1 surround sound layout consists of six distinct channels. When mapping channels in FFmpeg, they are identified by the following labels:

  • FL: Front Left
  • FR: Front Right
  • FC: Front Center
  • LFE: Low-Frequency Effects (Subwoofer)
  • BL: Back Left (Surround Left)
  • BR: Back Right (Surround Right)

In a stereo input file, the audio channels are represented as c0 (Left channel) and c1 (Right channel).

The Pan Filter Syntax

The pan filter configuration requires you to specify the output channel layout followed by the specific mix equations for each output channel. The basic structure is:

pan=layout|output_channel=equation|output_channel=equation|...

For a 5.1 output, you start with pan=5.1. You then define how c0 (Left) and c1 (Right) map to the six output channels using multiplication factors (weights) ranging generally from 0.0 to 1.0.

Custom Weights Configuration

To create a realistic surround sound experience from a stereo source, you can distribute the audio using these custom weights:

  • Front Left (FL): 100% of the input Left channel (1.0*c0).
  • Front Right (FR): 100% of the input Right channel (1.0*c1).
  • Front Center (FC): A balanced mix of both Left and Right channels, attenuated to prevent clipping (0.7*c0 + 0.7*c1).
  • Subwoofer (LFE): A combined mono signal of both channels focusing on low frequencies, typically heavily attenuated (0.5*c0 + 0.5*c1).
  • Back Left (BL): A attenuated copy of the input Left channel to feed the rear left speaker (0.7*c0).
  • Back Right (BR): A attenuated copy of the input Right channel to feed the rear right speaker (0.7*c1).

The FFmpeg Command

To apply these custom weights, run the following FFmpeg command in your terminal:

ffmpeg -i input.wav -af "pan=5.1|FL=c0|FR=c1|FC=0.7*c0+0.7*c1|LFE=0.5*c0+0.5*c1|BL=0.7*c0|BR=0.7*c1" output.wav

Key Considerations for Adjusting Weights

  • Clipping Prevention: If the sum of the weights for a single output channel (like the Center channel where 0.7 + 0.7 = 1.4) exceeds 1.0, the audio may clip and distort. FFmpeg automatically downscales the volume of the entire mix by default to prevent this.
  • Disabling Auto-Normalization: If you want to force FFmpeg to use your exact weights without automatic volume downscaling, prepend a negative sign to the channel layout (e.g., pan=-5.1|...). If you do this, ensure your weights for any single channel do not sum to more than 1.0.