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 |
*************************************************************************/ |
*************************************************************************/ |
702 |
int bytes1, bytes2; |
int bytes1, bytes2; |
703 |
int overflow; |
int overflow; |
704 |
int credits_pos; |
int credits_pos; |
705 |
|
int capped_to_max_framesize = 0; |
706 |
|
|
707 |
if (codec->framenum == 0) |
if (codec->framenum == 0) |
708 |
{ |
{ |
933 |
} |
} |
934 |
|
|
935 |
// Foxer: make sure overflow doesn't run away |
// Foxer: make sure overflow doesn't run away |
936 |
if (overflow > bytes2 * 6 / 10) |
if (overflow > bytes2 * codec->config.twopass_max_overflow_improvement / 100) |
937 |
{ |
{ |
938 |
bytes2 += (overflow <= bytes2) ? bytes2 * 6 / 10 : overflow * 6 / 10; |
bytes2 += (overflow <= bytes2) ? bytes2 * codec->config.twopass_max_overflow_improvement / 100 : |
939 |
|
overflow * codec->config.twopass_max_overflow_improvement / 100; |
940 |
} |
} |
941 |
else if (overflow < bytes2 * -6 / 10) |
else if (overflow < bytes2 * codec->config.twopass_max_overflow_degradation / -100) |
942 |
{ |
{ |
943 |
bytes2 += bytes2 * -6 / 10; |
bytes2 += bytes2 * codec->config.twopass_max_overflow_degradation / -100; |
944 |
} |
} |
945 |
else |
else |
946 |
{ |
{ |
947 |
bytes2 += overflow; |
bytes2 += overflow; |
948 |
} |
} |
949 |
|
|
950 |
|
if (bytes2 > twopass->max_framesize) |
951 |
|
{ |
952 |
|
capped_to_max_framesize = 1; |
953 |
|
bytes2 = twopass->max_framesize; |
954 |
|
} |
955 |
|
|
956 |
if (bytes2 < 1) |
if (bytes2 < 1) |
957 |
{ |
{ |
958 |
bytes2 = 1; |
bytes2 = 1; |
1016 |
} |
} |
1017 |
|
|
1018 |
// subsequent frame quants can only be +- 2 |
// subsequent frame quants can only be +- 2 |
1019 |
if (last_quant) |
if (last_quant && capped_to_max_framesize == 0) |
1020 |
{ |
{ |
1021 |
if (frame->quant > last_quant + 2) |
if (frame->quant > last_quant + 2) |
1022 |
{ |
{ |
1031 |
} |
} |
1032 |
} |
} |
1033 |
|
|
1034 |
|
if (capped_to_max_framesize == 0) |
1035 |
last_quant = frame->quant; |
last_quant = frame->quant; |
1036 |
|
|
1037 |
if (codec->config.quant_type == QUANT_MODE_MOD) |
if (codec->config.quant_type == QUANT_MODE_MOD) |
1073 |
nns1.md_u = nns1.md_y = 0; |
nns1.md_u = nns1.md_y = 0; |
1074 |
nns1.mk_u = nns1.mk_y = 0; |
nns1.mk_u = nns1.mk_y = 0; |
1075 |
|
|
1076 |
nns1.quant = stats->quant; |
// nns1.quant = stats->quant; |
1077 |
|
nns1.quant = 2; // ugly fix for lumi masking in 1st pass returning new quant |
1078 |
if (frame->intra) |
if (frame->intra) |
1079 |
{ |
{ |
1080 |
nns1.quant |= NNSTATS_KEYFRAME; |
nns1.quant |= NNSTATS_KEYFRAME; |