2014-01-16 58 views
0

我試圖轉換AAC音頻流進行播放。我發現我需要從AV_SAMPLE_FMT_FLTP轉換爲AV_SAMPLE_FMT_S16,但是當我這樣做時,音頻以大約一半的速度播放。FFmpeg從AAC轉換後緩慢播放音頻

swr = swr_alloc(); 
assert(av_opt_set_int(swr, "in_channel_layout", audioContext->channel_layout, 0) == 0); 
assert(av_opt_set_int(swr, "out_channel_layout", audioContext->channel_layout, 0) == 0); 
assert(av_opt_set_int(swr, "in_sample_rate", audioContext->sample_rate, 0) == 0); 
assert(av_opt_set_int(swr, "out_sample_rate", 44100, 0) == 0); 
assert(av_opt_set_int(swr, "in_sample_fmt", audioContext->sample_fmt, 0) == 0); 
assert(av_opt_set_int(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0) == 0); 
swr_init(swr); 

有我的代碼進行轉換。輸入採樣率是44100,音頻是立體聲。

我調用代碼

swr_convert(swr, &output, aDecodedFrame->nb_samples, (const uint8_t**)aDecodedFrame->extended_data, aDecodedFrame->nb_samples) >= 0) 

回答

0

你沒有表現出實際的音頻編碼代碼,所以我推測有一個機會,你可能無法妥善處理重採樣。請注意,您從重新採樣操作中讀取的數據減少了兩倍(即,如果傳遞80個字節,則將從重新採樣器讀取40個數據)。

您可以查看我的視頻編寫代碼,並去掉音頻編碼部分。它在這裏:http://sourceforge.net/p/karlyriceditor/code/HEAD/tree/src/ffmpegvideoencoder.cpp