static void do_video_out(AVFormatContext *s, 

                         AVOutputStream *ost, 

                         AVInputStream *ist,

                         AVPicture *picture1,

                         int *frame_size)

{

    int n1, n2, nb, i, ret, frame_number, dec_frame_rate;

    AVPicture *picture, *picture2, *pict;

    AVPicture picture_tmp1, picture_tmp2;

    UINT8 *video_buffer;

    UINT8 *buf = NULL, *buf1 = NULL;

    AVCodecContext *enc, *dec;



#define VIDEO_BUFFER_SIZE (1024*1024)



    enc = &ost->st->codec;

    dec = &ist->st->codec;



    frame_number = ist->frame_number;

    dec_frame_rate = ist->st->r_frame_rate;

    //    fprintf(stderr, "\n%d", dec_frame_rate);

    /* first drop frame if needed */

    n1 = ((INT64)frame_number * enc->frame_rate) / dec_frame_rate;

    n2 = (((INT64)frame_number + 1) * enc->frame_rate) / dec_frame_rate;

    nb = n2 - n1;

    if (nb <= 0) 

        return;



    video_buffer= av_malloc(VIDEO_BUFFER_SIZE);

    if(!video_buffer) return;



    /* deinterlace : must be done before any resize */

    if (do_deinterlace) {

        int size;



        /* create temporary picture */

        size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height);

        buf1 = av_malloc(size);

        if (!buf1)

            return;

        

        picture2 = &picture_tmp2;

        avpicture_fill(picture2, buf1, dec->pix_fmt, dec->width, dec->height);



        if (avpicture_deinterlace(picture2, picture1, 

                                  dec->pix_fmt, dec->width, dec->height) < 0) {

            /* if error, do not deinterlace */

            av_free(buf1);

            buf1 = NULL;

            picture2 = picture1;

        }

    } else {

        picture2 = picture1;

    }



    /* convert pixel format if needed */

    if (enc->pix_fmt != dec->pix_fmt) {

        int size;



        /* create temporary picture */

        size = avpicture_get_size(enc->pix_fmt, dec->width, dec->height);

        buf = av_malloc(size);

        if (!buf)

            return;

        pict = &picture_tmp1;

        avpicture_fill(pict, buf, enc->pix_fmt, dec->width, dec->height);

        

        if (img_convert(pict, enc->pix_fmt, 

                        picture2, dec->pix_fmt, 

                        dec->width, dec->height) < 0) {

            fprintf(stderr, "pixel format conversion not handled\n");

            goto the_end;

        }

    } else {

        pict = picture2;

    }



    /* XXX: resampling could be done before raw format convertion in

       some cases to go faster */

    /* XXX: only works for YUV420P */

    if (ost->video_resample) {

        picture = &ost->pict_tmp;

        img_resample(ost->img_resample_ctx, picture, pict);

    } else {

        picture = pict;

    }

    nb=1;

    /* duplicates frame if needed */

    /* XXX: pb because no interleaving */

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

        if (enc->codec_id != CODEC_ID_RAWVIDEO) {

            /* handles sameq here. This is not correct because it may

               not be a global option */

            if (same_quality) {

                enc->quality = dec->quality;

            }

            

            ret = avcodec_encode_video(enc, 

                                       video_buffer, VIDEO_BUFFER_SIZE,

                                       picture);

            //enc->frame_number = enc->real_pict_num;

            s->oformat->write_packet(s, ost->index, video_buffer, ret, 0);

            *frame_size = ret;

            //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d",

            //        enc->frame_number-1, enc->real_pict_num, ret,

            //        enc->pict_type);

        } else {

            write_picture(s, ost->index, picture, enc->pix_fmt, enc->width, enc->height);

        }

    }

    the_end:

    av_free(buf);

    av_free(buf1);

    av_free(video_buffer);

}

static void do_video_out(AVFormatContext *s, 

                         AVOutputStream *ost, 

                         AVInputStream *ist,

                         AVPicture *picture1,

                         int *frame_size)

