音频重采样swr_convert尾部丢帧的问题处理
问题描述
ffmpeg解码音频并重采样后送入sdl播放,会出现最后几秒音频数据的丢失。
问题分析
将音频解码前、解码后、重采样后的音频数据分别dump到文件进行试听分析,得知问题出现在重采样环节。查看swr_convert的注释
/** Convert audio.
*
* in and in_count can be set to 0 to flush the last few samples out at the
* end.
*
* If more input is provided than output space, then the input will be buffered.
* You can avoid this buffering by using swr_get_out_samples() to retrieve an
* upper bound on the required number of output samples for the given number of
* input samples. Conversion will run directly without copying whenever possible.
*
* @param s allocated Swr context, with parameters set
* @param out output buffers, only the first one need be set in case of packed audio
* @param out_count amount of space available for output in samples per channel
* @param in input buffers, only the first