(UINT8 *)picture, sizeof(AVPicture));
(UINT8 *)final_picture, sizeof(AVPicture));
static void do_video_out(AVFormatContext *s,                          AVOutputStream *ost,                          AVInputStream *ist,                         AVPicture *picture1,                         int *frame_size, AVOutputStream *audio_sync){    int nb_frames, i, ret;    AVPicture *picture, *pict;    AVPicture picture_tmp1;    static 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;    /* by default, we output a single frame */    nb_frames = 1;    /* NOTE: the A/V sync is always done by considering the audio is       the master clock. It is suffisant for transcoding or playing,       but not for the general case */    if (audio_sync) {        /* compute the A-V delay and duplicate/remove frames if needed */        double adelta, vdelta, apts, vpts, av_delay;                if (audio_sync->sync_ipts != AV_NOPTS_VALUE &&            ost->sync_ipts != AV_NOPTS_VALUE) {                        adelta = (double)(ost->st->pts.val - audio_sync->sync_opts) *                 s->pts_num / s->pts_den;            apts = audio_sync->sync_ipts + adelta;                         vdelta = (double)(ost->st->pts.val - ost->sync_opts) *                s->pts_num / s->pts_den;            vpts = ost->sync_ipts + vdelta;                        av_delay = apts - vpts;            //            printf("delay=%f\n", av_delay);            if (av_delay < -AV_DELAY_MAX)                nb_frames = 2;            else if (av_delay > AV_DELAY_MAX)                nb_frames = 0;        }    } else {        double vdelta;        if (ost->sync_ipts != AV_NOPTS_VALUE) {            vdelta = (double)(ost->st->pts.val) * s->pts_num / s->pts_den - (ost->sync_ipts - ost->sync_ipts_offset);            if (vdelta < 100 && vdelta > -100) {                if (vdelta < -AV_DELAY_MAX)                    nb_frames = 2;                else if (vdelta > AV_DELAY_MAX)                    nb_frames = 0;            } else {                ost->sync_ipts_offset -= vdelta;            }#if 0            {                static char *action[] = { "drop frame", "copy frame", "dup frame" };                printf("Input PTS %12.6f, output PTS %12.6f: %s\n",                    (double) ost->sync_ipts, (double) ost->st->pts.val * s->pts_num / s->pts_den,                    action[nb_frames]);            }#endif        }    }    if (nb_frames <= 0)         return;    if (!video_buffer)        video_buffer = av_malloc(VIDEO_BUFFER_SIZE);    if (!video_buffer)        return;    /* 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,                         picture1, dec->pix_fmt,                         dec->width, dec->height) < 0) {            fprintf(stderr, "pixel format conversion not handled\n");            goto the_end;        }    } else {        pict = picture1;    }    /* 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;    }    /* duplicates frame if needed */    /* XXX: pb because no interleaving */    for(i=0;i<nb_frames;i++) {        if (enc->codec_id != CODEC_ID_RAWVIDEO) {            AVVideoFrame big_picture;                        memset(&big_picture, 0, sizeof(AVVideoFrame));            *(AVPicture*)&big_picture= *picture;                                    /* handles sameq here. This is not correct because it may               not be a global option */            if (same_quality) {                big_picture.quality = ist->st->quality;            }else                big_picture.quality = ost->st->quality;                        ret = avcodec_encode_video(enc,                                        video_buffer, VIDEO_BUFFER_SIZE,                                       &big_picture);            //enc->frame_number = enc->real_pict_num;            av_write_frame(s, ost->index, video_buffer, ret);            *frame_size = ret;            //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d",            //        enc->frame_number-1, enc->real_pict_num, ret,            //        enc->pict_type);            /* if two pass, output log */            if (ost->logfile && enc->stats_out) {                fprintf(ost->logfile, "%s", enc->stats_out);            }        } else {            if (s->oformat->flags & AVFMT_RAWPICTURE) {                /* raw pictures are written as AVPicture structure to                   avoid any copies. We support temorarily the older                   method. */                av_write_frame(s, ost->index,                                (UINT8 *)picture, sizeof(AVPicture));            } else {                write_picture(s, ost->index, picture, enc->pix_fmt,                               enc->width, enc->height);            }        }        ost->frame_number++;    } the_end:    av_free(buf);    av_free(buf1);}