static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,

                      int *got_packet)

{

    X264Context *x4 = ctx->priv_data;

    x264_nal_t *nal;

    int nnal, i, ret;

    x264_picture_t pic_out = {0};

    int pict_type;



    x264_picture_init( &x4->pic );

    x4->pic.img.i_csp   = x4->params.i_csp;

    if (x264_bit_depth > 8)

        x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;

    x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);



    if (frame) {

        for (i = 0; i < x4->pic.img.i_plane; i++) {

            x4->pic.img.plane[i]    = frame->data[i];

            x4->pic.img.i_stride[i] = frame->linesize[i];

        }



        x4->pic.i_pts  = frame->pts;



        switch (frame->pict_type) {

        case AV_PICTURE_TYPE_I:

            x4->pic.i_type = x4->forced_idr > 0 ? X264_TYPE_IDR

                                                : X264_TYPE_KEYFRAME;

            break;

        case AV_PICTURE_TYPE_P:

            x4->pic.i_type = X264_TYPE_P;

            break;

        case AV_PICTURE_TYPE_B:

            x4->pic.i_type = X264_TYPE_B;

            break;

        default:

            x4->pic.i_type = X264_TYPE_AUTO;

            break;

        }

        reconfig_encoder(ctx, frame);



        if (x4->a53_cc) {

            void *sei_data;

            size_t sei_size;



            ret = ff_alloc_a53_sei(frame, 0, &sei_data, &sei_size);

            if (ret < 0) {

                av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");

            } else if (sei_data) {

                x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0]));

                if (x4->pic.extra_sei.payloads == NULL) {

                    av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");

                    av_free(sei_data);

                } else {

                    x4->pic.extra_sei.sei_free = av_free;



                    x4->pic.extra_sei.payloads[0].payload_size = sei_size;

                    x4->pic.extra_sei.payloads[0].payload = sei_data;

                    x4->pic.extra_sei.num_payloads = 1;

                    x4->pic.extra_sei.payloads[0].payload_type = 4;

                }

            }

        }

    }



    do {

        if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)

            return AVERROR_EXTERNAL;



        ret = encode_nals(ctx, pkt, nal, nnal);

        if (ret < 0)

            return ret;

    } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));



    pkt->pts = pic_out.i_pts;

    pkt->dts = pic_out.i_dts;





    switch (pic_out.i_type) {

    case X264_TYPE_IDR:

    case X264_TYPE_I:

        pict_type = AV_PICTURE_TYPE_I;

        break;

    case X264_TYPE_P:

        pict_type = AV_PICTURE_TYPE_P;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        pict_type = AV_PICTURE_TYPE_B;

        break;

    default:

        pict_type = AV_PICTURE_TYPE_NONE;

    }

#if FF_API_CODED_FRAME

FF_DISABLE_DEPRECATION_WARNINGS

    ctx->coded_frame->pict_type = pict_type;

FF_ENABLE_DEPRECATION_WARNINGS

#endif



    pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;

    if (ret) {

        ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, pict_type);



#if FF_API_CODED_FRAME

FF_DISABLE_DEPRECATION_WARNINGS

        ctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

    }



    *got_packet = ret;

    return 0;

}

static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,

                      int *got_packet)

{

    X264Context *x4 = ctx->priv_data;

    x264_nal_t *nal;

    int nnal, i, ret;

    x264_picture_t pic_out = {0};

    int pict_type;



    x264_picture_init( &x4->pic );

    x4->pic.img.i_csp   = x4->params.i_csp;

    if (x264_bit_depth > 8)

        x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;

    x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);



    if (frame) {

        for (i = 0; i < x4->pic.img.i_plane; i++) {

            x4->pic.img.plane[i]    = frame->data[i];

            x4->pic.img.i_stride[i] = frame->linesize[i];

        }



        x4->pic.i_pts  = frame->pts;



        switch (frame->pict_type) {

        case AV_PICTURE_TYPE_I:

            x4->pic.i_type = x4->forced_idr > 0 ? X264_TYPE_IDR

                                                : X264_TYPE_KEYFRAME;

            break;

        case AV_PICTURE_TYPE_P:

            x4->pic.i_type = X264_TYPE_P;

            break;

        case AV_PICTURE_TYPE_B:

            x4->pic.i_type = X264_TYPE_B;

            break;

        default:

            x4->pic.i_type = X264_TYPE_AUTO;

            break;

        }

        reconfig_encoder(ctx, frame);



        if (x4->a53_cc) {

            void *sei_data;

            size_t sei_size;



            ret = ff_alloc_a53_sei(frame, 0, &sei_data, &sei_size);

            if (ret < 0) {

                av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");

            } else if (sei_data) {

                x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0]));

                if (x4->pic.extra_sei.payloads == NULL) {

                    av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");

                    av_free(sei_data);

                } else {

                    x4->pic.extra_sei.sei_free = av_free;



                    x4->pic.extra_sei.payloads[0].payload_size = sei_size;

                    x4->pic.extra_sei.payloads[0].payload = sei_data;

                    x4->pic.extra_sei.num_payloads = 1;

                    x4->pic.extra_sei.payloads[0].payload_type = 4;

                }

            }

        }

    }



    do {

        if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)

            return AVERROR_EXTERNAL;



        ret = encode_nals(ctx, pkt, nal, nnal);

        if (ret < 0)

            return ret;

    } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));



    pkt->pts = pic_out.i_pts;

    pkt->dts = pic_out.i_dts;





    switch (pic_out.i_type) {

    case X264_TYPE_IDR:

    case X264_TYPE_I:

        pict_type = AV_PICTURE_TYPE_I;

        break;

    case X264_TYPE_P:

        pict_type = AV_PICTURE_TYPE_P;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        pict_type = AV_PICTURE_TYPE_B;

        break;

    default:

        pict_type = AV_PICTURE_TYPE_NONE;

    }

