我结合使用FFMPEG与FFmpegAudioPlayer做现场直播。我遇到的问题是,虽然音频可以被解码和播放,但音频中存在不断出现的点击/尖锐噪声,当其他应用程序流式传输相同的源时,该噪声不存在。所以我想这个问题的出现是由于我如何处理FFmpeg的AV_CODEC_ID_PCM_S16BE
音频数据递给AudioQueue前:如何养活FFMPEG AV_CODEC_ID_PCM_S16BE音频数据AudioQueue
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagsCanonical;//kAudioFormatFlagIsBigEndian|kAudioFormatFlagIsAlignedHigh;
audioFormat.mSampleRate = pAudioCodecCtx->sample_rate;
audioFormat.mBitsPerChannel = 8*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
audioFormat.mChannelsPerFrame = pAudioCodecCtx->channels;
audioFormat.mBytesPerFrame = pAudioCodecCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
audioFormat.mBytesPerPacket= pAudioCodecCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
audioFormat.mFramesPerPacket = 1;
audioFormat.mReserved = 0;
pSwrCtx = swr_alloc_set_opts(pSwrCtx,
1,//pAudioCodecCtx->channel_layout,
AV_SAMPLE_FMT_S16,
pAudioCodecCtx->sample_rate,
1,//pAudioCodecCtx->channel_layout,
AV_SAMPLE_FMT_S16,
pAudioCodecCtx->sample_rate,
0,
0);
outCount = swr_convert(pSwrCtx,
(uint8_t **)(&pOut),
in_samples,
(const uint8_t **)pAVFrame1->extended_data,
in_samples);
还请注意,我已经尝试了许多不同的参数为swr_alloc_set_opts
,但无论哪种声音变得面目全非或者噪音依然存在。
Here的与咔哒声,如果它可以帮助音频的样本。