簡體   English   中英

ffmpeg 資源暫時不可用

[英]ffmpeg Resource temporarily unavailable

我正在嘗試使用 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);
    }
}
}

這是來自AVERROR(EAGAIN)

當返回AVERROR(EAGAIN)時,您應該發送更多幀。

文檔為avcodec_receive_packet說明了這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(成功)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM