我试图解码来自各种文件格式的音频样本使用ffmpeg。因此,我已经开始了一些基于以下讨论中的代码的实验:How to decode audio via FFmpeg in Android。我使用最新的FFMPEG发行版(1.0),并使用https://github.com/halfninja/android-ffmpeg-x264编译它
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是使用enable-decoder=mp1/mp2/mp3/ogg/vorbis/wav/aac/theora编译的,没有任何外部库(例如libmp3lame、libtheora等)。
打开mp3和wav文件没有出现问题,产生了以下输出,例如用于mp3:
音频格式: mp3 音频比特率: 256121 流:0(总数: 1) 音频编解码器: mp3
但是当我试图打开一个ogg文件时,我得到了这样的信息:
错误查找流信息:-1 (流: 1)
当我手动设置audioStreamIndex=0并注释掉返回语句时:
错误查找流信息:-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,而其他格式却失败?
致以敬意,
发布于 2012-10-29 10:26:19
问题是一个失踪的辩证员。
https://stackoverflow.com/questions/12968650
复制相似问题