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;



    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;

        x4->pic.i_type =

            frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :

            frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :

            frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :

                                            X264_TYPE_AUTO;

        if (x4->params.b_interlaced && x4->params.b_tff != frame->top_field_first) {

            x4->params.b_tff = frame->top_field_first;

            x264_encoder_reconfig(x4->enc, &x4->params);

        }

        if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ||

            x4->params.vui.i_sar_width  != ctx->sample_aspect_ratio.num) {

            x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;

            x4->params.vui.i_sar_width  = ctx->sample_aspect_ratio.num;

            x264_encoder_reconfig(x4->enc, &x4->params);

        }

    }



    do {

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

            return -1;



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

        if (ret < 0)

            return -1;

    } 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:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_I;

        break;

    case X264_TYPE_P:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_P;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_B;

        break;

    }



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

    if (ret)

        x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;



    *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;



    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;

        x4->pic.i_type =

            frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :

            frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :

            frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :

                                            X264_TYPE_AUTO;

        if (x4->params.b_interlaced && x4->params.b_tff != frame->top_field_first) {

            x4->params.b_tff = frame->top_field_first;

            x264_encoder_reconfig(x4->enc, &x4->params);

        }

        if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ||

            x4->params.vui.i_sar_width  != ctx->sample_aspect_ratio.num) {

            x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;

            x4->params.vui.i_sar_width  = ctx->sample_aspect_ratio.num;

            x264_encoder_reconfig(x4->enc, &x4->params);

        }

    }



    do {

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

            return -1;



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

        if (ret < 0)

            return -1;

    } 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:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_I;

        break;

    case X264_TYPE_P:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_P;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_B;

        break;

    }



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

    if (ret)

        x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;



    *got_packet = ret;

    return 0;

}

    x264_picture_t pic_out;
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;



    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;

        x4->pic.i_type =

            VAR_2->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :

            VAR_2->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :

            VAR_2->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :

                                            X264_TYPE_AUTO;

        if (x4->params.b_interlaced && x4->params.b_tff != VAR_2->top_field_first) {

            x4->params.b_tff = VAR_2->top_field_first;

            x264_encoder_reconfig(x4->enc, &x4->params);

        }

        if (x4->params.vui.i_sar_height != VAR_0->sample_aspect_ratio.den ||

            x4->params.vui.i_sar_width  != VAR_0->sample_aspect_ratio.num) {

            x4->params.vui.i_sar_height = VAR_0->sample_aspect_ratio.den;

            x4->params.vui.i_sar_width  = VAR_0->sample_aspect_ratio.num;

            x264_encoder_reconfig(x4->enc, &x4->params);

        }

    }



    do {

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

            return -1;



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

        if (VAR_6 < 0)

            return -1;

    } 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:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_I;

        break;

    case X264_TYPE_P:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_P;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        x4->out_pic.pict_type = AV_PICTURE_TYPE_B;

        break;

    }



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

    if (VAR_6)

        x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;



    *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; 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; x4->pic.i_type =
VAR_2->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :
VAR_2->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :
VAR_2->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :
X264_TYPE_AUTO; if (x4->params.b_interlaced && x4->params.b_tff != VAR_2->top_field_first) { x4->params.b_tff = VAR_2->top_field_first; x264_encoder_reconfig(x4->enc, &x4->params); } if (x4->params.vui.i_sar_height != VAR_0->sample_aspect_ratio.den ||
x4->params.vui.i_sar_width  != VAR_0->sample_aspect_ratio.num) { x4->params.vui.i_sar_height = VAR_0->sample_aspect_ratio.den; x4->params.vui.i_sar_width  = VAR_0->sample_aspect_ratio.num; x264_encoder_reconfig(x4->enc, &x4->params); } } do { if (x264_encoder_encode(x4->enc, &nal, &VAR_4, VAR_2? &x4->pic: NULL, &pic_out) < 0)
return -1; VAR_6 = encode_nals(VAR_0, VAR_1, nal, VAR_4); if (VAR_6 < 0)
return -1; } 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:
x4->out_pic.pict_type = AV_PICTURE_TYPE_I; break; case X264_TYPE_P:
x4->out_pic.pict_type = AV_PICTURE_TYPE_P; break; case X264_TYPE_B:
case X264_TYPE_BREF:
x4->out_pic.pict_type = AV_PICTURE_TYPE_B; break; } VAR_1->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe; if (VAR_6)
x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; *VAR_3 = VAR_6; return 0; }