[cvs] / xvidcore / src / plugins / plugin_2pass2.c Repository:
ViewVC logotype

Diff of /xvidcore/src/plugins/plugin_2pass2.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.4, Fri May 16 17:19:51 2003 UTC revision 1.1.2.6, Tue May 20 17:28:25 2003 UTC
# Line 171  Line 171 
171          }else if (type == 'b') {          }else if (type == 'b') {
172              s->type = XVID_TYPE_BVOP;              s->type = XVID_TYPE_BVOP;
173          }else{  /* unknown type */          }else{  /* unknown type */
174              printf("unk\n");              DPRINTF(XVID_DEBUG_RC, "unknown stats frame type; assuming pvop");
175              continue;              s->type = XVID_TYPE_PVOP;
176          }          }
177    
178          i++;          i++;
# Line 186  Line 186 
186    
187    
188    
189    #if 0
190  static void print_stats(rc_2pass2_t * rc)  static void print_stats(rc_2pass2_t * rc)
191  {  {
192      int i;      int i;
193      for (i = 0; i < rc->num_frames; i++) {      for (i = 0; i < rc->num_frames; i++) {
194          stat_t * s = &rc->stats[i];          stat_t * s = &rc->stats[i];
195          printf("%i %i %i %i\n", s->type, s->quant, s->length, s->scaled_length);          DPRINTF(XVID_DEBUG_RC, "%i %i %i %i\n", s->type, s->quant, s->length, s->scaled_length);
   
196      }      }
197  }  }
198    #endif
199    
200  /* pre-process the statistics data  /* pre-process the statistics data
201      - for each type, count, tot_length, min_length, max_length      - for each type, count, tot_length, min_length, max_length
# Line 287  Line 287 
287      }      }
288      rc->avg_weight = n>0 ? rc->avg_weight/n : 1.0;      rc->avg_weight = n>0 ? rc->avg_weight/n : 1.0;
289    
290      /*for (i=0; i < rc->num_frames; i++) {      DPRINTF(XVID_DEBUG_RC, "center_weight: %f (for %i frames);   fixed_bytes: %i\n", rc->avg_weight, n, rc->tot_quant);
         printf("[%i] mode=%i weight=%f\n", i, rc->stats[i].zone_mode, rc->stats[i].weight);  
     }*/  
   
     printf("center_weight: %f (for %i frames);   fixed_bytes: %i\n", rc->avg_weight, n, rc->tot_quant);  
291  }  }
292    
293    
# Line 306  Line 302 
302          int i;          int i;
303    
304    
         if (target <= 0 || target >= pass1_length) {  
                 printf("undersize warning\n");  
         }  
   
305          /* perform an initial scale pass.          /* perform an initial scale pass.
306             if a frame size is scaled underneath our hardcoded minimums, then we force the             if a frame size is scaled underneath our hardcoded minimums, then we force the
307             frame size to the minimum, and deduct the original & scaled frmae length from the             frame size to the minimum, and deduct the original & scaled frmae length from the
# Line 319  Line 311 
311          min_size[1] = (rc->stats[0].blks[0] + 88) / 8;          min_size[1] = (rc->stats[0].blks[0] + 88) / 8;
312          min_size[2] = 8;          min_size[2] = 8;
313    
   
314          scaler = (double)target / (double)pass1_length;          scaler = (double)target / (double)pass1_length;
315          //printf("target=%i, tot_length=%i, scaler=%f\n", (int)target, (int)pass1_length, scaler);  
316            if (target <= 0 || pass1_length <= 0 || target >= pass1_length) {
317                    DPRINTF(XVID_DEBUG_RC, "undersize warning\n");
318            scaler = 1.0;
319            }
320    
321        DPRINTF(XVID_DEBUG_RC, "target=%i, tot_length=%i, scaler=%f\n", (int)target, (int)pass1_length, scaler);
322    
323          for (i=0; i<rc->num_frames; i++) {          for (i=0; i<rc->num_frames; i++) {
324                  stat_t * s = &rc->stats[i];                  stat_t * s = &rc->stats[i];
# Line 331  Line 328 
328              s->scaled_length = s->length;              s->scaled_length = s->length;
329          }else {          }else {
330                      len = (int)((double)s->length * scaler * s->weight / rc->avg_weight);                      len = (int)((double)s->length * scaler * s->weight / rc->avg_weight);
331                      if (len < min_size[s->type]) {              /* force frame size */                      if (len < min_size[s->type-1]) {            /* force frame size */
332                              s->scaled_length = min_size[s->type];                              s->scaled_length = min_size[s->type-1];
333                              target -= s->scaled_length;                              target -= s->scaled_length;
334                              pass1_length -= s->length;                              pass1_length -= s->length;
335                      }else{                      }else{
# Line 341  Line 338 
338          }          }
339          }          }
340    
341          if (target <= 0 || target >= pass1_length) {      scaler = (double)target / (double)pass1_length;
342                  printf("undersize warning\n");      if (target <= 0 || pass1_length <= 0 || target >= pass1_length) {
343                  return;                  DPRINTF(XVID_DEBUG_RC,"undersize warning\n");
344                    scaler = 1.0;
345          }          }
346    
347          scaler = (double)target / (double)pass1_length;          DPRINTF(XVID_DEBUG_RC, "target=%i, tot_length=%i, scaler=%f\n", (int)target, (int)pass1_length, scaler);
         //printf("target=%i, tot_length=%i, scaler=%f\n", (int)target, (int)tot_length, scaler);  
