static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){

    AVFrame *pic=NULL;

    int64_t pts;

    int i;

    const int encoding_delay= s->max_b_frames;

    int direct=1;



    if(pic_arg){

        pts= pic_arg->pts;

        pic_arg->display_picture_number= s->input_picture_number++;



        if(pts != AV_NOPTS_VALUE){

            if(s->user_specified_pts != AV_NOPTS_VALUE){

                int64_t time= pts;

                int64_t last= s->user_specified_pts;



                if(time <= last){

                    av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts);

                    return -1;

                }

            }

            s->user_specified_pts= pts;

        }else{

            if(s->user_specified_pts != AV_NOPTS_VALUE){

                s->user_specified_pts=

                pts= s->user_specified_pts + 1;

                av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts);

            }else{

                pts= pic_arg->display_picture_number;

            }

        }

    }



  if(pic_arg){

    if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;

    if(pic_arg->linesize[0] != s->linesize) direct=0;

    if(pic_arg->linesize[1] != s->uvlinesize) direct=0;

    if(pic_arg->linesize[2] != s->uvlinesize) direct=0;



//    av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);



    if(direct){

        i= ff_find_unused_picture(s, 1);



        pic= (AVFrame*)&s->picture[i];

        pic->reference= 3;



        for(i=0; i<4; i++){

            pic->data[i]= pic_arg->data[i];

            pic->linesize[i]= pic_arg->linesize[i];

        }

        ff_alloc_picture(s, (Picture*)pic, 1);

    }else{

        i= ff_find_unused_picture(s, 0);



        pic= (AVFrame*)&s->picture[i];

        pic->reference= 3;



        ff_alloc_picture(s, (Picture*)pic, 0);



        if(   pic->data[0] + INPLACE_OFFSET == pic_arg->data[0]

           && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1]

           && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){

       // empty

        }else{

            int h_chroma_shift, v_chroma_shift;

            avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);



            for(i=0; i<3; i++){

                int src_stride= pic_arg->linesize[i];

                int dst_stride= i ? s->uvlinesize : s->linesize;

                int h_shift= i ? h_chroma_shift : 0;

                int v_shift= i ? v_chroma_shift : 0;

                int w= s->width >>h_shift;

                int h= s->height>>v_shift;

                uint8_t *src= pic_arg->data[i];

                uint8_t *dst= pic->data[i];



                if(!s->avctx->rc_buffer_size)

                    dst +=INPLACE_OFFSET;



                if(src_stride==dst_stride)

                    memcpy(dst, src, src_stride*h);

                else{

                    while(h--){

                        memcpy(dst, src, w);

                        dst += dst_stride;

                        src += src_stride;

                    }

                }

            }

        }

    }

    copy_picture_attributes(s, pic, pic_arg);

    pic->pts= pts; //we set this here to avoid modifiying pic_arg

  }



    /* shift buffer entries */

    for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++)

        s->input_picture[i-1]= s->input_picture[i];



    s->input_picture[encoding_delay]= (Picture*)pic;



    return 0;

}

static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){

    AVFrame *pic=NULL;

    int64_t pts;

    int i;

    const int encoding_delay= s->max_b_frames;

    int direct=1;



    if(pic_arg){

        pts= pic_arg->pts;

        pic_arg->display_picture_number= s->input_picture_number++;



        if(pts != AV_NOPTS_VALUE){

            if(s->user_specified_pts != AV_NOPTS_VALUE){

                int64_t time= pts;

                int64_t last= s->user_specified_pts;



                if(time <= last){

                    av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts);

                    return -1;

                }

            }

            s->user_specified_pts= pts;

        }else{

            if(s->user_specified_pts != AV_NOPTS_VALUE){

                s->user_specified_pts=

                pts= s->user_specified_pts + 1;

                av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts);

            }else{

                pts= pic_arg->display_picture_number;

            }

        }

    }



  if(pic_arg){

    if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;

    if(pic_arg->linesize[0] != s->linesize) direct=0;

    if(pic_arg->linesize[1] != s->uvlinesize) direct=0;

    if(pic_arg->linesize[2] != s->uvlinesize) direct=0;







    if(direct){

        i= ff_find_unused_picture(s, 1);



        pic= (AVFrame*)&s->picture[i];

        pic->reference= 3;



        for(i=0; i<4; i++){

            pic->data[i]= pic_arg->data[i];

            pic->linesize[i]= pic_arg->linesize[i];

        }

        ff_alloc_picture(s, (Picture*)pic, 1);

    }else{

        i= ff_find_unused_picture(s, 0);



        pic= (AVFrame*)&s->picture[i];

        pic->reference= 3;



        ff_alloc_picture(s, (Picture*)pic, 0);



        if(   pic->data[0] + INPLACE_OFFSET == pic_arg->data[0]

           && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1]

           && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){

       

        }else{

            int h_chroma_shift, v_chroma_shift;

            avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);



            for(i=0; i<3; i++){

                int src_stride= pic_arg->linesize[i];

                int dst_stride= i ? s->uvlinesize : s->linesize;

                int h_shift= i ? h_chroma_shift : 0;

                int v_shift= i ? v_chroma_shift : 0;

                int w= s->width >>h_shift;

                int h= s->height>>v_shift;

                uint8_t *src= pic_arg->data[i];

                uint8_t *dst= pic->data[i];



                if(!s->avctx->rc_buffer_size)

                    dst +=INPLACE_OFFSET;



                if(src_stride==dst_stride)

                    memcpy(dst, src, src_stride*h);

                else{

                    while(h--){

                        memcpy(dst, src, w);

                        dst += dst_stride;

                        src += src_stride;

                    }

                }

            }

        }

    }

    copy_picture_attributes(s, pic, pic_arg);

    pic->pts= pts; 

  }



    

    for(i=1; i<MAX_PICTURE_COUNT ; i++)

        s->input_picture[i-1]= s->input_picture[i];



    s->input_picture[encoding_delay]= (Picture*)pic;



    return 0;

}

