2012-10-19 32 views
2

我試圖使用ffmpeg解碼來自各種文件格式的音頻樣本。因此,我已經根據此討論中的代碼開始了一些試驗:How to decode audio via FFmpeg in Android。我使用最新FFMPEG釋放(1.0),並使用https://github.com/halfninja/android-ffmpeg-x264使用libav/ffmpeg正確打開音頻文件

AVFormatContext * pFormatCtx; 

avcodec_register_all(); 
av_register_all(); 

int lError; 
if ((lError = avformat_open_input(&pFormatCtx, filename, NULL, 0)) 
     != 0) { 
    LOGE("Error open source file: %d", lError); 
    return; 
} 
if ((lError = avformat_find_stream_info(pFormatCtx, 0)) < 0) { 
    LOGE("Error find stream information: %d (Streams: %d)", lError, pFormatCtx->nb_streams); 
    return; 
} 
LOGE("audio format: %s", pFormatCtx->iformat->name); 
LOGE("audio bitrate: %d", pFormatCtx->bit_rate); 
audioStreamIndex = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, 
     -1, -1, &codec, 0); 

//if (audioStreamIndex < 0 || audioStreamIndex >= pFormatCtx->nb_streams) 
// audioStreamIndex = 0; 

LOGE("Stream: %d (total: %d)", audioStreamIndex, pFormatCtx->nb_streams); 
LOGE("audio codec: %s", codec->name); 

FFMPEG使用使解碼器= MP1/MP2/MP3/OGG/Vorbis格式/ WAV/AAC/Theora的編譯和沒有任何外部庫編譯它(如了libmp3lame,libtheora等)的MP3和WAV文件

開幕作品,未經產生例如下面的輸出MP3的問題:

音頻格式:MP3

b音頻itrate:256121

流:0(共1)

音頻編解碼器:MP3

但是當我嘗試打開OGG文件,我得到這個:

錯誤找到流信息:-1(Streams:1)

當我手動設置audioStreamIndex=0並註釋掉return語句:

錯誤發現流信息:-1(流:1)

音頻格式:MP3

音頻比特率:0

流:0(共1)

音頻編解碼器:MP3

對於M4A(AAC )我得到這樣的:

音頻格式:MP3

音頻比特率:288000

流:0(共1)

音頻編解碼器:MP1

但後來它在avcodec_decode_audio3失敗。

我也試過手動強制沒有成功的格式:

AVInputFormat *pForceFormat= av_find_input_format("ogg"); 
if ((lError = avformat_open_input(&pFormatCtx, filename, pForceFormat, 0)) 
// continue 

是不是有什麼毛病加載代碼,這使得它只能與MP3和WAV工作,併爲失敗其他格式?

問候,

回答

1

問題是一個失蹤的分路器。

相關問題