--- trunk/vfw/src/2pass.c 2002/04/05 14:42:37 102 +++ trunk/vfw/src/2pass.c 2002/04/08 12:51:41 109 @@ -23,6 +23,7 @@ * * History: * + * 07.04.2002 added max bitrate constraint, overflow controls (foxer) * 31.03.2002 inital version; * *************************************************************************/ @@ -700,6 +701,7 @@ int bytes1, bytes2; int overflow; int credits_pos; + int capped_to_max_framesize = 0; if (codec->framenum == 0) { @@ -708,6 +710,7 @@ for (i=0 ; i<32 ; ++i) { quant_error[i] = 0.0; + twopass->quant_count[i] = 0; } curve_comp_error = 0.0; @@ -929,19 +932,26 @@ } // Foxer: make sure overflow doesn't run away - if (overflow > bytes2 * 6 / 10) + if (overflow > bytes2 * codec->config.twopass_max_overflow_improvement / 100) { - bytes2 += (overflow <= bytes2) ? bytes2 * 6 / 10 : overflow * 6 / 10; + bytes2 += (overflow <= bytes2) ? bytes2 * codec->config.twopass_max_overflow_improvement / 100 : + overflow * codec->config.twopass_max_overflow_improvement / 100; } - else if (overflow < bytes2 * -6 / 10) + else if (overflow < bytes2 * codec->config.twopass_max_overflow_degradation / -100) { - bytes2 += bytes2 * -6 / 10; + bytes2 += bytes2 * codec->config.twopass_max_overflow_degradation / -100; } else { bytes2 += overflow; } + if (bytes2 > twopass->max_framesize) + { + capped_to_max_framesize = 1; + bytes2 = twopass->max_framesize; + } + if (bytes2 < 1) { bytes2 = 1; @@ -1005,7 +1015,7 @@ } // subsequent frame quants can only be +- 2 - if (last_quant) + if (last_quant && capped_to_max_framesize == 0) { if (frame->quant > last_quant + 2) { @@ -1020,7 +1030,8 @@ } } - last_quant = frame->quant; + if (capped_to_max_framesize == 0) + last_quant = frame->quant; if (codec->config.quant_type == QUANT_MODE_MOD) { @@ -1038,6 +1049,7 @@ NNSTATS nns1; DWORD wrote; + int credits_pos; char* quant_type; if (codec->framenum == 0) @@ -1084,7 +1096,12 @@ case DLG_MODE_2PASS_2_INT : case DLG_MODE_2PASS_2_EXT : codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length; - 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)) + + credits_pos = codec_is_in_credits(&codec->config, codec->framenum); + if (!credits_pos) + codec->twopass.quant_count[frame->quant]++; + + DEBUG2ND(frame->quant, quant_type, frame->intra, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos) break; default: @@ -1094,4 +1111,23 @@ return ICERR_OK; } +void codec_2pass_finish(CODEC* codec) +{ + int i; + char s[100]; + if (codec->config.mode == DLG_MODE_2PASS_2_EXT || codec->config.mode == DLG_MODE_2PASS_2_INT) + { + // output the quantizer distribution for this encode. + OutputDebugString("Quantizer distribution for 2nd pass:"); + for (i=1; i<=31; i++) + { + if (codec->twopass.quant_count[i]) + { + wsprintf(s, "Q:%i:%i", i, codec->twopass.quant_count[i]); + OutputDebugString(s); + } + } + return; + } +} \ No newline at end of file