[svn] / trunk / vfw / src / 2pass.c Repository:
ViewVC logotype

Diff of /trunk/vfw/src/2pass.c

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

revision 102, Fri Apr 5 14:42:37 2002 UTC revision 342, Fri Jul 26 19:58:22 2002 UTC
# Line 23  Line 23 
23   *   *
24   *      History:   *      History:
25   *   *
26     *      17.04.2002      changed 1st pass quant to always be 2 (2pass_update())
27     *      07.04.2002      added max bitrate constraint, overflow controls (foxer)
28   *      31.03.2002      inital version;   *      31.03.2002      inital version;
29   *   *
30   *************************************************************************/   *************************************************************************/
# Line 161  Line 163 
163                                          {                                          {
164                                                  i_boost_total = twopass->nns2.bytes * codec->config.keyframe_boost / 100;                                                  i_boost_total = twopass->nns2.bytes * codec->config.keyframe_boost / 100;
165                                                  i_total += twopass->nns2.bytes;                                                  i_total += twopass->nns2.bytes;
166                                                    twopass->keyframe_locations[i_frames] = frames;
167                                                  ++i_frames;                                                  ++i_frames;
168                                          }                                          }
169    
# Line 172  Line 175 
175    
176                                  ++frames;                                  ++frames;
177                          }                          }
178                            twopass->keyframe_locations[i_frames] = frames;
179    
180                          twopass->movie_curve = ((double)(total_ext + i_boost_total) / total_ext);                          twopass->movie_curve = ((double)(total_ext + i_boost_total) / total_ext);
181                          twopass->average_frame = ((double)(total_ext - i_total) / (frames - credits_frames - i_frames) / twopass->movie_curve);                          twopass->average_frame = ((double)(total_ext - i_total) / (frames - credits_frames - i_frames) / twopass->movie_curve);
# Line 369  Line 373 
373                                  {                                  {
374                                          i_total += twopass->nns1.bytes + twopass->nns1.bytes * codec->config.keyframe_boost / 100;                                          i_total += twopass->nns1.bytes + twopass->nns1.bytes * codec->config.keyframe_boost / 100;
375                                          total += twopass->nns1.bytes * codec->config.keyframe_boost / 100;                                          total += twopass->nns1.bytes * codec->config.keyframe_boost / 100;
376                                            twopass->keyframe_locations[i_frames] = frames;
377                                          ++i_frames;                                          ++i_frames;
378                                  }                                  }
379    
# Line 376  Line 381 
381    
382                                  ++frames;                                  ++frames;
383                          }                          }
384                            twopass->keyframe_locations[i_frames] = frames;
385    
386                          // compensate for avi frame overhead                          // compensate for avi frame overhead
387                          desired -= frames * 24;                          desired -= frames * 24;
# Line 680  Line 686 
686                  }                  }
687    
688                  twopass->overflow = 0;                  twopass->overflow = 0;
689                    twopass->KFoverflow = 0;
690                    twopass->KFoverflow_partial = 0;
691                    twopass->KF_idx = 1;
692    
693                  break;                  break;
694          }          }
# Line 700  Line 709 
709          int bytes1, bytes2;          int bytes1, bytes2;
710          int overflow;          int overflow;
711          int credits_pos;          int credits_pos;
712            int capped_to_max_framesize = 0;
713    
714          if (codec->framenum == 0)          if (codec->framenum == 0)
715          {          {
# Line 708  Line 718 
718                  for (i=0 ; i<32 ; ++i)                  for (i=0 ; i<32 ; ++i)
719                  {                  {
720                          quant_error[i] = 0.0;                          quant_error[i] = 0.0;
721                            twopass->quant_count[i] = 0;
722                  }                  }
723    
724                  curve_comp_error = 0.0;                  curve_comp_error = 0.0;
# Line 929  Line 940 
940          }          }
941    
942          // Foxer: make sure overflow doesn't run away          // Foxer: make sure overflow doesn't run away
943          if (overflow > bytes2 * 6 / 10)          if (overflow > bytes2 * codec->config.twopass_max_overflow_improvement / 100)
944          {          {
945                  bytes2 += (overflow <= bytes2) ? bytes2 * 6 / 10 : overflow * 6 / 10;                  bytes2 += (overflow <= bytes2) ? bytes2 * codec->config.twopass_max_overflow_improvement / 100 :
946                            overflow * codec->config.twopass_max_overflow_improvement / 100;
947          }          }
948          else if (overflow < bytes2 * -6 / 10)          else if (overflow < bytes2 * codec->config.twopass_max_overflow_degradation / -100)
949          {          {
950                  bytes2 += bytes2 * -6 / 10;                  bytes2 += bytes2 * codec->config.twopass_max_overflow_degradation / -100;
951          }          }
952          else          else
953          {          {
954                  bytes2 += overflow;                  bytes2 += overflow;
955          }          }
956    
957            if (bytes2 > twopass->max_framesize)
958            {
959                    capped_to_max_framesize = 1;
960                    bytes2 = twopass->max_framesize;
961            }
962    
963          if (bytes2 < 1)          if (bytes2 < 1)
964          {          {
965                  bytes2 = 1;                  bytes2 = 1;
# Line 1005  Line 1023 
1023                  }                  }
1024    
1025                  // subsequent frame quants can only be +- 2                  // subsequent frame quants can only be +- 2
1026                  if (last_quant)                  if (last_quant && capped_to_max_framesize == 0)
1027                  {                  {
1028                          if (frame->quant > last_quant + 2)                          if (frame->quant > last_quant + 2)
1029                          {                          {
# Line 1020  Line 1038 
1038                  }                  }
1039          }          }
1040    
1041            if (capped_to_max_framesize == 0)
1042          last_quant = frame->quant;          last_quant = frame->quant;
1043    
1044          if (codec->config.quant_type == QUANT_MODE_MOD)          if (codec->config.quant_type == QUANT_MODE_MOD)
# Line 1038  Line 1057 
1057    
1058          NNSTATS nns1;          NNSTATS nns1;
1059          DWORD wrote;          DWORD wrote;
1060            int credits_pos, tempdiv;
1061          char* quant_type;          char* quant_type;
1062    
1063          if (codec->framenum == 0)          if (codec->framenum == 0)
# Line 1060  Line 1080 
1080                  nns1.md_u = nns1.md_y = 0;                  nns1.md_u = nns1.md_y = 0;
1081                  nns1.mk_u = nns1.mk_y = 0;                  nns1.mk_u = nns1.mk_y = 0;
1082    
1083                  nns1.quant = stats->quant;  //              nns1.quant = stats->quant;
1084                    nns1.quant = 2;                         // ugly fix for lumi masking in 1st pass returning new quant
1085                  if (frame->intra)                  if (frame->intra)
1086                  {                  {
1087                          nns1.quant |= NNSTATS_KEYFRAME;                          nns1.quant |= NNSTATS_KEYFRAME;
# Line 1083  Line 1104 
1104    
1105          case DLG_MODE_2PASS_2_INT :          case DLG_MODE_2PASS_2_INT :
1106          case DLG_MODE_2PASS_2_EXT :          case DLG_MODE_2PASS_2_EXT :
1107                    credits_pos = codec_is_in_credits(&codec->config, codec->framenum);
1108                    if (!credits_pos)
1109                    {
1110                            codec->twopass.quant_count[frame->quant]++;
1111                            if ((codec->twopass.nns1.quant & NNSTATS_KEYFRAME))
1112                            {
1113                                    codec->twopass.overflow += codec->twopass.KFoverflow;
1114                                    codec->twopass.KFoverflow = codec->twopass.desired_bytes2 - frame->length;
1115    
1116                                    tempdiv = (codec->twopass.keyframe_locations[codec->twopass.KF_idx] -
1117                                            codec->twopass.keyframe_locations[codec->twopass.KF_idx - 1]);
1118    
1119                                    if (tempdiv > 1)
1120                                    {
1121                                            // non-consecutive keyframes
1122                                            codec->twopass.KFoverflow_partial = codec->twopass.KFoverflow / (tempdiv - 1);
1123                                    }
1124                                    else
1125                                    {
1126                                            // consecutive keyframes
1127                                            codec->twopass.overflow += codec->twopass.KFoverflow;
1128                                            codec->twopass.KFoverflow = 0;
1129                                            codec->twopass.KFoverflow_partial = 0;
1130                                    }
1131                                    codec->twopass.KF_idx++;
1132                            }
1133                            else
1134                            {
1135                                    codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length +
1136                                            codec->twopass.KFoverflow_partial;
1137                                    codec->twopass.KFoverflow -= codec->twopass.KFoverflow_partial;
1138                            }
1139                    }
1140                    else
1141                    {
1142                  codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length;                  codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length;
1143                  DEBUG2ND(frame->quant, quant_type, frame->intra, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, codec_is_in_credits(&codec->config, codec->framenum))  
1144                            // ugly fix for credits..
1145                            codec->twopass.overflow += codec->twopass.KFoverflow;
1146                            codec->twopass.KFoverflow = 0;
1147                            codec->twopass.KFoverflow_partial = 0;
1148                            // end of ugly fix.
1149                    }
1150    
1151                    DEBUG2ND(frame->quant, quant_type, frame->intra, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos)
1152                  break;                  break;
1153    
1154          default:          default:
# Line 1094  Line 1158 
1158          return ICERR_OK;          return ICERR_OK;
1159  }  }
1160    
1161    void codec_2pass_finish(CODEC* codec)
1162    {
1163            int i;
1164            char s[100];
1165            if (codec->config.mode == DLG_MODE_2PASS_2_EXT || codec->config.mode == DLG_MODE_2PASS_2_INT)
1166            {
1167                    // output the quantizer distribution for this encode.
1168    
1169                    OutputDebugString("Quantizer distribution for 2nd pass:");
1170                    for (i=1; i<=31; i++)
1171                    {
1172                            if (codec->twopass.quant_count[i])
1173                            {
1174                                    wsprintf(s, "Q:%i:%i", i, codec->twopass.quant_count[i]);
1175                                    OutputDebugString(s);
1176                            }
1177                    }
1178                    return;
1179            }
1180    }

Legend:
Removed from v.102  
changed lines
  Added in v.342

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