How to Pitch Shift Audio Without Changing Speed in FFmpeg
This article provides a straightforward guide on how to shift the
pitch of an audio file using FFmpeg without altering its playback speed.
You will learn the exact command-line filters required to achieve this
effect, including the high-quality rubberband filter and
the widely compatible asetrate and atempo
combination.
Method 1: Using the Rubberband Filter (Recommended)
The highest-quality way to pitch-shift audio in FFmpeg is by using
the rubberband audio filter. This filter requires your
FFmpeg build to be compiled with the --enable-librubberband
library.
To scale the pitch, you use the pitch parameter. A value
of 1.0 represents the original pitch.
To raise the pitch (e.g., up by 50%):
ffmpeg -i input.mp3 -af "rubberband=pitch=1.5" output.mp3To lower the pitch (e.g., down by 20%):
ffmpeg -i input.mp3 -af "rubberband=pitch=0.8" output.mp3
Method 2: Using Asetrate and Atempo (Built-in)
If your version of FFmpeg does not support rubberband,
you can achieve the same effect using native filters. This method
involves changing the sample rate to alter the pitch
(asetrate), and then correcting the speed change using the
tempo filter (atempo).
First, find your input audio’s sample rate (typically
44100 Hz or 48000 Hz). You will multiply this
sample rate by your pitch scale factor, and then divide the tempo by the
same factor.
To raise the pitch (e.g., scale factor of 1.25):
ffmpeg -i input.mp3 -af "asetrate=44100*1.25,atempo=1/1.25" output.mp3To lower the pitch (e.g., scale factor of 0.8):
ffmpeg -i input.mp3 -af "asetrate=44100*0.8,atempo=1/0.8" output.mp3
Note: The atempo filter only accepts values between
0.5 and 2.0. If your speed correction factor
falls outside of this range, you must chain multiple atempo
filters together (for example, atempo=0.5,atempo=0.5 to
achieve a speed factor of 0.25).