質問

I am trying to decode audio samples from various file formats using ffmpeg. Therefore I have started some experimenting based on the code in this discussion: How to decode audio via FFmpeg in Android . I use the latest FFMPEG release (1.0) and compile it using 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 is compiled using enable-decoder=mp1/mp2/mp3/ogg/vorbis/wav/aac/theora and without any external libraries (e.g. libmp3lame, libtheora, etc.)

Opening of mp3 and wav files works without problems producing the following output for instance for mp3:

audio format: mp3

audio bitrate: 256121

stream: 0 (total: 1)

audio codec: mp3

But when I try to open an ogg file I get this:

Error find stream information: -1 (Streams: 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,

役に立ちましたか?

解決

The problem was a missing demuxer.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top