{

    int n1, n2, nb, i, ret, frame_number, dec_frame_rate;

    AVPicture *picture, *picture2, *pict;

    AVPicture picture_tmp1, picture_tmp2;

    UINT8 *video_buffer;

    UINT8 *buf = NULL, *buf1 = NULL;

    AVCodecContext *enc, *dec;



#define VIDEO_BUFFER_SIZE (1024*1024)



    enc = &ost->st->codec;

    dec = &ist->st->codec;



    frame_number = ist->frame_number;

    dec_frame_rate = ist->st->r_frame_rate;

    

    

    n1 = ((INT64)frame_number * enc->frame_rate) / dec_frame_rate;

    n2 = (((INT64)frame_number + 1) * enc->frame_rate) / dec_frame_rate;

    nb = n2 - n1;

    if (nb <= 0) 

        return;



    video_buffer= av_malloc(VIDEO_BUFFER_SIZE);

    if(!video_buffer) return;



    

    if (do_deinterlace) {

        int size;



        

        size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height);

        buf1 = av_malloc(size);

        if (!buf1)

            return;

        

        picture2 = &picture_tmp2;

        avpicture_fill(picture2, buf1, dec->pix_fmt, dec->width, dec->height);



        if (avpicture_deinterlace(picture2, picture1, 

                                  dec->pix_fmt, dec->width, dec->height) < 0) {

            

            av_free(buf1);

            buf1 = NULL;

            picture2 = picture1;

        }

    } else {

        picture2 = picture1;

    }



    

    if (enc->pix_fmt != dec->pix_fmt) {

        int size;



        

        size = avpicture_get_size(enc->pix_fmt, dec->width, dec->height);

        buf = av_malloc(size);

        if (!buf)

            return;

        pict = &picture_tmp1;

        avpicture_fill(pict, buf, enc->pix_fmt, dec->width, dec->height);

        

        if (img_convert(pict, enc->pix_fmt, 

                        picture2, dec->pix_fmt, 

                        dec->width, dec->height) < 0) {

            fprintf(stderr, "pixel format conversion not handled\n");

            goto the_end;

        }

    } else {

        pict = picture2;

    }



    



    

    if (ost->video_resample) {

        picture = &ost->pict_tmp;

        img_resample(ost->img_resample_ctx, picture, pict);

    } else {

        picture = pict;

    }

    nb=1;

    

    

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

        if (enc->codec_id != CODEC_ID_RAWVIDEO) {

            



            if (same_quality) {

                enc->quality = dec->quality;

            }

            

            ret = avcodec_encode_video(enc, 

                                       video_buffer, VIDEO_BUFFER_SIZE,

                                       picture);

            

            s->oformat->write_packet(s, ost->index, video_buffer, ret, 0);

            *frame_size = ret;

            

            

            

        } else {

            write_picture(s, ost->index, picture, enc->pix_fmt, enc->width, enc->height);

        }

    }

    the_end:

    av_free(buf);

    av_free(buf1);

    av_free(video_buffer);

}

static void FUNC_0(AVFormatContext *VAR_0, 

                         AVOutputStream *VAR_1, 

                         AVInputStream *VAR_2,

                         AVPicture *VAR_3,

                         int *VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    AVPicture *picture, *picture2, *pict;

    AVPicture picture_tmp1, picture_tmp2;

    UINT8 *video_buffer;

    UINT8 *buf = NULL, *buf1 = NULL;

    AVCodecContext *enc, *dec;



#define VIDEO_BUFFER_SIZE (1024*1024)



    enc = &VAR_1->st->codec;

    dec = &VAR_2->st->codec;



    VAR_10 = VAR_2->VAR_10;

    VAR_11 = VAR_2->st->r_frame_rate;

    

    

    VAR_5 = ((INT64)VAR_10 * enc->frame_rate) / VAR_11;

    VAR_6 = (((INT64)VAR_10 + 1) * enc->frame_rate) / VAR_11;

    VAR_7 = VAR_6 - VAR_5;

    if (VAR_7 <= 0) 

        return;



    video_buffer= av_malloc(VIDEO_BUFFER_SIZE);

    if(!video_buffer) return;



    

    if (do_deinterlace) {

        int VAR_13;



        

        VAR_13 = avpicture_get_size(dec->pix_fmt, dec->width, dec->height);

        buf1 = av_malloc(VAR_13);

        if (!buf1)

            return;

        

        picture2 = &picture_tmp2;

        avpicture_fill(picture2, buf1, dec->pix_fmt, dec->width, dec->height);



        if (avpicture_deinterlace(picture2, VAR_3, 

                                  dec->pix_fmt, dec->width, dec->height) < 0) {

            

            av_free(buf1);

            buf1 = NULL;

            picture2 = VAR_3;

        }

    } else {

        picture2 = VAR_3;

    }



    

    if (enc->pix_fmt != dec->pix_fmt) {

        int VAR_13;



        

        VAR_13 = avpicture_get_size(enc->pix_fmt, dec->width, dec->height);

        buf = av_malloc(VAR_13);

        if (!buf)

            return;

        pict = &picture_tmp1;

        avpicture_fill(pict, buf, enc->pix_fmt, dec->width, dec->height);

        

        if (img_convert(pict, enc->pix_fmt, 

                        picture2, dec->pix_fmt, 

                        dec->width, dec->height) < 0) {

            fprintf(stderr, "pixel format conversion not handled\n");

            goto the_end;

        }

    } else {

        pict = picture2;

    }



    



    

    if (VAR_1->video_resample) {

        picture = &VAR_1->pict_tmp;

        img_resample(VAR_1->img_resample_ctx, picture, pict);

    } else {

        picture = pict;

    }

    VAR_7=1;

    

    

    for(VAR_8=0;VAR_8<VAR_7;VAR_8++) {

        if (enc->codec_id != CODEC_ID_RAWVIDEO) {

            



            if (same_quality) {

                enc->quality = dec->quality;

            }

            

            VAR_9 = avcodec_encode_video(enc, 

                                       video_buffer, VIDEO_BUFFER_SIZE,

                                       picture);

            

            VAR_0->oformat->write_packet(VAR_0, VAR_1->index, video_buffer, VAR_9, 0);

            *VAR_4 = VAR_9;

            

            

            

        } else {

            write_picture(VAR_0, VAR_1->index, picture, enc->pix_fmt, enc->width, enc->height);

        }

    }

    the_end:

    av_free(buf);

    av_free(buf1);

    av_free(video_buffer);

}