static int FUNC_0(MpegEncContext *VAR_0, AVFrame *VAR_1){

    AVFrame *pic=NULL;

    int64_t pts;

    int VAR_2;

    const int VAR_3= VAR_0->max_b_frames;

    int VAR_4=1;



    if(VAR_1){

        pts= VAR_1->pts;

        VAR_1->display_picture_number= VAR_0->input_picture_number++;



        if(pts != AV_NOPTS_VALUE){

            if(VAR_0->user_specified_pts != AV_NOPTS_VALUE){

                int64_t time= pts;

                int64_t last= VAR_0->user_specified_pts;



                if(time <= last){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, VAR_0->user_specified_pts);

                    return -1;

                }

            }

            VAR_0->user_specified_pts= pts;

        }else{

            if(VAR_0->user_specified_pts != AV_NOPTS_VALUE){

                VAR_0->user_specified_pts=

                pts= VAR_0->user_specified_pts + 1;

                av_log(VAR_0->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts);

            }else{

                pts= VAR_1->display_picture_number;

            }

        }

    }



  if(VAR_1){

    if(VAR_3 && !(VAR_0->flags&CODEC_FLAG_INPUT_PRESERVED)) VAR_4=0;

    if(VAR_1->linesize[0] != VAR_0->linesize) VAR_4=0;

    if(VAR_1->linesize[1] != VAR_0->uvlinesize) VAR_4=0;

    if(VAR_1->linesize[2] != VAR_0->uvlinesize) VAR_4=0;







    if(VAR_4){

        VAR_2= ff_find_unused_picture(VAR_0, 1);



        pic= (AVFrame*)&VAR_0->picture[VAR_2];

        pic->reference= 3;



        for(VAR_2=0; VAR_2<4; VAR_2++){

            pic->data[VAR_2]= VAR_1->data[VAR_2];

            pic->linesize[VAR_2]= VAR_1->linesize[VAR_2];

        }

        ff_alloc_picture(VAR_0, (Picture*)pic, 1);

    }else{

        VAR_2= ff_find_unused_picture(VAR_0, 0);



        pic= (AVFrame*)&VAR_0->picture[VAR_2];

        pic->reference= 3;



        ff_alloc_picture(VAR_0, (Picture*)pic, 0);



        if(   pic->data[0] + INPLACE_OFFSET == VAR_1->data[0]

           && pic->data[1] + INPLACE_OFFSET == VAR_1->data[1]

           && pic->data[2] + INPLACE_OFFSET == VAR_1->data[2]){

       

        }else{

            int VAR_5, VAR_6;

            avcodec_get_chroma_sub_sample(VAR_0->avctx->pix_fmt, &VAR_5, &VAR_6);



            for(VAR_2=0; VAR_2<3; VAR_2++){

                int VAR_7= VAR_1->linesize[VAR_2];

                int VAR_8= VAR_2 ? VAR_0->uvlinesize : VAR_0->linesize;

                int VAR_9= VAR_2 ? VAR_5 : 0;

                int VAR_10= VAR_2 ? VAR_6 : 0;

                int VAR_11= VAR_0->width >>VAR_9;

                int VAR_12= VAR_0->height>>VAR_10;

                uint8_t *src= VAR_1->data[VAR_2];

                uint8_t *dst= pic->data[VAR_2];



                if(!VAR_0->avctx->rc_buffer_size)

                    dst +=INPLACE_OFFSET;



                if(VAR_7==VAR_8)

                    memcpy(dst, src, VAR_7*VAR_12);

                else{

                    while(VAR_12--){

                        memcpy(dst, src, VAR_11);

                        dst += VAR_8;

                        src += VAR_7;

                    }

                }

            }

        }

    }

    copy_picture_attributes(VAR_0, pic, VAR_1);

    pic->pts= pts; 

  }



    

    for(VAR_2=1; VAR_2<MAX_PICTURE_COUNT ; VAR_2++)

        VAR_0->input_picture[VAR_2-1]= VAR_0->input_picture[VAR_2];



    VAR_0->input_picture[VAR_3]= (Picture*)pic;



    return 0;

}

