[svn] / branches / dev-api-4 / xvidcore / src / plugins / plugin_2pass2.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/plugins/plugin_2pass2.c

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

revision 1202, Sun Nov 9 20:49:21 2003 UTC revision 1247, Mon Dec 8 12:38:04 2003 UTC
# Line 25  Line 25 
25   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
26   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27   *   *
28   * $Id: plugin_2pass2.c,v 1.1.2.24 2003-11-09 20:49:21 edgomez Exp $   * $Id: plugin_2pass2.c,v 1.1.2.30 2003-12-08 12:38:04 syskin Exp $
29   *   *
30   *****************************************************************************/   *****************************************************************************/
31    
# Line 51  Line 51 
51    
52  /* Keyframe settings */  /* Keyframe settings */
53  #define DEFAULT_KFREDUCTION 20  #define DEFAULT_KFREDUCTION 20
54  #define DEFAULT_MIN_KEY_INTERVAL 1  #define DEFAULT_KFTHRESHOLD 1
55    
56  /*****************************************************************************  /*****************************************************************************
57   * Structures   * Structures
# Line 220  Line 220 
220  {  {
221          switch(opt) {          switch(opt) {
222          case XVID_PLG_INFO :          case XVID_PLG_INFO :
223            case XVID_PLG_FRAME :
224                  return 0;                  return 0;
225    
226          case XVID_PLG_CREATE :          case XVID_PLG_CREATE :
# Line 281  Line 282 
282    
283          /* Keyframe settings */          /* Keyframe settings */
284          _INIT(rc->param.kfreduction, DEFAULT_KFREDUCTION);          _INIT(rc->param.kfreduction, DEFAULT_KFREDUCTION);
285          _INIT(rc->param.min_key_interval, DEFAULT_MIN_KEY_INTERVAL);          _INIT(rc->param.kfthreshold, DEFAULT_KFTHRESHOLD);
286  #undef _INIT  #undef _INIT
287    
288          /* Initialize some stuff to zero */          /* Initialize some stuff to zero */
# Line 332  Line 333 
333          /* Compute the target filesize */          /* Compute the target filesize */
334          if (rc->param.bitrate<0) {          if (rc->param.bitrate<0) {
335                  /* if negative, bitrate equals the target (in kbytes) */                  /* if negative, bitrate equals the target (in kbytes) */
336                  rc->target = (-rc->param.bitrate) * 1024;                  rc->target = ((uint64_t)(-rc->param.bitrate)) * 1024;
337          } else if (rc->num_frames  < create->fbase/create->fincr) {          } else if (rc->num_frames  < create->fbase/create->fincr) {
338                  /* Source sequence is less than 1s long, we do as if it was 1s long */                  /* Source sequence is less than 1s long, we do as if it was 1s long */
339                  rc->target = rc->param.bitrate / 8;                  rc->target = rc->param.bitrate / 8;
# Line 435  Line 436 
436          if (data->quant > 0)          if (data->quant > 0)
437                  return(0);                  return(0);
438    
439          /* Second case: We are in a Quant zone */          /* Second case: insufficent stats data */
440            if (data->frame_num >= rc->num_frames) {
441                    DPRINTF(XVID_DEBUG_RC,"[xvid rc] -- stats file too short (now processing frame %d)",
442                            data->frame_num);
443                    return(0);
444            }
445    
446            /* Third case: We are in a Quant zone */
447          if (s->zone_mode == XVID_ZONE_QUANT) {          if (s->zone_mode == XVID_ZONE_QUANT) {
448                  rc->fq_error += s->weight;                  rc->fq_error += s->weight;
449                  data->quant = (int)rc->fq_error;                  data->quant = (int)rc->fq_error;
# Line 446  Line 454 
454                  return(0);                  return(0);
455          }          }
456    
         /* Third case: insufficent stats data */  
         if (data->frame_num >= rc->num_frames)  
                 return(0);  
457    
458          /*************************************************************************/          /*************************************************************************/
459          /*************************************************************************/          /*************************************************************************/
# Line 466  Line 471 
471    
472          /* IFrame user settings*/          /* IFrame user settings*/
473          if (s->type == XVID_TYPE_IVOP) {          if (s->type == XVID_TYPE_IVOP) {
   
474                  /* Keyframe boosting -- All keyframes benefit from it */                  /* Keyframe boosting -- All keyframes benefit from it */
475                  dbytes += dbytes*rc->param.keyframe_boost / 100;                  dbytes += dbytes*rc->param.keyframe_boost / 100;
476    
477                  /* Applies keyframe penalties, but not the first frame */  #if 0 /* ToDo: decide how to apply kfthresholding */
478                  if (rc->KF_idx) {  #endif
                         int penalty_distance;  
   
                         /* Minimum keyframe distance penalties */  
                         penalty_distance  = rc->param.min_key_interval;  
                         penalty_distance -= rc->keyframe_locations[rc->KF_idx];  
                         penalty_distance += rc->keyframe_locations[rc->KF_idx-1];  
   
                         /* Ah ah ! guilty keyframe, you're under arrest ! */  
                         if (penalty_distance > 0)  
                                 dbytes -= dbytes*penalty_distance*rc->param.kfreduction/100;  
                 }  
479          } else {          } else {
480    
481                  /* P/S/B frames must reserve some bits for iframe boosting */                  /* P/S/B frames must reserve some bits for iframe boosting */
# Line 616  Line 609 
609                          b_ref--;                          b_ref--;
610    
611                  /* Compute the original quant */                  /* Compute the original quant */
612                  s->quant  = 100*s->quant - data->bquant_offset;                  s->quant  = 2*(100*s->quant - data->bquant_offset);
613                  s->quant += data->bquant_ratio - 1; /* to avoid rouding issues */                  s->quant += data->bquant_ratio - 1; /* to avoid rouding issues */
614                  s->quant  = s->quant/data->bquant_ratio - b_ref->quant;                  s->quant  = s->quant/data->bquant_ratio - b_ref->quant;
615          }          }
# Line 823  Line 816 
816    
817                  char *ptr;                  char *ptr;
818                  char type;                  char type;
819                  int fields, nouse;                  int fields;
820    
821                  lines++;                  lines++;
822    
823                  /* We skip spaces */                  /* We skip spaces */
824                  ptr = skipspaces(line);                  ptr = skipspaces(line);
825    
826                  /* Skip coment lines */                  /* Skip coment lines or empty lines */
827                  if(iscomment(ptr)) {                  if(iscomment(ptr) || *ptr == '\0') {
828                          free(line);                          free(line);
829                          continue;                          continue;
830                  }                  }
831    
832                  /* Read the stat line from buffer */                  /* Read the stat line from buffer */
833                  fields = sscanf(ptr,                  fields = sscanf(ptr, "%c", &type);
                                                 "%c %d %d %d %d %d",  
                                                 &type, &nouse, &nouse, &nouse, &nouse, &nouse);  
834    
835                  /* Valid stats files have at least 6 fields */                  /* Valid stats files have at least 6 fields */
836                  if (fields == 6) {                  if (fields == 1) {
837                          switch(type) {                          switch(type) {
838                          case 'i':                          case 'i':
839                          case 'I':                          case 'I':
# Line 901  Line 892 
892                  /* We skip spaces */                  /* We skip spaces */
893                  ptr = skipspaces(line);                  ptr = skipspaces(line);
894    
895                  /* Skip comment lines */                  /* Skip comment lines or empty lines */
896                  if(iscomment(ptr)) {                  if(iscomment(ptr) || *ptr == '\0') {
897                          free(line);                          free(line);
898                          continue;                          continue;
899                  }                  }
# Line 1192  Line 1183 
1183  scaled_curve_apply_advanced_parameters(rc_2pass2_t * rc)  scaled_curve_apply_advanced_parameters(rc_2pass2_t * rc)
1184  {  {
1185          int i;          int i;
1186          uint64_t ivop_boost_total;          int64_t ivop_boost_total;
1187    
1188          /* Reset the rate controller (per frame type) total byte counters */          /* Reset the rate controller (per frame type) total byte counters */
1189          for (i=0; i<3; i++) rc->tot_scaled_length[i] = 0;          for (i=0; i<3; i++) rc->tot_scaled_length[i] = 0;
# Line 1215  Line 1206 
1206    
1207                  /* Some more work is needed for I frames */                  /* Some more work is needed for I frames */
1208                  if (s->type == XVID_TYPE_IVOP) {                  if (s->type == XVID_TYPE_IVOP) {
                         int penalty_distance;  
1209                          int ivop_boost;                          int ivop_boost;
1210    
1211                          /* Accumulate bytes needed for keyframe boosting */                          /* Accumulate bytes needed for keyframe boosting */
1212                          ivop_boost = s->scaled_length*rc->param.keyframe_boost/100;                          ivop_boost = s->scaled_length*rc->param.keyframe_boost/100;
1213    
1214                          if (rc->KF_idx) {  #if 0 /* ToDo: decide how to apply kfthresholding */
1215                                  /* Minimum keyframe distance penalties */  #endif
                                 penalty_distance  = rc->param.min_key_interval;  
                                 penalty_distance -= rc->keyframe_locations[rc->KF_idx];  
                                 penalty_distance += rc->keyframe_locations[rc->KF_idx-1];  
   
                                 /* Ah ah ! guilty keyframe, you're under arrest ! */  
                                 if (penalty_distance > 0)  
                                          ivop_boost -= (s->scaled_length + ivop_boost)*penalty_distance*rc->param.kfreduction/100;  
                         }  
   
1216                          /* If the frame size drops under the minimum length, then cap ivop_boost */                          /* If the frame size drops under the minimum length, then cap ivop_boost */
1217                          if (ivop_boost + s->scaled_length < rc->min_length[XVID_TYPE_IVOP-1])                          if (ivop_boost + s->scaled_length < rc->min_length[XVID_TYPE_IVOP-1])
1218                                  ivop_boost = rc->min_length[XVID_TYPE_IVOP-1] - s->scaled_length;                                  ivop_boost = rc->min_length[XVID_TYPE_IVOP-1] - s->scaled_length;
# Line 1261  Line 1242 
1242    
1243          /* Compute the ratio described above          /* Compute the ratio described above
1244           *     taxed_total = sum(0, n, tax*scaled_length)           *     taxed_total = sum(0, n, tax*scaled_length)
1245           * <=> taxed_total = tax.sum(0, n, tax*scaled_length)           * <=> taxed_total = tax.sum(0, n, scaled_length)
1246           * <=> tax = taxed_total / original_total */           * <=> tax = taxed_total / original_total */
1247          rc->pb_iboost_tax_ratio =          rc->pb_iboost_tax_ratio =
1248                  (rc->pb_iboost_tax_ratio - ivop_boost_total) /                  (rc->pb_iboost_tax_ratio - ivop_boost_total) /
# Line 1278  Line 1259 
1259                  } else {                  } else {
1260                          rc->avg_length[i] = rc->tot_scaled_length[i];                          rc->avg_length[i] = rc->tot_scaled_length[i];
1261    
1262                          if (i == XVID_TYPE_IVOP) {                          if (i == (XVID_TYPE_IVOP-1)) {
1263                                  /* I Frames total has to be added the boost total */                                  /* I Frames total has to be added the boost total */
1264                                  rc->avg_length[i] += ivop_boost_total;                                  rc->avg_length[i] += ivop_boost_total;
1265                          } else {                          } else {

Legend:
Removed from v.1202  
changed lines
  Added in v.1247

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