【问题标题】:ffmpeg Resource temporarily unavailableffmpeg 资源暂时不可用
【发布时间】:2018-03-11 21:00:35
【问题描述】:

我正在尝试使用 ffmpeg 库和 Opus 编解码器对音频帧进行编码 但我遇到了这个错误:

Resource temporarily unavailable

我的源代码:

void encode_audio(uint8_t *frame , int frame_size , void (*onPacket)(uint8_t *packet , int packet_size)){
if(audio_encoder_codec_context != NULL){
    memset(audio_encoder_frame_buffer , 0 , (size_t) audio_encoder_frame_size);
    swr_convert(
            s16_to_flt_resampler,
            &audio_encoder_frame_buffer,
            audio_encoder_frame_size,
            (const uint8_t **) &frame,
            frame_size
    );
    int result = avcodec_send_frame(audio_encoder_codec_context , audio_encoder_frame);
    while(result >= 0){
        result = avcodec_receive_packet(audio_encoder_codec_context , audio_encoder_packet);
        char *a = malloc(1024);
        av_strerror(result , a , 1024);
        printf("%s\n",a);
        if (result == AVERROR(EAGAIN) || result == AVERROR_EOF || result < 0){
            break;
        }
        onPacket(audio_encoder_packet->data , audio_encoder_packet->size);
        av_packet_unref(audio_encoder_packet);
    }
}
}

【问题讨论】:

  • 您找到解决方法了吗?我面临一个类似的问题,将帧编码为已从 Opus 解码的 AAC。
  • 我用的是Ffmpeg 3.1.2,我无法解决这个问题,你可以使用ffmpeg 4.0,可能会解决这个问题
  • 同样的错误,你是怎么解决的?

标签: c ffmpeg libav opus


【解决方案1】:

来自AVERROR(EAGAIN)

AVERROR(EAGAIN) 返回时,您应该发送更多帧。

文档为avcodec_receive_packet 声明了这一点

avcodec.h:

/**
 * Read encoded data from the encoder.
 *
 * @param avctx codec context
 * @param avpkt This will be set to a reference-counted packet allocated by the
 *              encoder. Note that the function will always call
 *              av_packet_unref(avpkt) before doing anything else.
 * @return 0 on success, otherwise negative error code:
 *      AVERROR(EAGAIN):   output is not available in the current state - user
 *                         must try to send input
 *      AVERROR_EOF:       the encoder has been fully flushed, and there will be
 *                         no more output packets
 *      AVERROR(EINVAL):   codec not opened, or it is a decoder
 *      other errors: legitimate encoding errors
 */
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);

根据数据,FFmpeg 可能需要额外的输入/数据才能产生输出。

更多来自文档:

AVERROR(EAGAIN): output is not available in the current state - user must try to send input.

继续为其提供数据,直到您获得返回码 0(成功)。

【讨论】:

    猜你喜欢
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2018-08-04
    • 2021-05-07
    • 2018-02-24
    • 2012-04-25
    • 1970-01-01
    相关资源
    最近更新 更多