static void FUNC_0(AVFormatContext *VAR_0,
AVOutputStream *VAR_1,
AVInputStream *VAR_2,
AVPicture *VAR_3,
int *VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; AVPicture *picture, *picture2, *pict; AVPicture picture_tmp1, picture_tmp2; UINT8 *video_buffer; UINT8 *buf = NULL, *buf1 = NULL; AVCodecContext *enc, *dec; #define VIDEO_BUFFER_SIZE (1024*1024)
enc = &VAR_1->st->codec; dec = &VAR_2->st->codec; VAR_10 = VAR_2->VAR_10; VAR_11 = VAR_2->st->r_frame_rate; VAR_5 = ((INT64)VAR_10 * enc->frame_rate) / VAR_11; VAR_6 = (((INT64)VAR_10 + 1) * enc->frame_rate) / VAR_11; VAR_7 = VAR_6 - VAR_5; if (VAR_7 <= 0)
return; video_buffer= av_malloc(VIDEO_BUFFER_SIZE); if(!video_buffer) return; if (do_deinterlace) { int VAR_13; VAR_13 = avpicture_get_size(dec->pix_fmt, dec->width, dec->height); buf1 = av_malloc(VAR_13); if (!buf1)
return; picture2 = &picture_tmp2; avpicture_fill(picture2, buf1, dec->pix_fmt, dec->width, dec->height); if (avpicture_deinterlace(picture2, VAR_3,
dec->pix_fmt, dec->width, dec->height) < 0) { av_free(buf1); buf1 = NULL; picture2 = VAR_3; } } else { picture2 = VAR_3; } if (enc->pix_fmt != dec->pix_fmt) { int VAR_13; VAR_13 = avpicture_get_size(enc->pix_fmt, dec->width, dec->height); buf = av_malloc(VAR_13); if (!buf)
return; pict = &picture_tmp1; avpicture_fill(pict, buf, enc->pix_fmt, dec->width, dec->height); if (img_convert(pict, enc->pix_fmt,
picture2, dec->pix_fmt,
dec->width, dec->height) < 0) { fprintf(stderr, "pixel format conversion not handled\n"); goto the_end; } } else { pict = picture2; } if (VAR_1->video_resample) { picture = &VAR_1->pict_tmp; img_resample(VAR_1->img_resample_ctx, picture, pict); } else { picture = pict; } VAR_7=1; for(VAR_8=0;VAR_8<VAR_7;VAR_8++) { if (enc->codec_id != CODEC_ID_RAWVIDEO) { if (same_quality) { enc->quality = dec->quality; } VAR_9 = avcodec_encode_video(enc,
video_buffer, VIDEO_BUFFER_SIZE,
picture); VAR_0->oformat->write_packet(VAR_0, VAR_1->index, video_buffer, VAR_9, 0); *VAR_4 = VAR_9; } else { write_picture(VAR_0, VAR_1->index, picture, enc->pix_fmt, enc->width, enc->height); } } the_end:
av_free(buf); av_free(buf1); av_free(video_buffer); }