Ios ffmpeg函数avcodec_接收_帧始终返回EAGAIN错误

Ios ffmpeg函数avcodec_接收_帧始终返回EAGAIN错误,ios,ffmpeg,Ios,Ffmpeg,我正在使用ffmpeg对iOS上的aac音频文件进行解码,解码器为libfdk_aac,以下是音频文件: 下面是av\u dump\u格式的结果: Metadata: major_brand : iso6 minor_version : 0 compatible_brands: iso6dash Duration: N/A, bitrate: N/A Stream #0:0(und): Audio: aac (mp4a / 0x6134706D),

我正在使用ffmpeg对iOS上的aac音频文件进行解码,解码器为
libfdk_aac
,以下是音频文件: 下面是
av\u dump\u格式的结果:

Metadata:
    major_brand     : iso6
    minor_version   : 0
    compatible_brands: iso6dash
  Duration: N/A, bitrate: N/A
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 2 channels (default)
    Metadata:
      handler_name    : USP Sound Handler
av\u read\u frame
avcodec\u send\u packet
返回0,但
avcodec\u receive\u frame
始终返回
AVERROR(EAGAIN)

我尝试了ffmpeg命令行工具:
ffmpeg-I bbc.mp4 bbc.mp3
,它成功了,而且mp3文件可以在iOS上播放

这是我的密码:

av_register_all();
AVFormatContext *avFormatContext = avformat_alloc_context();
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"bbc" ofType:@"mp4"];

int ret;
ret = avformat_open_input(&avFormatContext, [filePath UTF8String], NULL, NULL);
if (0 != ret) {
    NSLog(@"avformat_open_input failed: %d", ret);
}

ret = avformat_find_stream_info(avFormatContext, NULL);
if (0 != ret) {
    NSLog(@"avformat_find_stream_info: %d", ret);
}

// the libfdk_aac decoder
AVCodec *codec = avcodec_find_decoder_by_name("libfdk_aac");
AVCodecContext *codecContext = avcodec_alloc_context3(codec);

ret = avcodec_open2(codecContext, codec, NULL);
if (0 != ret) {
    NSLog(@"avcodec_open2 faild: %d", ret);
}

AVFrame *frame = av_frame_alloc();
AVPacket packet;
av_init_packet(&packet);

// start read data and decode data
while (true) {
    ret = av_read_frame(avFormatContext, &packet);
    if (0 != ret) {
        break;
    }
    ret = avcodec_send_packet(codecContext, &packet);
    if (ret != 0) {
        NSLog(@"send package with error: %d", ret);
        continue;
        break;
    }
    while (true) {
        // the ret below is always return -35, means AVERROR(EAGAIN)
        ret = avcodec_receive_frame(codecContext, frame);
        if (ret == AVERROR(EAGAIN)) {
            NSLog(@"avcodec_receive_frame with EAGAIN error: %d", ret);
            break;
        } else if (ret == AVERROR_EOF) {
            NSLog(@"end of file");
            break;
        }
    }
    if (ret == AVERROR(EAGAIN)) {
        continue;
    }
}

我尝试将
bbc.mp4
文件替换为
bbc.mp3
文件,并将解码器更改为:
AVCodec*codec=AVCodec\u find\u解码器(AV\u codec\u ID\u mp3),所有的工作都很好。非常感谢。

当avcodec\u receive\u frame返回EAGAIN时,在再次调用avcodec\u receive\u frame之前,必须先调用avcodec\u send\u packet(或流末尾的空数据包),然后再调用avcodec\u receive\u

我尝试过,当接收
averor(EAGAIN)
时,执行
av\u read\u帧(avFormatContext,&packet)
avcodec\u发送\u数据包(编解码器上下文和数据包)
,在此之后
avcodec\u接收\u帧(codecContext,frame)总是得到
AVERROR(EAGAIN)
我想这个逻辑已经在代码中了。可能是我错了,哈,内在的while循环是一个无限的循环。当EAGAIN返回时,它调用continue,继续循环,得到EAGAIN。在循环被中断(或删除)之前,您将始终获得EAGAIN抱歉,我的错误,当我发布此代码时,我做了一些编辑,已经更新了我的代码,内部循环中的
continue
更改为
break
,结果相同。