[svn] / branches / dev-api-4 / xvidcore / vfw / src / 2pass.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/vfw/src/2pass.c

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

revision 1052, Mon Jun 2 11:47:30 2003 UTC revision 1053, Mon Jun 9 01:25:19 2003 UTC
# Line 113  Line 113 
113                  twopass->nns_array_pos = 0;                  twopass->nns_array_pos = 0;
114          twopass->nns_update_pos = 0;          twopass->nns_update_pos = 0;
115    
116                  // read the stats file(s) into array(s) and reorder them so they                  /* read the stats file(s) into array(s) and reorder them so they */
117                  // correctly represent the frames that the encoder will receive.                  /* correctly represent the frames that the encoder will receive. */
118                  if (codec->config.mode == DLG_MODE_2PASS_2_EXT)                  if (codec->config.mode == DLG_MODE_2PASS_2_EXT)
119                  {                  {
120                          if (twopass->stats2 != INVALID_HANDLE_VALUE)                          if (twopass->stats2 != INVALID_HANDLE_VALUE)
# Line 172  Line 172 
172                                          }                                          }
173                                  }                                  }
174    
175                                  // increase the allocated memory if necessary                                  /* increase the allocated memory if necessary */
176                                  if (frames >= twopass->nns_array_size)                                  if (frames >= twopass->nns_array_size)
177                                  {                                  {
178                                          twopass->nns1_array = (NNSTATS*)realloc(twopass->nns1_array,                                          twopass->nns1_array = (NNSTATS*)realloc(twopass->nns1_array,
# Line 182  Line 182 
182                                          twopass->nns_array_size = twopass->nns_array_size * 5 / 4 + 1;                                          twopass->nns_array_size = twopass->nns_array_size * 5 / 4 + 1;
183                                  }                                  }
184    
185                                  // copy this frame's stats into the arrays                                  /* copy this frame's stats into the arrays */
186                                  memcpy (&twopass->nns1_array[frames], &twopass->nns1, sizeof(NNSTATS));                                  memcpy (&twopass->nns1_array[frames], &twopass->nns1, sizeof(NNSTATS));
187                                  memcpy (&twopass->nns2_array[frames], &twopass->nns2, sizeof(NNSTATS));                                  memcpy (&twopass->nns2_array[frames], &twopass->nns2, sizeof(NNSTATS));
188                                  frames++;                                  frames++;
# Line 191  Line 191 
191                          SetFilePointer(twopass->stats1, sizeof(DWORD), 0, FILE_BEGIN);                          SetFilePointer(twopass->stats1, sizeof(DWORD), 0, FILE_BEGIN);
192                          SetFilePointer(twopass->stats2, sizeof(DWORD), 0, FILE_BEGIN);                          SetFilePointer(twopass->stats2, sizeof(DWORD), 0, FILE_BEGIN);
193                  }                  }
194                  else    // DLG_MODE_2PASS_2_INT                  else    /* DLG_MODE_2PASS_2_INT */
195                  {                  {
196                          while (1)                          while (1)
197                          {                          {
# Line 212  Line 212 
212                                          }                                          }
213                                  }                                  }
214    
215                                  // increase the allocated memory if necessary                                  /* increase the allocated memory if necessary */
216                                  if (frames >= twopass->nns_array_size)                                  if (frames >= twopass->nns_array_size)
217                                  {                                  {
218                                          twopass->nns1_array = (NNSTATS*)realloc(twopass->nns1_array,                                          twopass->nns1_array = (NNSTATS*)realloc(twopass->nns1_array,
# Line 220  Line 220 
220                                          twopass->nns_array_size = twopass->nns_array_size * 5 / 4 + 1;                                          twopass->nns_array_size = twopass->nns_array_size * 5 / 4 + 1;
221                                  }                                  }
222    
223                                  // copy this frame's stats into the array                                  /* copy this frame's stats into the array */
224                                  memcpy (&twopass->nns1_array[frames], &twopass->nns1, sizeof(NNSTATS));                                  memcpy (&twopass->nns1_array[frames], &twopass->nns1, sizeof(NNSTATS));
225                                  frames++;                                  frames++;
226                          }                          }
# Line 233  Line 233 
233                  twopass->nns_array_length = frames;                  twopass->nns_array_length = frames;
234                  frames = 0;                  frames = 0;
235    
236  /* // this isn't necessary with the current core.  /* /* this isn't necessary with the current core. */
237                  // reorder the array(s) so they are in the order that they were received                  /* reorder the array(s) so they are in the order that they were received */
238                  // IPBBPBB to                  /* IPBBPBB to */
239                  // IBBPBBP                  /* IBBPBBP */
240                  for (i=0; i<twopass->nns_array_length; i++)                  for (i=0; i<twopass->nns_array_length; i++)
241                  {                  {
242                          NNSTATS temp_nns, temp_nns2;                          NNSTATS temp_nns, temp_nns2;
# Line 271  Line 271 
271                          }                          }
272                  }                  }
273  */  */
274                  // continue with the initialization..                  /* continue with the initialization.. */
275                  if (codec->config.mode == DLG_MODE_2PASS_2_EXT)                  if (codec->config.mode == DLG_MODE_2PASS_2_EXT)
276                  {                  {
277                          while (1)                          while (1)
# Line 324  Line 324 
324    
325                                  if (twopass->nns1.quant & NNSTATS_KEYFRAME)                                  if (twopass->nns1.quant & NNSTATS_KEYFRAME)
326                                  {                                  {
327                                          // this test needs to be corrected..                                          /* this test needs to be corrected.. */
328                                          if (!(twopass->nns1.kblk + twopass->nns1.mblk))                                          if (!(twopass->nns1.kblk + twopass->nns1.mblk))
329                                                  recminisize = twopass->nns1.bytes;                                                  recminisize = twopass->nns1.bytes;
330                                  }                                  }
# Line 353  Line 353 
353                                  twopass->average_pframe = (double)pframe_total_ext / pframes / twopass->movie_curve;                                  twopass->average_pframe = (double)pframe_total_ext / pframes / twopass->movie_curve;
354                          else                          else
355                                  if (bframes)                                  if (bframes)
356                                          twopass->average_pframe = twopass->average_bframe;  // b-frame packed bitstream fix                                          twopass->average_pframe = twopass->average_bframe;  /* b-frame packed bitstream fix */
357                                  else                                  else
358                                  {                                  {
359                                          DEBUGERR("ERROR:  No p-frames or b-frames were present in the 1st pass.  Rate control cannot function properly!");                                          DEBUGERR("ERROR:  No p-frames or b-frames were present in the 1st pass.  Rate control cannot function properly!");
# Line 362  Line 362 
362    
363    
364    
365                          // perform prepass to compensate for over/undersizing                          /* perform prepass to compensate for over/undersizing */
366                          frames = 0;                          frames = 0;
367    
368                          if (codec->config.use_alt_curve)                          if (codec->config.use_alt_curve)
# Line 391  Line 391 
391                                  {                                  {
392                                          switch(codec->config.alt_curve_type)                                          switch(codec->config.alt_curve_type)
393                                          {                                          {
394                                          case 2: // Sine Curve (high aggressiveness)                                          case 2: /* Sine Curve (high aggressiveness) */
395                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +
396                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff)));                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff)));
397                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *
398                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff));                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff));
399                                                  break;                                                  break;
400                                          case 1: // Linear (medium aggressiveness)                                          case 1: /* Linear (medium aggressiveness) */
401                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +
402                                                          twopass->average_pframe / twopass->alt_curve_low_diff);                                                          twopass->average_pframe / twopass->alt_curve_low_diff);
403                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *
404                                                          twopass->average_pframe / twopass->alt_curve_low_diff;                                                          twopass->average_pframe / twopass->alt_curve_low_diff;
405                                                  break;                                                  break;
406                                          case 0: // Cosine Curve (low aggressiveness)                                          case 0: /* Cosine Curve (low aggressiveness) */
407                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +
408                                                          (1.0 - cos(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff))));                                                          (1.0 - cos(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff))));
409                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *
# Line 545  Line 545 
545                                  DEBUG2P(s);                                  DEBUG2P(s);
546                          }                          }
547                  }                  }
548                  else    // DLG_MODE_2PASS_2_INT                  else    /* DLG_MODE_2PASS_2_INT */
549                  {                  {
550                          while (1)                          while (1)
551                          {                          {
# Line 598  Line 598 
598    
599                                  if (twopass->nns1.quant & NNSTATS_KEYFRAME)                                  if (twopass->nns1.quant & NNSTATS_KEYFRAME)
600                                  {                                  {
601                                          // this test needs to be corrected..                                          /* this test needs to be corrected.. */
602                                          if (!(twopass->nns1.kblk + twopass->nns1.mblk))                                          if (!(twopass->nns1.kblk + twopass->nns1.mblk))
603                                                  recminisize = twopass->nns1.bytes;                                                  recminisize = twopass->nns1.bytes;
604                                  }                                  }
# Line 617  Line 617 
617                          }                          }
618                          twopass->keyframe_locations[i_frames] = frames;                          twopass->keyframe_locations[i_frames] = frames;
619    
620                          // compensate for avi frame overhead                          /* compensate for avi frame overhead */
621                          desired -= frames * 24;                          desired -= frames * 24;
622    
623                          switch (codec->config.credits_mode)                          switch (codec->config.credits_mode)
624                          {                          {
625                          case CREDITS_MODE_RATE :                          case CREDITS_MODE_RATE :
626    
627                                  // credits curve = (total / desired_size) * (100 / credits_rate)                                  /* credits curve = (total / desired_size) * (100 / credits_rate) */
628                                  twopass->credits_start_curve = twopass->credits_end_curve =                                  twopass->credits_start_curve = twopass->credits_end_curve =
629                                          ((double)(bframe_total + pframe_total + i_total + start + end) / desired) *                                          ((double)(bframe_total + pframe_total + i_total + start + end) / desired) *
630                                          ((double)100 / codec->config.credits_rate);                                          ((double)100 / codec->config.credits_rate);
# Line 632  Line 632 
632                                  start_curved = (__int64)(start / twopass->credits_start_curve);                                  start_curved = (__int64)(start / twopass->credits_start_curve);
633                                  end_curved = (__int64)(end / twopass->credits_end_curve);                                  end_curved = (__int64)(end / twopass->credits_end_curve);
634    
635                                  // movie curve = (total - credits) / (desired_size - curved credits)                                  /* movie curve = (total - credits) / (desired_size - curved credits) */
636                                  twopass->movie_curve = (double)                                  twopass->movie_curve = (double)
637                                          (bframe_total + pframe_total + i_total) /                                          (bframe_total + pframe_total + i_total) /
638                                          (desired - start_curved - end_curved);                                          (desired - start_curved - end_curved);
# Line 641  Line 641 
641    
642                          case CREDITS_MODE_QUANT :                          case CREDITS_MODE_QUANT :
643    
644                                  // movie curve = (total - credits) / (desired_size - credits)                                  /* movie curve = (total - credits) / (desired_size - credits) */
645                                  twopass->movie_curve = (double)                                  twopass->movie_curve = (double)
646                                          (bframe_total + pframe_total + i_total) / (desired - start - end);                                          (bframe_total + pframe_total + i_total) / (desired - start - end);
647    
648                                  // aid the average asymmetric frame calculation below                                  /* aid the average asymmetric frame calculation below */
649                                  start_curved = start;                                  start_curved = start;
650                                  end_curved = end;                                  end_curved = end;
651    
# Line 653  Line 653 
653    
654                          case CREDITS_MODE_SIZE :                          case CREDITS_MODE_SIZE :
655    
656                                  // start curve = (start / start desired size)                                  /* start curve = (start / start desired size) */
657                                  twopass->credits_start_curve = (double)                                  twopass->credits_start_curve = (double)
658                                          (start / 1024) / codec->config.credits_start_size;                                          (start / 1024) / codec->config.credits_start_size;
659    
660                                  // end curve = (end / end desired size)                                  /* end curve = (end / end desired size) */
661                                  twopass->credits_end_curve = (double)                                  twopass->credits_end_curve = (double)
662                                          (end / 1024) / codec->config.credits_end_size;                                          (end / 1024) / codec->config.credits_end_size;
663    
664                                  start_curved = (__int64)(start / twopass->credits_start_curve);                                  start_curved = (__int64)(start / twopass->credits_start_curve);
665                                  end_curved = (__int64)(end / twopass->credits_end_curve);                                  end_curved = (__int64)(end / twopass->credits_end_curve);
666    
667                                  // movie curve = (total - credits) / (desired_size - curved credits)                                  /* movie curve = (total - credits) / (desired_size - curved credits) */
668                                  twopass->movie_curve = (double)                                  twopass->movie_curve = (double)
669                                          (bframe_total + pframe_total + i_total) /                                          (bframe_total + pframe_total + i_total) /
670                                          (desired - start_curved - end_curved);                                          (desired - start_curved - end_curved);
# Line 679  Line 679 
679                                  twopass->average_pframe = (double)pframe_total / pframes / twopass->movie_curve;                                  twopass->average_pframe = (double)pframe_total / pframes / twopass->movie_curve;
680                          else                          else
681                                  if (bframes)                                  if (bframes)
682                                          twopass->average_pframe = twopass->average_bframe;  // b-frame packed bitstream fix                                          twopass->average_pframe = twopass->average_bframe;  /* b-frame packed bitstream fix */
683                                  else                                  else
684                                  {                                  {
685                                          DEBUGERR("ERROR:  No p-frames or b-frames were present in the 1st pass.  Rate control cannot function properly!");                                          DEBUGERR("ERROR:  No p-frames or b-frames were present in the 1st pass.  Rate control cannot function properly!");
# Line 688  Line 688 
688    
689    
690    
691                          // perform prepass to compensate for over/undersizing                          /* perform prepass to compensate for over/undersizing */
692                          frames = 0;                          frames = 0;
693    
694                          if (codec->config.use_alt_curve)                          if (codec->config.use_alt_curve)
# Line 714  Line 714 
714                                  {                                  {
715                                          switch(codec->config.alt_curve_type)                                          switch(codec->config.alt_curve_type)
716                                          {                                          {
717                                          case 2: // Sine Curve (high aggressiveness)                                          case 2: /* Sine Curve (high aggressiveness) */
718                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +
719                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff)));                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff)));
720                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *
721                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff));                                                          sin(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff));
722                                                  break;                                                  break;
723                                          case 1: // Linear (medium aggressiveness)                                          case 1: /* Linear (medium aggressiveness) */
724                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +
725                                                          twopass->average_pframe / twopass->alt_curve_low_diff);                                                          twopass->average_pframe / twopass->alt_curve_low_diff);
726                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *
727                                                          twopass->average_pframe / twopass->alt_curve_low_diff;                                                          twopass->average_pframe / twopass->alt_curve_low_diff;
728                                                  break;                                                  break;
729                                          case 0: // Cosine Curve (low aggressiveness)                                          case 0: /* Cosine Curve (low aggressiveness) */
730                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +                                                  twopass->alt_curve_qual_dev *= 2.0 / (1.0 +
731                                                          (1.0 - cos(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff))));                                                          (1.0 - cos(DEG2RAD * (twopass->average_pframe * 90.0 / twopass->alt_curve_low_diff))));
732                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *                                                  twopass->alt_curve_mid_qual = 1.0 - twopass->alt_curve_qual_dev *
# Line 877  Line 877 
877                          twopass->curve_comp_scale = ((total1 - total2) * (1.0 - (double)codec->config.alt_curve_bonus_bias / 100.0) + total2) / total2;                          twopass->curve_comp_scale = ((total1 - total2) * (1.0 - (double)codec->config.alt_curve_bonus_bias / 100.0) + total2) / total2;
878    
879    
880                          // special info for alt curve:  bias bonus and quantizer thresholds,                          /* special info for alt curve:  bias bonus and quantizer thresholds,  */
881                          {                          {
882                                  double curve_temp, dbytes;                                  double curve_temp, dbytes;
883                                  char s[100];                                  char s[100];
# Line 1002  Line 1002 
1002    
1003          if (twopass->nns_array_pos >= twopass->nns_array_length)          if (twopass->nns_array_pos >= twopass->nns_array_length)
1004          {          {
1005                  // fix for VirtualDub 1.4.13 bframe handling                  /* fix for VirtualDub 1.4.13 bframe handling */
1006                  if (codec->config.max_bframes > 0 &&                  if (codec->config.max_bframes > 0 &&
1007                          codec->framenum < twopass->nns_array_length + codec->config.max_bframes)                          codec->framenum < twopass->nns_array_length + codec->config.max_bframes)
1008                  {                  {
# Line 1082  Line 1082 
1082                                  {                                  {
1083                                          bytes2 = (int)(bytes1 / twopass->credits_start_curve);                                          bytes2 = (int)(bytes1 / twopass->credits_start_curve);
1084                                  }                                  }
1085                                  else // CREDITS_END                                  else /* CREDITS_END */
1086                                  {                                  {
1087                                          bytes2 = (int)(bytes1 / twopass->credits_end_curve);                                          bytes2 = (int)(bytes1 / twopass->credits_end_curve);
1088                                  }                                  }
# Line 1109  Line 1109 
1109                                  return ICERR_OK;                                  return ICERR_OK;
1110                          }                          }
1111                  }                  }
1112                  else    // DLG_MODE_2PASS_2_EXT                  else    /* DLG_MODE_2PASS_2_EXT */
1113                  {                  {
1114                          if (codec->config.credits_mode == CREDITS_MODE_QUANT)                          if (codec->config.credits_mode == CREDITS_MODE_QUANT)
1115                          {                          {
# Line 1134  Line 1134 
1134                                  bytes2 = twopass->nns2.bytes;                                  bytes2 = twopass->nns2.bytes;
1135                  }                  }
1136          }          }
1137          else    // Foxer: apply curve compression outside credits          else    /* Foxer: apply curve compression outside credits */
1138          {          {
1139                  double dbytes, curve_temp;                  double dbytes, curve_temp;
1140    
# Line 1153  Line 1153 
1153                  if (twopass->nns1.dd_v & NNSTATS_BFRAME)                  if (twopass->nns1.dd_v & NNSTATS_BFRAME)
1154                          dbytes *= twopass->average_pframe / twopass->average_bframe;                          dbytes *= twopass->average_pframe / twopass->average_bframe;
1155    
1156                  // spread the compression error across payback_delay frames                  /* spread the compression error across payback_delay frames */
1157                  if (codec->config.bitrate_payback_method == 0)                  if (codec->config.bitrate_payback_method == 0)
1158                  {                  {
1159                          bytes2 = (int)(curve_comp_error / codec->config.bitrate_payback_delay);                          bytes2 = (int)(curve_comp_error / codec->config.bitrate_payback_delay);
# Line 1267  Line 1267 
1267                          curve_comp_error += dbytes - ((int)dbytes);                          curve_comp_error += dbytes - ((int)dbytes);
1268                  }                  }
1269    
1270                  // cap bytes2 to first pass size, lowers number of quant=1 frames                  /* cap bytes2 to first pass size, lowers number of quant=1 frames */
1271                  if (bytes2 > bytes1)                  if (bytes2 > bytes1)
1272                  {                  {
1273                          curve_comp_error += bytes2 - bytes1;                          curve_comp_error += bytes2 - bytes1;
# Line 1388  Line 1388 
1388          }          }
1389          else if (frame->type != XVID_TYPE_IVOP)          else if (frame->type != XVID_TYPE_IVOP)
1390          {          {
1391                  // Foxer: aid desired quantizer precision by accumulating decision error                  /* Foxer: aid desired quantizer precision by accumulating decision error */
1392                  if (twopass->nns1.dd_v & NNSTATS_BFRAME)                  if (twopass->nns1.dd_v & NNSTATS_BFRAME)
1393                  {                  {
1394                          bquant_error[frame->quant] += ((double)((twopass->nns1.quant & ~NNSTATS_KEYFRAME) *                          bquant_error[frame->quant] += ((double)((twopass->nns1.quant & ~NNSTATS_KEYFRAME) *
# Line 1443  Line 1443 
1443                          frame->quant = codec->config.min_pquant;                          frame->quant = codec->config.min_pquant;
1444                  }                  }
1445    
1446                  // subsequent frame quants can only be +- 2                  /* subsequent frame quants can only be +- 2 */
1447                  if ((last_pquant || last_bquant) && capped_to_max_framesize == 0)                  if ((last_pquant || last_bquant) && capped_to_max_framesize == 0)
1448                  {                  {
1449                          if (twopass->nns1.dd_v & NNSTATS_BFRAME)                          if (twopass->nns1.dd_v & NNSTATS_BFRAME)
1450                          {                          {
1451                                  // this bframe quantizer variation                                  /* this bframe quantizer variation */
1452                                  // restriction needs to be redone.                                  /* restriction needs to be redone. */
1453                                  if (frame->quant > last_bquant + 2)                                  if (frame->quant > last_bquant + 2)
1454                                  {                                  {
1455                                          frame->quant = last_bquant + 2;                                          frame->quant = last_bquant + 2;
# Line 1535  Line 1535 
1535          switch (codec->config.mode)          switch (codec->config.mode)
1536          {          {
1537          case DLG_MODE_2PASS_1 :          case DLG_MODE_2PASS_1 :
1538                  nns1.bytes = stats->length;     // total bytes                  nns1.bytes = stats->length;     /* total bytes */
1539                  nns1.dd_v = 0;                  nns1.dd_v = 0;
1540                  nns1.dd_u = nns1.dd_y = 0;                  nns1.dd_u = nns1.dd_y = 0;
1541                  nns1.dk_v = nns1.dk_u = nns1.dk_y = 0;                  nns1.dk_v = nns1.dk_u = nns1.dk_y = 0;
# Line 1543  Line 1543 
1543                  nns1.mk_u = nns1.mk_y = 0;                  nns1.mk_u = nns1.mk_y = 0;
1544    
1545  //              nns1.quant = stats->quant;  //              nns1.quant = stats->quant;
1546                  nns1.quant = 2;                         // ugly fix for lumi masking in 1st pass returning new quant                  nns1.quant = 2;                         /* ugly fix for lumi masking in 1st pass returning new quant */
1547                  nns1.lum_noise[0] = nns1.lum_noise[1] = 1;                  nns1.lum_noise[0] = nns1.lum_noise[1] = 1;
1548    
1549                  switch(stats->type)                  switch(stats->type)
# Line 1582  Line 1582 
1582                          if (!credits_pos)                          if (!credits_pos)
1583                          {                          {
1584                                  codec->twopass.quant_count[stats->quant]++;                                  codec->twopass.quant_count[stats->quant]++;
1585                                  //if ((codec->twopass.nns1.quant & NNSTATS_KEYFRAME))                                  /* if ((codec->twopass.nns1.quant & NNSTATS_KEYFRAME)) */
1586                  if ((codec->twopass.nns1_array[codec->twopass.nns_update_pos].quant & NNSTATS_KEYFRAME))                  if ((codec->twopass.nns1_array[codec->twopass.nns_update_pos].quant & NNSTATS_KEYFRAME))
1587                                  {                                  {
1588                                          // calculate how much to distribute per frame in                                          /* calculate how much to distribute per frame in */
1589                                          // order to make up for this keyframe's overflow                                          /* order to make up for this keyframe's overflow */
1590    
1591                                          codec->twopass.overflow += codec->twopass.KFoverflow;                                          codec->twopass.overflow += codec->twopass.KFoverflow;
1592                                          //codec->twopass.KFoverflow = codec->twopass.desired_bytes2 - frame->length;                                          /* codec->twopass.KFoverflow = codec->twopass.desired_bytes2 - frame->length; */
1593                      // XXX: very ugly hack for bframs; this affects twopass quality                      /* XXX: very ugly hack for bframs; this affects twopass quality */
1594                      codec->twopass.KFoverflow = codec->twopass.nns2_array[codec->twopass.nns_update_pos].bytes/*codec->twopass.desired_bytes2*/ - stats->length;                      codec->twopass.KFoverflow = codec->twopass.nns2_array[codec->twopass.nns_update_pos].bytes/*codec->twopass.desired_bytes2*/ - stats->length;
1595    
1596                                          tempdiv = (codec->twopass.keyframe_locations[codec->twopass.KF_idx] -                                          tempdiv = (codec->twopass.keyframe_locations[codec->twopass.KF_idx] -
# Line 1598  Line 1598 
1598    
1599                                          if (tempdiv > 1)                                          if (tempdiv > 1)
1600                                          {                                          {
1601                                                  // non-consecutive keyframes                                                  /* non-consecutive keyframes */
1602                                                  codec->twopass.KFoverflow_partial = codec->twopass.KFoverflow / (tempdiv - 1);                                                  codec->twopass.KFoverflow_partial = codec->twopass.KFoverflow / (tempdiv - 1);
1603                                          }                                          }
1604                                          else                                          else
1605                                          {                                          {
1606                                                  // consecutive keyframes                                                  /* consecutive keyframes */
1607                                                  codec->twopass.overflow += codec->twopass.KFoverflow;                                                  codec->twopass.overflow += codec->twopass.KFoverflow;
1608                                                  codec->twopass.KFoverflow = 0;                                                  codec->twopass.KFoverflow = 0;
1609                                                  codec->twopass.KFoverflow_partial = 0;                                                  codec->twopass.KFoverflow_partial = 0;
# Line 1612  Line 1612 
1612                                  }                                  }
1613                                  else                                  else
1614                                  {                                  {
1615                                          // distribute part of the keyframe overflow                                          /* distribute part of the keyframe overflow */
1616    
1617                                          //codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length +                                          /* codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length + */
1618                                          //      codec->twopass.KFoverflow_partial;                                          /* codec->twopass.KFoverflow_partial; */
1619                                  codec->twopass.overflow += codec->twopass.nns2_array[codec->twopass.nns_update_pos].bytes/*codec->twopass.desired_bytes2*/ - stats->length +                                  codec->twopass.overflow += codec->twopass.nns2_array[codec->twopass.nns_update_pos].bytes/*codec->twopass.desired_bytes2*/ - stats->length +
1620                                          codec->twopass.KFoverflow_partial;                                          codec->twopass.KFoverflow_partial;
1621                                          codec->twopass.KFoverflow -= codec->twopass.KFoverflow_partial;                                          codec->twopass.KFoverflow -= codec->twopass.KFoverflow_partial;
# Line 1623  Line 1623 
1623                          }                          }
1624                          else                          else
1625                          {                          {
1626                                  //codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length;                                  /* codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length; */
1627                  codec->twopass.overflow += codec->twopass.nns2_array[codec->twopass.nns_update_pos].bytes/*codec->twopass.desired_bytes2*/ - stats->length;                  codec->twopass.overflow += codec->twopass.nns2_array[codec->twopass.nns_update_pos].bytes/*codec->twopass.desired_bytes2*/ - stats->length;
1628    
1629                                  // ugly fix for credits..                                  /* ugly fix for credits.. */
1630                                  codec->twopass.overflow += codec->twopass.KFoverflow;                                  codec->twopass.overflow += codec->twopass.KFoverflow;
1631                                  codec->twopass.KFoverflow = 0;                                  codec->twopass.KFoverflow = 0;
1632                                  codec->twopass.KFoverflow_partial = 0;                                  codec->twopass.KFoverflow_partial = 0;
1633                                  // end of ugly fix.                                  /* end of ugly fix. */
1634                          }                          }
1635    
1636          /* XXX: remove          /* XXX: remove
# Line 1664  Line 1664 
1664                  }                  }
1665          */          */
1666    
1667                  //DEBUG2ND(frame->quant, quant_type, frame_type, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos)                  /* DEBUG2ND(frame->quant, quant_type, frame_type, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos) */
1668                  wsprintf(tmp, "[%i] 2nd-pass: quant:%d %s %s stats1:%d scaled:%d actual:%d overflow:%d %s",                  wsprintf(tmp, "[%i] 2nd-pass: quant:%d %s %s stats1:%d scaled:%d actual:%d overflow:%d %s",
1669                          codec->twopass.nns_update_pos,                          codec->twopass.nns_update_pos,
1670                          stats->quant,                          stats->quant,
# Line 1708  Line 1708 
1708    
1709          if (codec->config.mode == DLG_MODE_2PASS_2_EXT || codec->config.mode == DLG_MODE_2PASS_2_INT)          if (codec->config.mode == DLG_MODE_2PASS_2_EXT || codec->config.mode == DLG_MODE_2PASS_2_INT)
1710          {          {
1711                  // output the quantizer distribution for this encode.                  /* output the quantizer distribution for this encode. */
1712    
1713                  OutputDebugString("Quantizer distribution for 2nd pass:");                  OutputDebugString("Quantizer distribution for 2nd pass:");
1714                  for (i=1; i<=31; i++)                  for (i=1; i<=31; i++)

Legend:
Removed from v.1052  
changed lines
  Added in v.1053

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