s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; }else{ s->reordered_input_picture[0]= s->input_picture[s->max_b_frames]; if(s->picture_in_gop_number + s->max_b_frames >= s->gop_size) s->reordered_input_picture[0]->pict_type= I_TYPE; else s->reordered_input_picture[0]->pict_type= P_TYPE; s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; for(i=0; i<s->max_b_frames; i++){ coded_pic_num++; s->reordered_input_picture[i+1]= s->input_picture[i]; s->reordered_input_picture[i+1]->pict_type= B_TYPE; s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num; }
else s->reordered_input_picture[0]->pict_type= P_TYPE; s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; for(i=0; i<b_frames; i++){ coded_pic_num++; s->reordered_input_picture[i+1]= s->input_picture[i]; s->reordered_input_picture[i+1]->pict_type= B_TYPE; s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num;
static void select_input_picture(MpegEncContext *s){    int i;    const int encoding_delay= s->max_b_frames;    int coded_pic_num=0;        if(s->reordered_input_picture[0])        coded_pic_num= s->reordered_input_picture[0]->coded_picture_number + 1;//printf("cpn:%d\n", coded_pic_num);    for(i=1; i<MAX_PICTURE_COUNT; i++)        s->reordered_input_picture[i-1]= s->reordered_input_picture[i];    s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL;    /* set next picture types & ordering */    if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){        if(s->input_picture[0]->pict_type){            /* user selected pict_type */            if(s->input_picture[0]->pict_type == I_TYPE){                s->reordered_input_picture[0]= s->input_picture[0];                s->reordered_input_picture[0]->coded_picture_number= coded_pic_num;            }else{                int b_frames;                for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){                    if(s->input_picture[b_frames]->pict_type!=B_TYPE) break;                }                                if(b_frames > s->max_b_frames){                    fprintf(stderr, "warning, too many bframes in a row\n");                    b_frames = s->max_b_frames;                    s->input_picture[b_frames]->pict_type= I_TYPE;                }                                s->reordered_input_picture[0]= s->input_picture[b_frames];                s->reordered_input_picture[0]->coded_picture_number= coded_pic_num;                for(i=0; i<b_frames; i++){                    coded_pic_num++;                    s->reordered_input_picture[i+1]= s->input_picture[i];                    s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num;                }                }        }else{            if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture.data[0]==NULL || s->intra_only){                s->reordered_input_picture[0]= s->input_picture[0];                s->reordered_input_picture[0]->pict_type= I_TYPE;                s->reordered_input_picture[0]->coded_picture_number= coded_pic_num;            }else{                s->reordered_input_picture[0]= s->input_picture[s->max_b_frames];                if(s->picture_in_gop_number + s->max_b_frames >= s->gop_size)                    s->reordered_input_picture[0]->pict_type= I_TYPE;                else                    s->reordered_input_picture[0]->pict_type= P_TYPE;                s->reordered_input_picture[0]->coded_picture_number= coded_pic_num;                for(i=0; i<s->max_b_frames; i++){                    coded_pic_num++;                    s->reordered_input_picture[i+1]= s->input_picture[i];                    s->reordered_input_picture[i+1]->pict_type= B_TYPE;                    s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num;                }                }        }    }        if(s->reordered_input_picture[0]){        if(s->reordered_input_picture[0]->pict_type==B_TYPE){            s->reordered_input_picture[0]->reference=0;        }        s->current_picture= *s->reordered_input_picture[0];        s->new_picture= s->current_picture;        s->new_picture.data[0]+=16;        s->new_picture.data[1]+=16;        s->new_picture.data[2]+=16;            s->picture_number= s->new_picture.display_picture_number;//printf("dpn:%d\n", s->picture_number);    }else{       memset(&s->new_picture, 0, sizeof(Picture));    }}