comparison ratecontrol.c @ 3064:a5e0b58b4471 libavcodec

xvid ratecontrol support
author michael
date Tue, 24 Jan 2006 21:57:26 +0000
parents 0b546eab515d
children b2c352a66a73
comparison
equal deleted inserted replaced
3063:f02d0b59279c 3064:a5e0b58b4471
36 36
37 static int init_pass2(MpegEncContext *s); 37 static int init_pass2(MpegEncContext *s);
38 static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num); 38 static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num);
39 39
40 void ff_write_pass1_stats(MpegEncContext *s){ 40 void ff_write_pass1_stats(MpegEncContext *s){
41 snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d;\n", 41 snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n",
42 s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type, 42 s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type,
43 s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits, 43 s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits,
44 s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count); 44 s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits);
45 } 45 }
46 46
47 int ff_rate_control_init(MpegEncContext *s) 47 int ff_rate_control_init(MpegEncContext *s)
48 { 48 {
49 RateControlContext *rcc= &s->rc_context; 49 RateControlContext *rcc= &s->rc_context;
105 105
106 assert(picture_number >= 0); 106 assert(picture_number >= 0);
107 assert(picture_number < rcc->num_entries); 107 assert(picture_number < rcc->num_entries);
108 rce= &rcc->entry[picture_number]; 108 rce= &rcc->entry[picture_number];
109 109
110 e+=sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d", 110 e+=sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d",
111 &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, &rce->mv_bits, &rce->misc_bits, 111 &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, &rce->mv_bits, &rce->misc_bits,
112 &rce->f_code, &rce->b_code, &rce->mc_mb_var_sum, &rce->mb_var_sum, &rce->i_count); 112 &rce->f_code, &rce->b_code, &rce->mc_mb_var_sum, &rce->mb_var_sum, &rce->i_count, &rce->skip_count, &rce->header_bits);
113 if(e!=12){ 113 if(e!=14){
114 av_log(s->avctx, AV_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e); 114 av_log(s->avctx, AV_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e);
115 return -1; 115 return -1;
116 } 116 }
117
117 p= next; 118 p= next;
118 } 119 }
120
121 //FIXME maybe move to end
122 if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
123 return ff_xvid_rate_control_init(s);
119 124
120 if(init_pass2(s) < 0) return -1; 125 if(init_pass2(s) < 0) return -1;
121 } 126 }
122 127
123 if(!(s->flags&CODEC_FLAG_PASS2)){ 128 if(!(s->flags&CODEC_FLAG_PASS2)){
179 { 184 {
180 RateControlContext *rcc= &s->rc_context; 185 RateControlContext *rcc= &s->rc_context;
181 emms_c(); 186 emms_c();
182 187
183 av_freep(&rcc->entry); 188 av_freep(&rcc->entry);
189
190 if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
191 ff_xvid_rate_control_uninit(s);
184 } 192 }
185 193
186 static inline double qp2bits(RateControlEntry *rce, double qp){ 194 static inline double qp2bits(RateControlEntry *rce, double qp){
187 if(qp<=0.0){ 195 if(qp<=0.0){
188 av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n"); 196 av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n");
638 int var; 646 int var;
639 const int pict_type= s->pict_type; 647 const int pict_type= s->pict_type;
640 Picture * const pic= &s->current_picture; 648 Picture * const pic= &s->current_picture;
641 emms_c(); 649 emms_c();
642 650
651 if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
652 return ff_xvid_rate_estimate_qscale(s, dry_run);
653
643 get_qminmax(&qmin, &qmax, s, pict_type); 654 get_qminmax(&qmin, &qmax, s, pict_type);
644 655
645 fps= 1/av_q2d(s->avctx->time_base); 656 fps= 1/av_q2d(s->avctx->time_base);
646 //printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate); 657 //printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate);
647 /* update predictors */ 658 /* update predictors */