static int FUNC_0(MpegEncContext *VAR_0, AVFrame *VAR_1){ AVFrame *pic=NULL; int64_t pts; int VAR_2; const int VAR_3= VAR_0->max_b_frames; int VAR_4=1; if(VAR_1){ pts= VAR_1->pts; VAR_1->display_picture_number= VAR_0->input_picture_number++; if(pts != AV_NOPTS_VALUE){ if(VAR_0->user_specified_pts != AV_NOPTS_VALUE){ int64_t time= pts; int64_t last= VAR_0->user_specified_pts; if(time <= last){ av_log(VAR_0->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, VAR_0->user_specified_pts); return -1; } } VAR_0->user_specified_pts= pts; }else{ if(VAR_0->user_specified_pts != AV_NOPTS_VALUE){ VAR_0->user_specified_pts=
pts= VAR_0->user_specified_pts + 1; av_log(VAR_0->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); }else{ pts= VAR_1->display_picture_number; } } } if(VAR_1){ if(VAR_3 && !(VAR_0->flags&CODEC_FLAG_INPUT_PRESERVED)) VAR_4=0; if(VAR_1->linesize[0] != VAR_0->linesize) VAR_4=0; if(VAR_1->linesize[1] != VAR_0->uvlinesize) VAR_4=0; if(VAR_1->linesize[2] != VAR_0->uvlinesize) VAR_4=0; if(VAR_4){ VAR_2= ff_find_unused_picture(VAR_0, 1); pic= (AVFrame*)&VAR_0->picture[VAR_2]; pic->reference= 3; for(VAR_2=0; VAR_2<4; VAR_2++){ pic->data[VAR_2]= VAR_1->data[VAR_2]; pic->linesize[VAR_2]= VAR_1->linesize[VAR_2]; } ff_alloc_picture(VAR_0, (Picture*)pic, 1); }else{ VAR_2= ff_find_unused_picture(VAR_0, 0); pic= (AVFrame*)&VAR_0->picture[VAR_2]; pic->reference= 3; ff_alloc_picture(VAR_0, (Picture*)pic, 0); if(   pic->data[0] + INPLACE_OFFSET == VAR_1->data[0]
&& pic->data[1] + INPLACE_OFFSET == VAR_1->data[1]
&& pic->data[2] + INPLACE_OFFSET == VAR_1->data[2]){ }else{ int VAR_5, VAR_6; avcodec_get_chroma_sub_sample(VAR_0->avctx->pix_fmt, &VAR_5, &VAR_6); for(VAR_2=0; VAR_2<3; VAR_2++){ int VAR_7= VAR_1->linesize[VAR_2]; int VAR_8= VAR_2 ? VAR_0->uvlinesize : VAR_0->linesize; int VAR_9= VAR_2 ? VAR_5 : 0; int VAR_10= VAR_2 ? VAR_6 : 0; int VAR_11= VAR_0->width >>VAR_9; int VAR_12= VAR_0->height>>VAR_10; uint8_t *src= VAR_1->data[VAR_2]; uint8_t *dst= pic->data[VAR_2]; if(!VAR_0->avctx->rc_buffer_size)
dst +=INPLACE_OFFSET; if(VAR_7==VAR_8)
memcpy(dst, src, VAR_7*VAR_12); else{ while(VAR_12--){ memcpy(dst, src, VAR_11); dst += VAR_8; src += VAR_7; } } } } } copy_picture_attributes(VAR_0, pic, VAR_1); pic->pts= pts; } for(VAR_2=1; VAR_2<MAX_PICTURE_COUNT ; VAR_2++) VAR_0->input_picture[VAR_2-1]= VAR_0->input_picture[VAR_2]; VAR_0->input_picture[VAR_3]= (Picture*)pic; return 0; }