How to Change Audio Pitch Without Changing Tempo in FFmpeg
This article provides a quick, practical guide on how to use the
rubberband audio filter in FFmpeg to adjust the pitch of an
audio file without affecting its playback speed (tempo). You will learn
the required FFmpeg commands, how to calculate precise pitch shifts
using semitones, and the prerequisite library needed to run these
commands successfully.
Prerequisites
To use the rubberband filter, your FFmpeg installation
must be compiled with the librubberband library. You can
verify if your FFmpeg version supports it by running:
ffmpeg -filters | grep rubberbandIf rubberband appears in the output, your installation
is ready.
Basic Command Structure
To change the pitch of an audio file without altering its tempo, use
the -af (audio filter) flag with the
rubberband filter and define the pitch scale
factor:
ffmpeg -i input.mp3 -af "rubberband=pitch=1.5" output.mp3In this command: * -i input.mp3 specifies the input
audio file. * -af "rubberband=pitch=1.5" applies the
rubberband filter. A value of 1.5 raises the pitch. *
output.mp3 is the resulting audio file.
How the Pitch Scale Factor Works
The pitch parameter accepts a scale factor where: *
1.0 is the original pitch (no change). *
Values greater than 1.0 raise the pitch
(e.g., 2.0 raises the pitch by one octave). *
Values between 0.0 and 1.0
lower the pitch (e.g., 0.5 lowers the pitch by one
octave).
Calculating Semitones
If you want to shift the pitch by a specific number of semitones, you can calculate the scale factor using the following formula:
\[\text{Scale Factor} = 2^{\frac{n}{12}}\]
Where \(n\) is the number of semitones you want to shift (use positive numbers to shift up, negative numbers to shift down).
Here are some common semitone conversion values:
| Semitone Shift | Pitch Scale Factor Formula | Calculated Value (approx.) |
|---|---|---|
| Up 1 semitone | \(2^{1/12}\) | 1.05946 |
| Up 2 semitones | \(2^{2/12}\) | 1.12246 |
| Up 5 semitones | \(2^{5/12}\) | 1.33484 |
| Down 1 semitone | \(2^{-1/12}\) | 0.94387 |
| Down 2 semitones | \(2^{-2/12}\) | 0.89090 |
| Down 5 semitones | \(2^{-5/12}\) | 0.74915 |
Example: Shifting Pitch Up by 3 Semitones
To shift the pitch up by 3 semitones (\(2^{3/12} \approx 1.1892\)), run:
ffmpeg -i input.wav -af "rubberband=pitch=1.1892" output.wavExample: Shifting Pitch Down by 4 Semitones
To shift the pitch down by 4 semitones (\(2^{-4/12} \approx 0.7937\)), run:
ffmpeg -i input.wav -af "rubberband=pitch=0.7937" output.wav