[Libav-user] Audio resampling changes slightly the speed of the music

Hristo Ivanov hivanov.ffmailing at gmail.com
Thu Oct 25 14:29:28 EEST 2018


Hi Yury

On Thu, Oct 25, 2018 at 11:18 AM Yurii Monakov <monakov.y at gmail.com> wrote:

> Resampling can introduce additional samples in the output (because
> out_samples is rounded).
> You should keep track of input time and output time to calculate number of
> output samples.
>
> Yurii
>

I am not sure if that is true or not.

In his sample code he is rounding up when allocating memory:

int out_samples = (int) av_rescale_rnd(
swr_get_delay(swrContext, codecContext->sample_rate) + frame->nb_samples,
out_sample_rate,
codecContext->sample_rate,
AV_ROUND_UP);
av_samples_alloc(&localBuffer, NULL, 2, out_samples, AV_SAMPLE_FMT_FLT, 0);

Lets say out_samples is 1000.6 without rounding and 1001 rounded. Memory
for 1001 samples is allocated.

Then he calls swr_convert which returns the number of converted samples:

int numberSampleOutputPerChannel = swr_convert(swrContext,
&localBuffer, out_samples,
(const uint8_t **) frame->extended_data, frame->nb_samples);

To my understanding the first call of swr_convert will return 1000
samples(numberSampleOutputPerChannel is 1000).

The following is not technically correct but helps me illustrate my point:
*The 0.6 extra samples will be buffered and returned in the next call to
swr_convert. The second call will be fed 1000.6 + 0.6 samples and return
1001 samples and buffer 0.2.*

I am not 100% sure that the previous is true, can someone confirm it?
I will test it later.

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20181025/4ad5573f/attachment.html>


More information about the Libav-user mailing list