if ((s->picture_number % s->gop_size) == 0)
if (s->picture_in_gop_number >= s->gop_size){ s->picture_in_gop_number=0;
int MPV_encode_picture(AVCodecContext *avctx,                       unsigned char *buf, int buf_size, void *data){    MpegEncContext *s = avctx->priv_data;    AVPicture *pict = data;    int i, j;    if (s->fixed_qscale)         s->qscale = avctx->quality;    init_put_bits(&s->pb, buf, buf_size, NULL, NULL);    if (!s->intra_only) {        /* first picture of GOP is intra */        if ((s->picture_number % s->gop_size) == 0)            s->pict_type = I_TYPE;        else            s->pict_type = P_TYPE;    } else {        s->pict_type = I_TYPE;    }        MPV_frame_start(s);        for(i=0;i<3;i++) {        UINT8 *src = pict->data[i];        UINT8 *dest = s->current_picture[i];        int src_wrap = pict->linesize[i];        int dest_wrap = s->linesize;        int w = s->width;        int h = s->height;        if (i >= 1) {            dest_wrap >>= 1;            w >>= 1;            h >>= 1;        }        if(dest_wrap==src_wrap){            s->new_picture[i] = pict->data[i];        } else {            for(j=0;j<h;j++) {                memcpy(dest, src, w);                dest += dest_wrap;                src += src_wrap;            }            s->new_picture[i] = s->current_picture[i];	    }    }    encode_picture(s, s->picture_number);    avctx->key_frame = (s->pict_type == I_TYPE);        MPV_frame_end(s);    s->picture_number++;    if (s->out_format == FMT_MJPEG)        mjpeg_picture_trailer(s);    flush_put_bits(&s->pb);    s->last_frame_bits= s->frame_bits;    s->frame_bits  = (pbBufPtr(&s->pb) - s->pb.buf) * 8;    s->total_bits += s->frame_bits;    avctx->quality = s->qscale;    if (avctx->get_psnr) {        /* At this point pict->data should have the original frame   */        /* an s->current_picture should have the coded/decoded frame */        get_psnr(pict->data, s->current_picture,                 pict->linesize, s->linesize, avctx);    }    return pbBufPtr(&s->pb) - s->pb.buf;}