我結合使用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的與咔噠聲,如果它可以幫助音頻的樣本。