for(i=0; i<MAX_PICTURE_COUNT; i++){ if(s->picture[i].data[0]==NULL) break; } assert(i<MAX_PICTURE_COUNT);
i= find_unused_picture(s, 0);
int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx){    int i, r;    AVVideoFrame *pic;    s->mb_skiped = 0;        /* mark&release old frames */    if (s->pict_type != B_TYPE && s->last_picture.data[0]) {        for(i=0; i<MAX_PICTURE_COUNT; i++){            if(s->picture[i].data[0] == s->last_picture.data[0]){//                s->picture[i].reference=0;                avctx->release_buffer(avctx, (AVVideoFrame*)&s->picture[i]);                break;            }            }        assert(i<MAX_PICTURE_COUNT);        /* release forgotten pictures */        /* if(mpeg124/h263) */        if(!s->encoding){            for(i=0; i<MAX_PICTURE_COUNT; i++){                if(s->picture[i].data[0] && s->picture[i].data[0] != s->next_picture.data[0] && s->picture[i].reference){                    fprintf(stderr, "releasing zombie picture\n");                    avctx->release_buffer(avctx, (AVVideoFrame*)&s->picture[i]);                                }            }        }    }alloc:    if(!s->encoding){        /* find unused Picture */        for(i=0; i<MAX_PICTURE_COUNT; i++){            if(s->picture[i].data[0]==NULL) break;        }        assert(i<MAX_PICTURE_COUNT);            pic= (AVVideoFrame*)&s->picture[i];        pic->reference= s->pict_type != B_TYPE;        pic->coded_picture_number= s->current_picture.coded_picture_number+1;                r= avctx->get_buffer(avctx, pic);            if(r<0 || (s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1]))){            fprintf(stderr, "get_buffer() failed (stride changed), bye bye\n");            return -1;        }        s->linesize  = pic->linesize[0];        s->uvlinesize= pic->linesize[1];            if(pic->qscale_table==NULL)            alloc_picture(s, (Picture*)pic);        s->current_picture= s->picture[i];    }    if (s->pict_type != B_TYPE) {        s->last_picture= s->next_picture;        s->next_picture= s->current_picture;    }        if(s->pict_type != I_TYPE && s->last_picture.data[0]==NULL){        fprintf(stderr, "warning: first frame is no keyframe\n");        assert(s->pict_type != B_TYPE); //these should have been dropped if we dont have a reference        goto alloc;    }       s->hurry_up= s->avctx->hurry_up;    s->error_resilience= avctx->error_resilience;    /* set dequantizer, we cant do it during init as it might change for mpeg4       and we cant do it in the header decode as init isnt called for mpeg4 there yet */    if(s->out_format == FMT_H263){        if(s->mpeg_quant)            s->dct_unquantize = s->dct_unquantize_mpeg2;        else            s->dct_unquantize = s->dct_unquantize_h263;    }else         s->dct_unquantize = s->dct_unquantize_mpeg1;    return 0;}