How to Set Soxr Resampler Precision in FFmpeg
When converting audio sample rates in FFmpeg, the SoX Resampler (soxr) library offers high-quality resampling that often surpasses the default FFmpeg resampler. This article explains how to configure the precision of the soxr resampler using FFmpeg command-line arguments, detailing the available bit-depth options and providing clear, practical examples.
Using the
aresample Audio Filter
The standard and most reliable way to set the soxr resampler
precision is by utilizing the aresample audio filter
(-af). You must explicitly define the resampler as
soxr and then pass the precision
parameter.
Here is the basic command structure:
ffmpeg -i input.wav -af "aresample=resampler=soxr:precision=28" output.wavUnderstanding the Precision Values
The precision parameter is defined in bits. It
determines the quality of the Chebyshev window used by the resampler.
Higher precision values yield cleaner audio with fewer artifacts but
require more CPU processing power.
The available precision levels include:
- 16 (16-bit): Suitable for quick, low-latency processing where CD-quality audio is acceptable.
- 20 (20-bit): The default setting. It offers a great balance between processing speed and audio quality.
- 24 (24-bit): High-quality setting, ideal for mastering and professional audio applications.
- 28 (28-bit): Very high quality, pushing the limits of human hearing perception.
- 32 (32-bit): Extreme quality. It utilizes the maximum 32-bit floating-point precision, resulting in the slowest processing times.
Alternative Method: Using
swr_opts
If you are transcoding audio as part of a larger video encoding
pipeline and prefer not to use audio filters, you can set the resampler
precision globally using the -swr_opts (Software Resampler
Options) flag:
ffmpeg -i input.mp4 -c:a flac -swr_opts resampler=soxr:precision=24 output.mkvBy specifying these options, FFmpeg bypasses its default internal resampler and utilizes SoX’s advanced algorithms at your specified bit-depth, ensuring optimal audio fidelity for your target output.