Hi Yury On Thu, Oct 25, 2018 at 11:18 AM Yurii Monakov <[email protected]> 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.
_______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user
