How to Change Audio Pitch with FFmpeg

This article provides a quick overview and practical guide on how to change the pitch of an audio file using FFmpeg. You will learn the two primary methods for pitch shifting: using the high-quality rubberband filter to alter pitch without affecting speed, and utilizing the combined asetrate and atempo filters as a highly compatible alternative.

The most effective way to change audio pitch without affecting the playback speed (tempo) is by using the rubberband audio filter. Note that this filter requires your FFmpeg build to be compiled with library support (--enable-librubberband).

To scale the pitch, use the pitch option. A value of 1.0 represents the original pitch. Values above 1.0 raise the pitch, while values below 1.0 lower it.

To raise the pitch (e.g., by 1.5x):

ffmpeg -i input.mp3 -af "rubberband=pitch=1.5" output.mp3

To lower the pitch (e.g., by 0.8x):

ffmpeg -i input.mp3 -af "rubberband=pitch=0.8" output.mp3

Method 2: Pitch Shifting with Asetrate and Atempo (Standard Method)

If your version of FFmpeg does not support the rubberband filter, you can achieve pitch shifting by combining asetrate (which changes the sample rate, altering both pitch and speed) and atempo (which restores the original speed).

First, determine your source audio’s sample rate (usually 44,100 Hz or 48,000 Hz). You will multiply this sample rate by your desired pitch factor, and then divide the tempo by the same factor to keep the speed normal.

To raise the pitch (e.g., by 1.25x for a 44.1 kHz file): * New sample rate: \(44100 \times 1.25 = 55125\) * Tempo compensation: \(1 / 1.25 = 0.8\)

ffmpeg -i input.mp3 -af "asetrate=55125,atempo=0.8" output.mp3

To lower the pitch (e.g., by 0.8x for a 44.1 kHz file): * New sample rate: \(44100 \times 0.8 = 35280\) * Tempo compensation: \(1 / 0.8 = 1.25\)

ffmpeg -i input.mp3 -af "asetrate=35280,atempo=1.25" output.mp3

(Note: The atempo filter in FFmpeg only accepts values between 0.5 and 2.0. If your tempo adjustment falls outside of this range, you must chain multiple atempo filters together, such as atempo=0.5,atempo=0.5 for a speed of 0.25.)


Method 3: Changing Pitch and Speed Simultaneously

If you want to mimic a vinyl record or tape speed effect, where raising the pitch also speeds up the audio, you only need to use the asetrate filter.

ffmpeg -i input.mp3 -af "asetrate=48000*1.5" output.mp3

This command multiplies the sample rate of a 48 kHz file by 1.5, resulting in both a higher pitch and a faster playback speed.