Audio resampler (SoX) returns different result

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Audio resampler (SoX) returns different result

林至善
Hi all,

I need a down-sampled(=8kHz) version of my input.wav file (=16kHz).

According to
https://trac.ffmpeg.org/wiki/FFmpeg%20and%20the%20SoX%20Resampler,
I use the command below

ffmpeg -i In16k.wav -af aresample=resampler=soxr -ar 8000 Out8k.wav

It works well, but I found that every time I run the command above,
it returns the "Out8k.wav" with a slightly different(in PCM value).

The question is :
  *Is the difference I found a normal phenomenon?
  *If I want a resampler which always returns the same result, how can I do?

Sorry about my poor English.
Thank you all.


LCS
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Audio resampler (SoX) returns different result

Moritz Barsnick
Hi,

On Mon, Nov 19, 2018 at 16:14:03 +0800, 林至善 wrote:

> I need a down-sampled(=8kHz) version of my input.wav file (=16kHz).
>
> According to
> https://trac.ffmpeg.org/wiki/FFmpeg%20and%20the%20SoX%20Resampler,
> I use the command below
>
> ffmpeg -i In16k.wav -af aresample=resampler=soxr -ar 8000 Out8k.wav
>
> It works well, but I found that every time I run the command above,
> it returns the "Out8k.wav" with a slightly different(in PCM value).

Interesting. But first of all, I believe your command line is wrong.
"-ar" uses ffmpeg's native resampler, I believe. Using the filter, you
need to pass the rate to the filter itself:

ffmpeg -i In16k.wav -af aresample=resampler=soxr:sample_rate=8000 Out8k.wav

You could also just use any other resampler, e.g. by omitting "-af
aresample=resampler=soxr" fully.

I don't have soxr support, so I can't reproduce your issue. It should
be deterministic. Perhaps some metadata thing.

>   *If I want a resampler which always returns the same result, how can I do?

Can you try whether the command line option "-bitexact" changes
anything?

Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Audio resampler (SoX) returns different result

Carl Eugen Hoyos-2
In reply to this post by 林至善
2018-11-19 9:14 GMT+01:00, 林至善 <[hidden email]>:
> Hi all,
>
> I need a down-sampled(=8kHz) version of my input.wav file (=16kHz).
>
> According to
> https://trac.ffmpeg.org/wiki/FFmpeg%20and%20the%20SoX%20Resampler,
> I use the command below
>
> ffmpeg -i In16k.wav -af aresample=resampler=soxr -ar 8000 Out8k.wav

Please always provide the command line you test together with
the complete, uncut console output when asking for support here.

> It works well, but I found that every time I run the command above,
> it returns the "Out8k.wav" with a slightly different(in PCM value).
>
> The question is :
>   *Is the difference I found a normal phenomenon?

>   *If I want a resampler which always returns the same result, how can I do?

FFmpeg's default resampler is deterministic.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Audio resampler (SoX) returns different result

林至善
Hello *Moritz*:

*Thank you so much for responding to my issue :)*

> Interesting. But first of all, I believe your command line is wrong.
> "-ar" uses ffmpeg's native resampler, I believe. Using the filter, you
> need to pass the rate to the filter itself:

> ffmpeg -i In16k.wav -af aresample=resampler=soxr:sample_rate=8000
Out8k.wav

I have tried it, but got the same result(resampler works well but slightly
different when I run this command again).

> You could also just use any other resampler, e.g. by omitting "-af
> aresample=resampler=soxr" fully.

Thanks! It is the default resampler I guess. It is deterministic.
But the default resampler brings some "aliasing" to the resampled auidio.

> I don't have soxr support, so I can't reproduce your issue. It should
> be deterministic. Perhaps some metadata thing.

Metadata. I am not sure what it means but I think it must be something
important.
Is it about my environment setting? Can I fix it?

//
----------------------------------------------------------------------------------------------------------------------------------

Hello *Carl Eugen*:

*So pleased to hear from you :)*

> Please always provide the command line you test together with
> the complete, uncut console output when asking for support here.

↓ run "ffmpeg -i Fsweep16.wav -af aresample=resampler=soxr -ar 8000
Fsweep8.wav"
[image: 159.JPG]
↓  run again.
[image: 147.JPG]

> FFmpeg's default resampler is deterministic.

Thank you for your advice. I tried this:

ffmpeg -i Fsweep16.wav -ar 8000 Fsweep8.wav

It works well and it is deterministic. It uses the resampler "swr" I guess,
but with slightly aliasing in resampled audio.
I think the 'soxr' is necessary in my case, but I am not sure if I should
ask for support here or libsxor?

//
----------------------------------------------------------------------------------------------------------------------------------

Thank you all again for your support.

LCS

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

159.JPG (216K) Download Attachment
147.JPG (218K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Audio resampler (SoX) returns different result

Moritz Barsnick
On Tue, Nov 20, 2018 at 10:03:48 +0800, 林至善 wrote:
> It works well and it is deterministic. It uses the resampler "swr" I guess,
> but with slightly aliasing in resampled audio.
> I think the 'soxr' is necessary in my case, but I am not sure if I should
> ask for support here or libsxor?

I could now reproduce your issue with a libsoxr enabled ffmpeg. It
appears that libsoxr produces slightly different results each time, as
if rounding arbitrarily. It seems indetermenistic. You should take it
up with libsoxr.

The try native resampler, but with some of the other dither methods
described in
$ ffmpeg -h filter=aresample
and in the "Resampler Options" section of ffmpeg's documentation.

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".