[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 1242, Fri Dec 5 14:44:35 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.28 2003-12-05 14:44:35 edgomez 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 466  Line 467 
467    
468          /* IFrame user settings*/          /* IFrame user settings*/
469          if (s->type == XVID_TYPE_IVOP) {          if (s->type == XVID_TYPE_IVOP) {
   
470                  /* Keyframe boosting -- All keyframes benefit from it */                  /* Keyframe boosting -- All keyframes benefit from it */
471                  dbytes += dbytes*rc->param.keyframe_boost / 100;                  dbytes += dbytes*rc->param.keyframe_boost / 100;
472    
473                  /* Applies keyframe penalties, but not the first frame */  #if 0 /* ToDo: decide how to apply kfthresholding */
474                  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;  
                 }  
475          } else {          } else {
476    
477                  /* 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 605 
605                          b_ref--;                          b_ref--;
606    
607                  /* Compute the original quant */                  /* Compute the original quant */
608                  s->quant  = 100*s->quant - data->bquant_offset;                  s->quant  = 2*(100*s->quant - data->bquant_offset);
609                  s->quant += data->bquant_ratio - 1; /* to avoid rouding issues */                  s->quant += data->bquant_ratio - 1; /* to avoid rouding issues */
610                  s->quant  = s->quant/data->bquant_ratio - b_ref->quant;                  s->quant  = s->quant/data->bquant_ratio - b_ref->quant;
611          }          }
# Line 823  Line 812 
812    
813                  char *ptr;                  char *ptr;
814                  char type;                  char type;
815                  int fields, nouse;                  int fields;
816    
817                  lines++;                  lines++;
818    
819                  /* We skip spaces */                  /* We skip spaces */
820                  ptr = skipspaces(line);                  ptr = skipspaces(line);
821    
822                  /* Skip coment lines */                  /* Skip coment lines or empty lines */
823                  if(iscomment(ptr)) {                  if(iscomment(ptr) || *ptr == '\0') {
824                          free(line);                          free(line);
825                          continue;                          continue;
826                  }                  }
827    
828                  /* Read the stat line from buffer */                  /* Read the stat line from buffer */
829                  fields = sscanf(ptr,                  fields = sscanf(ptr, "%c", &type);
                                                 "%c %d %d %d %d %d",  
                                                 &type, &nouse, &nouse, &nouse, &nouse, &nouse);  
830    
831                  /* Valid stats files have at least 6 fields */                  /* Valid stats files have at least 6 fields */
832                  if (fields == 6) {                  if (fields == 1) {
833                          switch(type) {                          switch(type) {
834                          case 'i':                          case 'i':
835                          case 'I':                          case 'I':
# Line 901  Line 888 
888                  /* We skip spaces */                  /* We skip spaces */
889                  ptr = skipspaces(line);                  ptr = skipspaces(line);
890    
891                  /* Skip comment lines */                  /* Skip comment lines or empty lines */
892                  if(iscomment(ptr)) {                  if(iscomment(ptr) || *ptr == '\0') {
893                          free(line);                          free(line);
894                          continue;                          continue;
895                  }                  }
# Line 1192  Line 1179 
1179  scaled_curve_apply_advanced_parameters(rc_2pass2_t * rc)  scaled_curve_apply_advanced_parameters(rc_2pass2_t * rc)
1180  {  {
1181          int i;          int i;
1182          uint64_t ivop_boost_total;          int64_t ivop_boost_total;
1183    
1184          /* Reset the rate controller (per frame type) total byte counters */          /* Reset the rate controller (per frame type) total byte counters */
1185          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 1202 
1202    
1203                  /* Some more work is needed for I frames */                  /* Some more work is needed for I frames */
1204                  if (s->type == XVID_TYPE_IVOP) {                  if (s->type == XVID_TYPE_IVOP) {
                         int penalty_distance;  
1205                          int ivop_boost;                          int ivop_boost;
1206    
1207                          /* Accumulate bytes needed for keyframe boosting */                          /* Accumulate bytes needed for keyframe boosting */
1208                          ivop_boost = s->scaled_length*rc->param.keyframe_boost/100;                          ivop_boost = s->scaled_length*rc->param.keyframe_boost/100;
1209    
1210                          if (rc->KF_idx) {  #if 0 /* ToDo: decide how to apply kfthresholding */
1211                                  /* 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;  
                         }  
   
1212                          /* 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 */
1213                          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])
1214                                  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 1238 
1238    
1239          /* Compute the ratio described above          /* Compute the ratio described above
1240           *     taxed_total = sum(0, n, tax*scaled_length)           *     taxed_total = sum(0, n, tax*scaled_length)
1241           * <=> taxed_total = tax.sum(0, n, tax*scaled_length)           * <=> taxed_total = tax.sum(0, n, scaled_length)
1242           * <=> tax = taxed_total / original_total */           * <=> tax = taxed_total / original_total */
1243          rc->pb_iboost_tax_ratio =          rc->pb_iboost_tax_ratio =
1244                  (rc->pb_iboost_tax_ratio - ivop_boost_total) /                  (rc->pb_iboost_tax_ratio - ivop_boost_total) /
# Line 1278  Line 1255 
1255                  } else {                  } else {
1256                          rc->avg_length[i] = rc->tot_scaled_length[i];                          rc->avg_length[i] = rc->tot_scaled_length[i];
1257    
1258                          if (i == XVID_TYPE_IVOP) {                          if (i == (XVID_TYPE_IVOP-1)) {
1259                                  /* I Frames total has to be added the boost total */                                  /* I Frames total has to be added the boost total */
1260                                  rc->avg_length[i] += ivop_boost_total;                                  rc->avg_length[i] += ivop_boost_total;
1261                          } else {                          } else {

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

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