2

我正在尝试使用 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)

When I manually set audioStreamIndex=0 and comment out the return statement:

Error find stream information: -1 (Streams: 1)

audio format: mp3

audio bitrate: 0

stream: 0 (total: 1)

audio codec: mp3

For m4a (AAC) I get this:

audio format: mp3

audio bitrate: 288000

stream: 0 (total: 1)

audio codec: mp1

but later it fails in avcodec_decode_audio3.

I also tried to manually force a format without success:

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

Is there something wrong with the loading code which makes it only work with mp3 and wav and fails for other formats?

Regards,

4

1 回答 1

2

The problem was a missing demuxer.

于 2012-10-29T10:26:19.493 回答