| @@ -75,6 +75,7 @@ typedef struct MCDeintContext { · 74 unmodified lines |
| 75 | 75 | int parity; ///< MCDeintParity |
| 76 | 76 | int qp; |
| 77 | 77 | AVPacket *pkt; |
| 78 | + AVFrame *frame_dec; |
| 78 | 79 | AVCodecContext *enc_ctx; |
| 79 | 80 | } MCDeintContext; |
| 80 | 81 | |
| @@ -116,6 +117,9 @@ static int config_props(AVFilterLink *inlink) · 35 unmodified lines |
| 116 | 117 | mcdeint->pkt = av_packet_alloc(); |
| 117 | 118 | if (!mcdeint->pkt) |
| 118 | 119 | return AVERROR(ENOMEM); |
| 120 | + mcdeint->frame_dec = av_frame_alloc(); |
| 121 | + if (!mcdeint->frame_dec) |
| 122 | + return AVERROR(ENOMEM); |
| 119 | 123 | mcdeint->enc_ctx = avcodec_alloc_context3(enc); |
| 120 | 124 | if (!mcdeint->enc_ctx) |
| 121 | 125 | return AVERROR(ENOMEM); |
| @@ -126,7 +130,7 @@ static int config_props(AVFilterLink *inlink) · 4 unmodified lines |
| 126 | 130 | enc_ctx->gop_size = INT_MAX; |
| 127 | 131 | enc_ctx->max_b_frames = 0; |
| 128 | 132 | enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P; |
| 129 | | − enc_ctx->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY; |
| 133 | + enc_ctx->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY | AV_CODEC_FLAG_RECON_FRAME; |
| 130 | 134 | enc_ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; |
| 131 | 135 | enc_ctx->global_quality = 1; |
| 132 | 136 | enc_ctx->me_cmp = enc_ctx->me_sub_cmp = FF_CMP_SAD; |
| @@ -160,15 +164,16 @@ static av_cold void uninit(AVFilterContext *ctx) · 27 unmodified lines |
| 160 | 164 | |
| 161 | 165 | av_packet_free(&mcdeint->pkt); |
| 162 | 166 | avcodec_free_context(&mcdeint->enc_ctx); |
| 167 | + av_frame_free(&mcdeint->frame_dec); |
| 163 | 168 | } |
| 164 | 169 | |
| 165 | 170 | static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) |
| 166 | 171 | { |
| 167 | 172 | MCDeintContext *mcdeint = inlink->dst->priv; |
| 168 | 173 | AVFilterLink *outlink = inlink->dst->outputs[0]; |
| 169 | | − AVFrame *outpic, *frame_dec; |
| 174 | + AVFrame *outpic, *frame_dec = mcdeint->frame_dec; |
| 170 | 175 | AVPacket *pkt = mcdeint->pkt; |
| 171 | | − int x, y, i, ret, got_frame = 0; |
| 176 | + int x, y, i, ret; |
| 172 | 177 | |
| 173 | 178 | outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 174 | 179 | if (!outpic) { |
| @@ -178,11 +183,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 3 unmodified lines |
| 178 | 183 | av_frame_copy_props(outpic, inpic); |
| 179 | 184 | inpic->quality = mcdeint->qp * FF_QP2LAMBDA; |
| 180 | 185 | |
| 181 | | − ret = avcodec_encode_video2(mcdeint->enc_ctx, pkt, inpic, &got_frame); |
| 182 | | − if (ret < 0) |
| 186 | + ret = avcodec_send_frame(mcdeint->enc_ctx, inpic); |
| 187 | + if (ret < 0) { |
| 188 | + av_log(mcdeint->enc_ctx, AV_LOG_ERROR, "Error sending a frame for encoding\n"); |
| 183 | 189 | goto end; |
| 184 | | − |
| 185 | | − frame_dec = mcdeint->enc_ctx->coded_frame; |
| 190 | + } |
| 191 | + ret = avcodec_receive_packet(mcdeint->enc_ctx, pkt); |
| 192 | + if (ret < 0) { |
| 193 | + av_log(mcdeint->enc_ctx, AV_LOG_ERROR, "Error receiving a packet from encoding\n"); |
| 194 | + goto end; |
| 195 | + } |
| 196 | + av_packet_unref(pkt); |
| 197 | + ret = avcodec_receive_frame(mcdeint->enc_ctx, frame_dec); |
| 198 | + if (ret < 0) { |
| 199 | + av_log(mcdeint->enc_ctx, AV_LOG_ERROR, "Error receiving a frame from encoding\n"); |
| 200 | + goto end; |
| 201 | + } |
| 186 | 202 | |
| 187 | 203 | for (i = 0; i < 3; i++) { |
| 188 | 204 | int is_chroma = !!i; |