How to Use FFmpeg Rubberband for Audio Pitch Shifting
This guide explains how to use the rubberband filter in
FFmpeg to perform high-quality audio pitch shifting without changing the
audio’s tempo. You will learn the basic command structure, how to
calculate pitch shifts using semitones, and how to adjust pitch and
tempo independently using the Rubber Band library integration.
Prerequisites
To use this filter, your FFmpeg build must be compiled with support
for the Rubber Band library. You can verify this by running
ffmpeg -filters in your terminal and checking if
rubberband is listed. If it is missing, you must install
the librubberband package and compile FFmpeg with the
--enable-librubberband flag.
Basic Pitch Shifting Syntax
The rubberband filter uses a scale factor to shift the
pitch. A value of 1.0 represents the original pitch.
To shift the pitch up or down, use the following syntax:
ffmpeg -i input.mp3 -af "rubberband=pitch=1.5" output.mp3pitch=1.5: Increases the pitch. A factor of2.0shifts the pitch up by one octave.pitch=0.5: Decreases the pitch. A factor of0.5shifts the pitch down by one octave.
Pitch Shifting by Semitones
Because the pitch parameter requires a multiplier rather
than a semitone value, you must calculate the ratio. The formula to
shift pitch by \(n\) semitones is:
\[\text{Pitch Factor} = 2^{(n/12)}\]
Here are the pitch factor values for common semitone shifts:
| Semitone Shift | Pitch Factor Value |
|---|---|
| +1 Semitone | 1.05946 |
| +2 Semitones | 1.12246 |
| +5 Semitones (Perfect 4th) | 1.33484 |
| -1 Semitone | 0.94387 |
| -2 Semitones | 0.89090 |
| -5 Semitones | 0.74915 |
Example Command (+2 Semitones):
ffmpeg -i input.wav -af "rubberband=pitch=1.12246" output.wavAdjusting Pitch and Tempo Independently
The primary benefit of the rubberband filter over
options like atempo or asetrate is its ability
to adjust pitch and tempo independently with minimal transients and
phasing artifacts.
To speed up the audio while keeping the pitch higher, use both the
pitch and tempo options:
ffmpeg -i input.mp3 -af "rubberband=pitch=1.2:tempo=1.5" output.mp3To change only the tempo while preserving the original pitch, set
pitch to 1.0 and adjust the
tempo:
ffmpeg -i input.mp3 -af "rubberband=pitch=1.0:tempo=0.85" output.mp3