348    
349          for (i=0; i<rc->num_frames; i++) {          for (i=0; i<rc->num_frames; i++) {
350                  stat_t * s = &rc->stats[i];                  stat_t * s = &rc->stats[i];
# Line 356  Line 353 
353                          s->scaled_length = (int)((double)s->length * scaler * s->weight / rc->avg_weight);                          s->scaled_length = (int)((double)s->length * scaler * s->weight / rc->avg_weight);
354                  }                  }
355          }          }
   
356  }  }
357    
358    
# Line 515  Line 511 
511      rc->curve_comp_scale = total1 / total2;      rc->curve_comp_scale = total1 / total2;
512    
513      if (!rc->param.use_alt_curve) {      if (!rc->param.use_alt_curve) {
514          printf("middle frame size for asymmetric curve compression: %i\n",          DPRINTF(XVID_DEBUG_RC, "middle frame size for asymmetric curve compression: %i\n",
515              (int)(rc->avg_length[XVID_TYPE_PVOP-1] * rc->curve_comp_scale));              (int)(rc->avg_length[XVID_TYPE_PVOP-1] * rc->curve_comp_scale));
516      }      }
517    
# Line 532  Line 528 
528    
529          /* special info for alt curve:  bias bonus and quantizer thresholds */          /* special info for alt curve:  bias bonus and quantizer thresholds */
530    
531                  printf("avg scaled framesize:%i", (int)rc->avg_length[XVID_TYPE_PVOP-1]);                  DPRINTF(XVID_DEBUG_RC, "avg scaled framesize:%i", (int)rc->avg_length[XVID_TYPE_PVOP-1]);
532                  printf("bias bonus:%i bytes", (int)rc->alt_curve_curve_bias_bonus);                  DPRINTF(XVID_DEBUG_RC, "bias bonus:%i bytes", (int)rc->alt_curve_curve_bias_bonus);
533    
534                  for (i=1; i <= (int)(rc->alt_curve_high*2)+1; i++) {                  for (i=1; i <= (int)(rc->alt_curve_high*2)+1; i++) {
535              double curve_temp, dbytes;              double curve_temp, dbytes;
# Line 582  Line 578 
578                                  if (newquant != oldquant) {                                  if (newquant != oldquant) {
579                      int percent = (int)((i - rc->avg_length[XVID_TYPE_PVOP-1]) * 100.0 / rc->avg_length[XVID_TYPE_PVOP-1]);                      int percent = (int)((i - rc->avg_length[XVID_TYPE_PVOP-1]) * 100.0 / rc->avg_length[XVID_TYPE_PVOP-1]);
580                                          oldquant = newquant;                                          oldquant = newquant;
581                                          printf("quant:%i threshold at %i : %i percent", newquant, i, percent);                                          DPRINTF(XVID_DEBUG_RC, "quant:%i threshold at %i : %i percent", newquant, i, percent);
582                                  }                                  }
583                          }                          }
584                  }                  }
# Line 633  Line 629 
629      if (rc->param.min_key_interval <= 0) rc->param.min_key_interval = 300;      if (rc->param.min_key_interval <= 0) rc->param.min_key_interval = 300;
630    
631      if (!det_stats_length(rc, param->filename)){      if (!det_stats_length(rc, param->filename)){
632          DPRINTF(DPRINTF_RC,"fopen %s failed\n", param->filename);          DPRINTF(XVID_DEBUG_RC,"fopen %s failed\n", param->filename);
633          free(rc);          free(rc);
634          return XVID_ERR_FAIL;          return XVID_ERR_FAIL;
635      }      }
# Line 651  Line 647 
647      }      }
648    
649      if (!load_stats(rc, param->filename)) {      if (!load_stats(rc, param->filename)) {
650          DPRINTF(DPRINTF_RC,"fopen %s failed\n", param->filename);          DPRINTF(XVID_DEBUG_RC,"fopen %s failed\n", param->filename);
651          free(rc->keyframe_locations);          free(rc->keyframe_locations);
652          free(rc->stats);          free(rc->stats);
653          free(rc);          free(rc);
# Line 666  Line 662 
662                  rc->target = (rc->param.bitrate * rc->num_frames * create->fincr) / (create->fbase * 8);                  rc->target = (rc->param.bitrate * rc->num_frames * create->fincr) / (create->fbase * 8);
663          }          }
664    
665        DPRINTF(XVID_DEBUG_RC, "rc->target : %i\n", rc->target);
666    
667          rc->target -= rc->num_frames*24;        /* avi file header */          rc->target -= rc->num_frames*24;        /* avi file header */
668    
669    
670          pre_process0(rc);          pre_process0(rc);
671    
672          if (rc->param.bitrate) {          if (rc->param.bitrate) {
673          zone_process(rc, create);          zone_process(rc, create);
674                  internal_scale(rc);                  internal_scale(rc);
# Line 724  Line 723 
723              data->quant = (int)rc->fq_error;              data->quant = (int)rc->fq_error;
724              rc->fq_error -= data->quant;              rc->fq_error -= data->quant;
725    
726                s->desired_length = s->length;
727    
728          }else { /* XVID_ZONE_WEIGHT */          }else { /* XVID_ZONE_WEIGHT */
729    
730              if (data->frame_num >= rc->num_frames) {              if (data->frame_num >= rc->num_frames) {
# Line 840  Line 841 
841                          rc->curve_comp_error += dbytes - (int)dbytes;                          rc->curve_comp_error += dbytes - (int)dbytes;
842              }              }
843    
844                  if (desired > s->length){  
845                    if (desired > s->length) {  /* if desired length exceeds the pass1 length.. */
846                          rc->curve_comp_error += desired - s->length;                          rc->curve_comp_error += desired - s->length;
847                          desired = s->length;                          desired = s->length;
848                  }else{                  }else{
# Line 951  Line 953 
953    
954                          if (data->quant > rc->last_quant[s->type-1] + 2) {                          if (data->quant > rc->last_quant[s->type-1] + 2) {
955                                  data->quant = rc->last_quant[s->type-1] + 2;                                  data->quant = rc->last_quant[s->type-1] + 2;
956                                  DPRINTF(DPRINTF_RC, "p/b-frame quantizer prevented from rising too steeply");                                  DPRINTF(XVID_DEBUG_RC, "p/b-frame quantizer prevented from rising too steeply");
957                          }                          }
958                          if (data->quant < rc->last_quant[s->type-1] - 2) {                          if (data->quant < rc->last_quant[s->type-1] - 2) {
959                                  data->quant = rc->last_quant[s->type-1] - 2;                                  data->quant = rc->last_quant[s->type-1] - 2;
960                                  DPRINTF(DPRINTF_RC, "p/b-frame quantizer prevented from falling too steeply");                                  DPRINTF(XVID_DEBUG_RC, "p/b-frame quantizer prevented from falling too steeply");
961                          }                          }
962                  }                  }
963    
# Line 1004  Line 1006 
1006          rc->KFoverflow -= rc->KFoverflow_partial;          rc->KFoverflow -= rc->KFoverflow_partial;
1007      }      }
1008    
1009      printf("[%i] quant:%i stats1:%i scaled:%i actual:%i overflow:%i\n",      DPRINTF(XVID_DEBUG_RC, "[%i] quant:%i stats1:%i scaled:%i actual:%i overflow:%i\n",
1010          data->frame_num,          data->frame_num,
1011          data->quant,          data->quant,
1012          s->length,          s->length,

Legend:
Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.6

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4