h4tr3d / avcpp

C++ wrapper for FFmpeg
Other
429 stars 78 forks source link

Take into account the filter size when calculating the delay #122

Closed mmomtchev closed 7 months ago

mmomtchev commented 7 months ago

When calculating the number of samples that AudioResampler::pop will return, the filter size must be taken into account:

https://github.com/h4tr3d/avcpp/blob/c3311e6ac4944496a57281cc237ac79248683e92/src/audioresampler.cpp#L209

libswresample uses a filter and needs a number of bytes after the end of the sample to be able to resample - 16 in my case.

Otherwise, it risks returning partial frames.

The total value is available in SwrContext->filter_size, the number of samples needed is half that.

Ref: https://stackoverflow.com/questions/39587839/libswresample-swr-convert-not-producing-enough-samples

h4tr3d commented 7 months ago

Sounds like this field was added a far ago:

da9587952a8 (Michael Niedermayer 2012-04-26 01:35:22 +0200 127)     int filter_size;                                /**< length of each FIR filter in the resampling filterbank relative to the cutoff frequency */

approve! Thanks!