音频重采样swr_convert尾部丢帧的问题处理

在使用ffmpeg解码音频并经swr_convert重采样后通过sdl播放时,发现最后几秒音频丢失。问题源于重采样过程中缓冲区的数据未被完全取出。解决方案有两种:一是通过将in和in_count设为0来获取缓冲区数据,但这不易判断重采样结尾;二是利用swr_get_out_samples接口确定输出帧样本数,确保重采样后的数据完整。通过调整重采样参数和sdl的音频规格,成功避免了丢帧问题。
摘要由CSDN通过智能技术生成

音频重采样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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值