#if FF_API_CODED_FRAME

FF_DISABLE_DEPRECATION_WARNINGS

    ctx->coded_frame->pict_type = pict_type;

FF_ENABLE_DEPRECATION_WARNINGS

#endif



    pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;

    if (ret) {

        ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, pict_type);



#if FF_API_CODED_FRAME

FF_DISABLE_DEPRECATION_WARNINGS

        ctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

    }



    *got_packet = ret;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1, const AVFrame *VAR_2,

                      int *VAR_3)

{

    X264Context *x4 = VAR_0->priv_data;

    x264_nal_t *nal;

    int VAR_4, VAR_5, VAR_6;

    x264_picture_t pic_out = {0};

    int VAR_7;



    x264_picture_init( &x4->pic );

    x4->pic.img.i_csp   = x4->params.i_csp;

    if (x264_bit_depth > 8)

        x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;

    x4->pic.img.i_plane = avfmt2_num_planes(VAR_0->pix_fmt);



    if (VAR_2) {

        for (VAR_5 = 0; VAR_5 < x4->pic.img.i_plane; VAR_5++) {

            x4->pic.img.plane[VAR_5]    = VAR_2->data[VAR_5];

            x4->pic.img.i_stride[VAR_5] = VAR_2->linesize[VAR_5];

        }



        x4->pic.i_pts  = VAR_2->pts;



        switch (VAR_2->VAR_7) {

        case AV_PICTURE_TYPE_I:

            x4->pic.i_type = x4->forced_idr > 0 ? X264_TYPE_IDR

                                                : X264_TYPE_KEYFRAME;

            break;

        case AV_PICTURE_TYPE_P:

            x4->pic.i_type = X264_TYPE_P;

            break;

        case AV_PICTURE_TYPE_B:

            x4->pic.i_type = X264_TYPE_B;

            break;

        default:

            x4->pic.i_type = X264_TYPE_AUTO;

            break;

        }

        reconfig_encoder(VAR_0, VAR_2);



        if (x4->a53_cc) {

            void *VAR_8;

            size_t sei_size;



            VAR_6 = ff_alloc_a53_sei(VAR_2, 0, &VAR_8, &sei_size);

            if (VAR_6 < 0) {

                av_log(VAR_0, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");

            } else if (VAR_8) {

                x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0]));

                if (x4->pic.extra_sei.payloads == NULL) {

                    av_log(VAR_0, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n");

                    av_free(VAR_8);

                } else {

                    x4->pic.extra_sei.sei_free = av_free;



                    x4->pic.extra_sei.payloads[0].payload_size = sei_size;

                    x4->pic.extra_sei.payloads[0].payload = VAR_8;

                    x4->pic.extra_sei.num_payloads = 1;

                    x4->pic.extra_sei.payloads[0].payload_type = 4;

                }

            }

        }

    }



    do {

        if (x264_encoder_encode(x4->enc, &nal, &VAR_4, VAR_2? &x4->pic: NULL, &pic_out) < 0)

            return AVERROR_EXTERNAL;



        VAR_6 = encode_nals(VAR_0, VAR_1, nal, VAR_4);

        if (VAR_6 < 0)

            return VAR_6;

    } while (!VAR_6 && !VAR_2 && x264_encoder_delayed_frames(x4->enc));



    VAR_1->pts = pic_out.i_pts;

    VAR_1->dts = pic_out.i_dts;





    switch (pic_out.i_type) {

    case X264_TYPE_IDR:

    case X264_TYPE_I:

        VAR_7 = AV_PICTURE_TYPE_I;

        break;

    case X264_TYPE_P:

        VAR_7 = AV_PICTURE_TYPE_P;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        VAR_7 = AV_PICTURE_TYPE_B;

        break;

    default:

        VAR_7 = AV_PICTURE_TYPE_NONE;

    }

