2014-10-22 82 views
0

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

回答

0

原來,噪音是不是在音頻流解碼的問題,但在攝像裝置的飼料音頻流應用程序的一個問題。

當連接到Android應用程序時,噪聲是無法聽到的,在測試Android應用程序時導致我們錯過它,並認爲這是iOS應用程序處理音頻的問題,而不是設備出現問題。

0

我不知道到底,但s16be是整數(16位),而kAudioFormatLinearPCM爲float(32位)。

如果我在你的鞋子,我只會使用s16be和kAudioFormatLinearPCM格式,這意味着修復AudioCodecCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)和其他人。
然後插入的ffmpeg之間PCM格式轉換步驟 - >的iOS數據流。

這個職位看起來非常有幫助的:iOS Core Audio : Converting between kAudioFormatFlagsCanonical and kAudioFormatFlagsAudioUnitCanonical