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.mp3How 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. Asinewave creates a smooth, continuous transition between the speakers. Alternative options includetriangle,square,sawup, andsawdown.hz=0.5: Controls the speed of the panning cycle in Hertz. A value of0.5means the sound completes one full panning cycle (left to right and back) every two seconds.amount=1: Sets the modulation depth from0.0to1.0. A value of1provides maximum separation, completely muting one side when the other reaches peak volume. Lower values (such as0.7) provide a subtler panning effect.offset_l=0andoffset_r=0.5: These define the starting phase offsets for each channel. Settingoffset_l=0andoffset_r=0.5puts 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.mp3In 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.mp3The square wave instantly switches the signal from one
channel to the other at the specified frequency, creating a classic
ping-pong effect.