#if FF_API_CODED_FRAME

FF_DISABLE_DEPRECATION_WARNINGS

    VAR_0->coded_frame->VAR_7 = VAR_7;

FF_ENABLE_DEPRECATION_WARNINGS

#endif



    VAR_1->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;

    if (VAR_6) {

        ff_side_data_set_encoder_stats(VAR_1, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, VAR_7);



#if FF_API_CODED_FRAME

FF_DISABLE_DEPRECATION_WARNINGS

        VAR_0->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

    }



    *VAR_3 = VAR_6;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1, const AVFrame *VAR_2,
int *VAR_3)
{ X264Context *x4 = VAR_0->priv_data; x264_nal_t *nal; int VAR_4, VAR_5, VAR_6; x264_picture_t pic_out = {0}; int VAR_7; x264_picture_init( &x4->pic ); x4->pic.img.i_csp   = x4->params.i_csp; if (x264_bit_depth > 8)
x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH; x4->pic.img.i_plane = avfmt2_num_planes(VAR_0->pix_fmt); if (VAR_2) { for (VAR_5 = 0; VAR_5 < x4->pic.img.i_plane; VAR_5++) { x4->pic.img.plane[VAR_5]    = VAR_2->data[VAR_5]; x4->pic.img.i_stride[VAR_5] = VAR_2->linesize[VAR_5]; } x4->pic.i_pts  = VAR_2->pts; switch (VAR_2->VAR_7) { case AV_PICTURE_TYPE_I:
x4->pic.i_type = x4->forced_idr > 0 ? X264_TYPE_IDR
: X264_TYPE_KEYFRAME; break; case AV_PICTURE_TYPE_P:
x4->pic.i_type = X264_TYPE_P; break; case AV_PICTURE_TYPE_B:
x4->pic.i_type = X264_TYPE_B; break; default:
x4->pic.i_type = X264_TYPE_AUTO; break; } reconfig_encoder(VAR_0, VAR_2); if (x4->a53_cc) { void *VAR_8; size_t sei_size; VAR_6 = ff_alloc_a53_sei(VAR_2, 0, &VAR_8, &sei_size); if (VAR_6 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n"); } else if (VAR_8) { x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0])); if (x4->pic.extra_sei.payloads == NULL) { av_log(VAR_0, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n"); av_free(VAR_8); } else { x4->pic.extra_sei.sei_free = av_free; x4->pic.extra_sei.payloads[0].payload_size = sei_size; x4->pic.extra_sei.payloads[0].payload = VAR_8; x4->pic.extra_sei.num_payloads = 1; x4->pic.extra_sei.payloads[0].payload_type = 4; } } } } do { if (x264_encoder_encode(x4->enc, &nal, &VAR_4, VAR_2? &x4->pic: NULL, &pic_out) < 0)
return AVERROR_EXTERNAL; VAR_6 = encode_nals(VAR_0, VAR_1, nal, VAR_4); if (VAR_6 < 0)
return VAR_6; } while (!VAR_6 && !VAR_2 && x264_encoder_delayed_frames(x4->enc)); VAR_1->pts = pic_out.i_pts; VAR_1->dts = pic_out.i_dts; switch (pic_out.i_type) { case X264_TYPE_IDR:
case X264_TYPE_I:
VAR_7 = AV_PICTURE_TYPE_I; break; case X264_TYPE_P:
VAR_7 = AV_PICTURE_TYPE_P; break; case X264_TYPE_B:
case X264_TYPE_BREF:
VAR_7 = AV_PICTURE_TYPE_B; break; default:
VAR_7 = AV_PICTURE_TYPE_NONE; } #if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
VAR_0->coded_frame->VAR_7 = VAR_7; FF_ENABLE_DEPRECATION_WARNINGS
#endif
VAR_1->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe; if (VAR_6) { ff_side_data_set_encoder_stats(VAR_1, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, VAR_7); #if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
VAR_0->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; FF_ENABLE_DEPRECATION_WARNINGS
#endif
} *VAR_3 = VAR_6; return 0; }