Showing the changes to libavfilter (1 of 3 files). Show all
Unified · Split
| @@ -75,6 +75,7 @@ typedef struct MCDeintContext { · 74 unmodified lines | |||
| 75 | int parity; ///< MCDeintParity | 75 | int parity; ///< MCDeintParity |
| 76 | int qp; | 76 | int qp; |
| 77 | AVPacket *pkt; | 77 | AVPacket *pkt; |
| 78 | AVFrame *frame_dec; | ||
| 78 | AVCodecContext *enc_ctx; | 79 | AVCodecContext *enc_ctx; |
| 79 | } MCDeintContext; | 80 | } MCDeintContext; |
| 80 | 81 | ||
| @@ -116,6 +117,9 @@ static int config_props(AVFilterLink *inlink) · 35 unmodified lines | |||
| 116 | mcdeint->pkt = av_packet_alloc(); | 117 | mcdeint->pkt = av_packet_alloc(); |
| 117 | if (!mcdeint->pkt) | 118 | if (!mcdeint->pkt) |
| 118 | return AVERROR(ENOMEM); | 119 | return AVERROR(ENOMEM); |
| 120 | mcdeint->frame_dec = av_frame_alloc(); | ||
| 121 | if (!mcdeint->frame_dec) | ||
| 122 | return AVERROR(ENOMEM); | ||
| 119 | mcdeint->enc_ctx = avcodec_alloc_context3(enc); | 123 | mcdeint->enc_ctx = avcodec_alloc_context3(enc); |
| 120 | if (!mcdeint->enc_ctx) | 124 | if (!mcdeint->enc_ctx) |
| 121 | return AVERROR(ENOMEM); | 125 | return AVERROR(ENOMEM); |
| @@ -126,7 +130,7 @@ static int config_props(AVFilterLink *inlink) · 4 unmodified lines | |||
| 126 | enc_ctx->gop_size = INT_MAX; | 130 | enc_ctx->gop_size = INT_MAX; |
| 127 | enc_ctx->max_b_frames = 0; | 131 | enc_ctx->max_b_frames = 0; |
| 128 | enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P; | 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 | enc_ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; | 134 | enc_ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; |
| 131 | enc_ctx->global_quality = 1; | 135 | enc_ctx->global_quality = 1; |
| 132 | enc_ctx->me_cmp = enc_ctx->me_sub_cmp = FF_CMP_SAD; | 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 | av_packet_free(&mcdeint->pkt); | 165 | av_packet_free(&mcdeint->pkt); |
| 162 | avcodec_free_context(&mcdeint->enc_ctx); | 166 | avcodec_free_context(&mcdeint->enc_ctx); |
| 167 | av_frame_free(&mcdeint->frame_dec); | ||
| 163 | } | 168 | } |
| 164 | 169 | ||
| 165 | static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) | 170 | static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) |
| 166 | { | 171 | { |
| 167 | MCDeintContext *mcdeint = inlink->dst->priv; | 172 | MCDeintContext *mcdeint = inlink->dst->priv; |
| 168 | AVFilterLink *outlink = inlink->dst->outputs[0]; | 173 | AVFilterLink *outlink = inlink->dst->outputs[0]; |
| 169 | AVFrame *outpic, *frame_dec; | 174 | AVFrame *outpic, *frame_dec = mcdeint->frame_dec; |
| 170 | AVPacket *pkt = mcdeint->pkt; | 175 | AVPacket *pkt = mcdeint->pkt; |
| 171 | int x, y, i, ret, got_frame = 0; | 176 | int x, y, i, ret; |
| 172 | 177 | ||
| 173 | outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h); | 178 | outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 174 | if (!outpic) { | 179 | if (!outpic) { |
| @@ -178,11 +183,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 3 unmodified lines | |||
| 178 | av_frame_copy_props(outpic, inpic); | 183 | av_frame_copy_props(outpic, inpic); |
| 179 | inpic->quality = mcdeint->qp * FF_QP2LAMBDA; | 184 | inpic->quality = mcdeint->qp * FF_QP2LAMBDA; |
| 180 | 185 | ||
| 181 | ret = avcodec_encode_video2(mcdeint->enc_ctx, pkt, inpic, &got_frame); | 186 | ret = avcodec_send_frame(mcdeint->enc_ctx, inpic); |
| 182 | if (ret < 0) | 187 | if (ret < 0) { |
| 188 | av_log(mcdeint->enc_ctx, AV_LOG_ERROR, "Error sending a frame for encoding\n"); | ||
| 183 | goto end; | 189 | goto end; |
| 184 | 190 | } | |
| 185 | frame_dec = mcdeint->enc_ctx->coded_frame; | 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 | for (i = 0; i < 3; i++) { | 203 | for (i = 0; i < 3; i++) { |
| 188 | int is_chroma = !!i; | 204 | int is_chroma = !!i; |