Auto-Pan Audio Left and Right with FFmpeg apulsator

This article explains how to use FFmpeg's built-in apulsator audio filter to create an automated panning effect that smoothly shifts sound between the left and right stereo channels. By modulating channel amplitudes with opposing phase offsets, you can transform static audio tracks into dynamic, spatially animated stereo mixes without requiring a digital audio workstation (DAW).

The Basic Auto-Pan Command

To apply a basic left-to-right auto-pan effect, use the apulsator audio filter in your FFmpeg command:

ffmpeg -i input.mp3 -af "apulsator=mode=sine:hz=0.5:amount=1:offset_l=0:offset_r=0.5" output.mp3

How the Parameters Work

The auto-pan effect relies on setting an out-of-phase relationship between the left and right audio channels. Here is a breakdown of the key parameters used:

  • mode=sine: Sets the modulation waveform. A sine wave creates a smooth, continuous transition between the speakers. Alternative options include triangle, square, sawup, and sawdown.
  • hz=0.5: Controls the speed of the panning cycle in Hertz. A value of 0.5 means the sound completes one full panning cycle (left to right and back) every two seconds.
  • amount=1: Sets the modulation depth from 0.0 to 1.0. A value of 1 provides maximum separation, completely muting one side when the other reaches peak volume. Lower values (such as 0.7) provide a subtler panning effect.
  • offset_l=0 and offset_r=0.5: These define the starting phase offsets for each channel. Setting offset_l=0 and offset_r=0.5 puts the channels 180 degrees out of phase. When the left channel's amplitude is at its maximum, the right channel is at its minimum, creating the back-and-forth movement.

Synchronizing to a Specific Tempo (BPM)

If you are working with music and want the panning to match a specific beat, switch the timing mode to bpm:

ffmpeg -i input.mp3 -af "apulsator=mode=sine:timing=bpm:bpm=120:amount=0.8:offset_l=0:offset_r=0.5" output.mp3

In this example, timing=bpm instructs the filter to use beats per minute rather than Hertz, synchronizing the movement to a 120 BPM track.

Creating a Hard "Ping-Pong" Pan

For a sudden, rhythmic jump between the left and right speakers rather than a smooth sweep, change the waveform mode to square:

ffmpeg -i input.mp3 -af "apulsator=mode=square:hz=1:amount=1:offset_l=0:offset_r=0.5" output.mp3

The square wave instantly switches the signal from one channel to the other at the specified frequency, creating a classic ping-pong effect.