[Libav-user] converting pcm sample rate

Anton Adamansky adamansky at post.nsu.ru
Wed Nov 2 11:48:16 CET 2011


Hello!

I'm converting sample rate for raw pcm buffer:

input:    2ch, in_srate: 22050  sample: 16bits
output:  2ch, out_srate: 44100  sample: 16bits

So I'm using  swr_convert() function:

int out_samples =
                     swr_convert(swr_ctx, buff_in, resampled_size / 
(out_channels * 2),
                                           buff_out, input_pcm_len / 
(input_pcm_channels * 2));

I've got as result samples buffer with rate of 44100 and duration: 
(out_samples * 2 / out_srate) as half of original samples duration.

How can i convert this pcm buffer with preserved samples duration, so:
(out_samples * 2 / out_srate) === (in_samples * 2 / in_srate) ?

What I'm missing?

Anton



More information about the Libav-user mailing list