How to Change FFmpeg Resampler to Soxr

This article provides a quick guide on how to switch the default audio resampler engine in FFmpeg from swresample to soxr (libsoxr) to achieve higher-quality audio resampling. You will learn how to verify if your FFmpeg build supports the SoX Resampler and the exact command-line arguments needed to enable and configure it.

Verify SoX Resampler Support

Before switching the resampler, you must ensure your FFmpeg installation was compiled with libsoxr support. Run the following command in your terminal:

ffmpeg -version

Look for --enable-libsoxr in the configuration block of the output. If it is present, you can proceed with using the soxr engine.

Method 1: Using the -resampler Option

The simplest way to globally switch the audio resampler engine is by using the -resampler flag in your FFmpeg command.

ffmpeg -i input.wav -resampler soxr -ar 48000 output.wav

In this command: * -resampler soxr tells FFmpeg to use the SoX Resampler instead of the default swresample. * -ar 48000 sets the output sample rate to 48 kHz.

Method 2: Using the aresample Audio Filter

For more precise control, you can specify the resampler engine directly inside the aresample audio filter chain using the -af flag.

ffmpeg -i input.wav -af "aresample=resampler=soxr:osr=48000" output.wav

In this filter graph: * resampler=soxr defines the engine. * osr=48000 (Output Sample Rate) defines the target sample rate.

Adjusting Soxr Quality Settings

The soxr engine allows you to customize the resampling precision and quality. You can adjust the precision (in bits) and the chebyshev phase-response.

For example, to set the precision to 28-bit (very high quality) using the audio filter, run:

ffmpeg -i input.wav -af "aresample=resampler=soxr:osr=48000:precision=28" output.wav