slhck / ffmpeg-normalize

Audio Normalization for Python/ffmpeg
MIT License
1.25k stars 117 forks source link

Use SOXR sample rate conversion #160

Closed Forza-tng closed 2 years ago

Forza-tng commented 2 years ago

Hi!

In order to get the best audio quality, it would be nice to use Soxr for sample rate conversion filter instead of the default 'swr' when it is available. In addition I'd like to see the possibility to specify the output bit depth, for example 24bit or 16bit, no matter what input format that is used.

https://ffmpeg.org/ffmpeg-resampler.html mentions that soxr is the preferable method.

slhck commented 2 years ago

Please use the --extra-output-options option to supply the needed flags, such as:

 -e '[ "-resampler", "soxr" ]'

Or -sample-fmt etc.

slhck commented 2 years ago

PS: To give you some background as to why this extra-options option is there, I cannot reasonably manually include all possible ffmpeg options that people might want to use, so you can specify them directly. Otherwise it would be too much of a maintenance burden, apart from the different option naming convention (one dash vs two dashes) and potential option clashes.

Forza-tng commented 2 years ago

Please use the --extra-output-options option to supply the needed flags, such as:

 -e '[ "-resampler", "soxr" ]'

Or -sample-fmt etc.

Thanks for the example. How would I add soxr options to the -e '[ "-resampler", "soxr" ]'. I'd like to match the following filter line resampler=soxr:out_sample_rate=48000:precision=28:cheby=1:dither_method=triangular

slhck commented 2 years ago

You should be able to add:

"-out_sample_rate" , "48000"

to the array. The manual you linked to contains all the options. Please add the remaining ones accordingly.

The string you showed belongs to the filter usage. The extra options I demonstrated are for the regular ffmpeg command line.

sergeevabc commented 11 months ago

Aggrrhh, pieces and clues. What would be an example command line with SOX resampler then? It seems ffmpeg-normalize in.wav -o out.wav -prf "aresample=resampler=soxr:osr=16000" does not work.

slhck commented 11 months ago

The -prf option is a pre-filter that gets applied before normalization. So you want a post-filter (-pof):

ffmpeg-normalize in.wav -o out.wav -pof "aresample=resampler=soxr:osr=16000"

That, however, leads to an error — a known bug — that can be fixed by explicitly supplying the output channel format:

ffmpeg-normalize in.wav -f -o out.wav -pof "aresample=resampler=soxr:osr=16000" -e "-ac 2"

(Please note that "does not work" is usually not a good error description. It helps to explain what specifically does not work.)

sergeevabc commented 10 months ago

@slhck, by the way, that bug was fixed after 2023-05-13. I have just verified: official FFMPEG 6.1 and a more recent custom build work fine w/o having to add -e "-ac 2".

slhck commented 10 months ago

Thanks for the info. I had checked with 6.0 and that still apparently has this bug.