简体   繁体   English

ffmpeg 资源暂时不可用

[英]ffmpeg Resource temporarily unavailable

I'm trying to encode an audio frame using ffmpeg library and Opus codec but i faced with this error :我正在尝试使用 ffmpeg 库和 Opus 编解码器对音频帧进行编码,但我遇到了这个错误:

Resource temporarily unavailable

My source code :我的源代码:

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);
    }
}
}

This is coming from AVERROR(EAGAIN) .这是来自AVERROR(EAGAIN)

You should send more frames when AVERROR(EAGAIN) is returned.当返回AVERROR(EAGAIN)时,您应该发送更多帧。

Docs state this for avcodec_receive_packet文档为avcodec_receive_packet说明了这avcodec_receive_packet

avcodec.h: 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);

Depending on the data, FFmpeg can require additional input/data before output can be produced.根据数据,FFmpeg 可能需要额外的输入/数据才能产生输出。

More from the docs:更多来自文档:

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

Keep giving it data until you get a return code of 0 (success).继续为其提供数据,直到获得返回码 0(成功)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM