ffmpeg avcodec_receive_packet 返回 -11 [英] ffmpeg avcodec_receive_packet return -11

查看:37
本文介绍了ffmpeg avcodec_receive_packet 返回 -11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 ffmpeg API 从一系列输入图像创建视频.

I tried to create a video from a sequence of input images with ffmpeg API.

首先我从输入文件中读取 AVFrame 然后传递给 avcodec_send_frame(),但是当我调用 avcodec_get_packet() 来获取编码的数据包时,它返回 -11 (输出在当前状态下不可用).

First I read the AVFrame from input file then pass to avcodec_send_frame(), but when I call avcodec_get_packet() to get the encoded packet, it returns -11 (output is not available in the current state).

我只是一个初学者,所以我不知道我的代码是否有问题.

I'm just a beginner so I don't know if anything wrong in my code.

这是我的源代码:

for (unsigned int i = 0; i < nb_input; ++i) {
        const char *item = input[i];
        ret = open_input_file(item);
        if(ret < 0) {
            goto end;
        }
        packet = av_packet_alloc();
        if(packet == NULL) {
            _log_e("Cannot allocate packet");
            goto end;
        }
        ret = av_read_frame(_ifmt_ctx, packet);
        if(ret < 0) {
            goto end;
        }
        av_packet_rescale_ts(packet,
                             _ifmt_ctx->streams[0]->time_base,
                             _decode_ctx->time_base);

        ret = avcodec_send_packet(_decode_ctx, packet);
        if (ret < 0) {           
            goto end;
        }

        frame = av_frame_alloc();
        if(frame == NULL) {
            ret = AVERROR(ENOMEM);
            _log_e_2("Failed to allocate frame variable for this file : %s ", item);
            goto end;
        }
        ret = avcodec_receive_frame(_decode_ctx, frame);
        if (ret == 0) {
            /*
             * DO FILTER PROCESSING HERE
             */
        } 

        for (int j = 0; j < 25; ++j) {
            ret = avcodec_send_frame(_encode_ctx, frame);
            if (ret < 0) {
                _log_e_2("Failed to send frame at pts = %d", pts);
                goto end;
            }
            AVPacket *out_packet;
            out_packet = av_packet_alloc();
            if(out_packet == NULL) {
                _log_e_2("Failed to allocate output packet at pts = %d" , pts);
                goto end;
            }
            ret = avcodec_receive_packet(_encode_ctx, out_packet);
            if(ret < 0) {
                _log_e_2("Failed to receive encoded packet at pts = %d" , pts);
                if (ret == AVERROR(EAGAIN)) {
                    _log_e(" output is not available in the current state - user must try to send input");
                }
                else if (ret == AVERROR_EOF) {
                    _log_e(" the encoder has been fully flushed, and there will be no more output packets");
                }
                else if (ret == AVERROR(EINVAL)) {
                    _log_e(" codec is not opened");
                }
                av_packet_unref(out_packet);
                goto end;
            }
            _log_v_2("Write encoded packet at pts = %d to output file", pts);
            ret = av_interleaved_write_frame(_ofmt_ctx, out_packet);
            if (ret < 0) {
                _log_e_2("Failed to write encoded packet at pts = %d to output file", pts);
                goto end;
            }
            av_packet_unref(out_packet);
            pts++;
        }

推荐答案

编码器在输出第一个编码帧之前需要几帧输入.您必须忽略 EAGAIN 并只提供下一个输入帧.

The encoder needs several frames of input before it outputs the first encoded frame. You have to ignore EAGAIN and just feed the next input frame.

这篇关于ffmpeg avcodec_receive_packet 返回 -11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