[Libav-user] one issue about audio resampler
Hendrik Leppkes
h.leppkes at gmail.com
Fri Sep 18 08:51:47 CEST 2015
On Fri, Sep 18, 2015 at 5:33 AM, qw <applemax82 at 163.com> wrote:
> Hi,
>
> I'm using below functions to implement audio resampling, but encounter one
> issue.
>
> swr_alloc_set_opts(), swr_init(), swr_convert_frame(), swr_get_delay().
>
> Input frame is set to 8000hz mono AV_SAMPLE_FMT_FLT, while output frame is
> set to 44100Hz mono AV_SAMPLE_FMT_S16, and output frame's nb_samples is set
> to 80.
>
> swr_get_delay() is used to check whether resampler can ouput one frame with
> 80 audio samples or not. If the return value from swr_get_delay() is less
> than 80, swr_convert_frame() will called next time when input audio samples
> are feed into resampler. Or swr_convert_frame() is used to flush resampler
> to output one audio frame with 80 samples.
>
> But I encounter one issue. swr_get_delay().returns 88, which is larger than
> 80, and means audio resampler can be flushed to output one full audio frame
> with 80 samples. Resampler only outputs 41 samples, and next time output 0
> samples, but swr_get_delay() always return 88. Why? is this a bug in ffmpeg?
>
If you want to know the number of samples output on the next call, you
should use swr_get_out_samples. The delay does not necessarily
represent that, as it also holds data internally.
Note that none of these functions are guaranteed to be perfectly
accurate, and it would be much easier if you can just deal with
smaller frame sizes in your code (ie. by re-assembling them into the
frame size you need manually).
- Hendrik
More information about the Libav-user
mailing list