Configure Sample Rate and Channels with FFmpeg Rubberband

This article explains how to configure and manage the sample rate and channel count when using the rubberband audio filter in FFmpeg. While the rubberband filter is primarily designed for high-quality pitch shifting and time stretching, modifying the sample rate and channel layout requires combining it with FFmpeg’s native audio resampling and formatting filters within the same filtergraph.

Understanding how Rubberband handles Audio Properties

The rubberband filter does not natively change the sample rate or the physical channel count of your audio file during its process. Instead, it alters the pitch or tempo while preserving the input’s sample rate and channel configuration.

To change the sample rate or channel count of the output while applying rubberband, you must chain it with the aresample or aformat filters.

Configuring the Sample Rate

To change the sample rate (for example, to 44100 Hz or 48000 Hz) alongside the rubberband filter, chain the aresample filter immediately after the rubberband filter.

Use the following command structure to stretch the audio tempo and resample the output:

ffmpeg -i input.wav -af "rubberband=tempo=1.5,aresample=48000" output.wav

In this command: * rubberband=tempo=1.5 speeds up the audio to 150% of its original speed. * aresample=48000 resamples the resulting audio to 48 kHz.

Configuring the Channel Count

To change the channel layout (such as downmixing stereo to mono, or forcing a stereo output), use the aformat filter.

For example, to shift the pitch of an audio file and output it as a mono stream:

ffmpeg -i input.wav -af "rubberband=pitch=1.2,aformat=channel_layouts=mono" output.wav

If you need to change both the sample rate and the channel count simultaneously, you can define both parameters inside the aformat filter:

ffmpeg -i input.wav -af "rubberband=pitch=1.2,aformat=sample_rates=44100:channel_layouts=stereo" output.wav

The Rubberband “channels” Option

The rubberband filter includes an internal option named channels. It is important to note that this option does not change the number of output channels. Instead, it tells the filter how to process multi-channel audio (channel coupling).

The available options for the channels parameter are: * keep: Keeps the default processing behavior of the library. * independent: Processes each channel entirely independently. * subgroup: Processes channels in acoustic subgroups (e.g., stereo pairs).

To specify independent channel processing while shifting pitch:

ffmpeg -i input.wav -af "rubberband=pitch=1.5:channels=independent" output.wav