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 |
|
|
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); |
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 |
|
|
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; |
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 |
} |
} |
710 |
int overflow; |
int overflow; |
711 |
int credits_pos; |
int credits_pos; |
712 |
int capped_to_max_framesize = 0; |
int capped_to_max_framesize = 0; |
713 |
|
int KFdistance, KF_min_size; |
714 |
|
|
715 |
if (codec->framenum == 0) |
if (codec->framenum == 0) |
716 |
{ |
{ |
930 |
|
|
931 |
twopass->desired_bytes2 = bytes2; |
twopass->desired_bytes2 = bytes2; |
932 |
|
|
933 |
|
if (frame->intra) |
934 |
|
{ |
935 |
|
KFdistance = codec->twopass.keyframe_locations[codec->twopass.KF_idx] - |
936 |
|
codec->twopass.keyframe_locations[codec->twopass.KF_idx - 1]; |
937 |
|
|
938 |
|
if (KFdistance < codec->config.kftreshold) |
939 |
|
{ |
940 |
|
KFdistance = KFdistance - codec->config.min_key_interval; |
941 |
|
|
942 |
|
if (KFdistance >= 0) |
943 |
|
{ |
944 |
|
KF_min_size = bytes2 * (100 - codec->config.kfreduction) / 100; |
945 |
|
if (KF_min_size < 1) |
946 |
|
KF_min_size = 1; |
947 |
|
|
948 |
|
bytes2 = KF_min_size + (bytes2 - KF_min_size) * KFdistance / |
949 |
|
(codec->config.kftreshold - codec->config.min_key_interval); |
950 |
|
|
951 |
|
if (bytes2 < 1) |
952 |
|
bytes2 = 1; |
953 |
|
} |
954 |
|
} |
955 |
|
} |
956 |
|
|
957 |
// Foxer: scale overflow in relation to average size, so smaller frames don't get |
// Foxer: scale overflow in relation to average size, so smaller frames don't get |
958 |
// too much/little bitrate |
// too much/little bitrate |
959 |
overflow = (int)((double)overflow * bytes2 / twopass->average_frame); |
overflow = (int)((double)overflow * bytes2 / twopass->average_frame); |
1082 |
|
|
1083 |
NNSTATS nns1; |
NNSTATS nns1; |
1084 |
DWORD wrote; |
DWORD wrote; |
1085 |
int credits_pos; |
int credits_pos, tempdiv; |
1086 |
char* quant_type; |
char* quant_type; |
1087 |
|
|
1088 |
if (codec->framenum == 0) |
if (codec->framenum == 0) |
1129 |
|
|
1130 |
case DLG_MODE_2PASS_2_INT : |
case DLG_MODE_2PASS_2_INT : |
1131 |
case DLG_MODE_2PASS_2_EXT : |
case DLG_MODE_2PASS_2_EXT : |
|
codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length; |
|
|
|
|
1132 |
credits_pos = codec_is_in_credits(&codec->config, codec->framenum); |
credits_pos = codec_is_in_credits(&codec->config, codec->framenum); |
1133 |
if (!credits_pos) |
if (!credits_pos) |
1134 |
|
{ |
1135 |
codec->twopass.quant_count[frame->quant]++; |
codec->twopass.quant_count[frame->quant]++; |
1136 |
|
if ((codec->twopass.nns1.quant & NNSTATS_KEYFRAME)) |
1137 |
|
{ |
1138 |
|
codec->twopass.overflow += codec->twopass.KFoverflow; |
1139 |
|
codec->twopass.KFoverflow = codec->twopass.desired_bytes2 - frame->length; |
1140 |
|
|
1141 |
|
tempdiv = (codec->twopass.keyframe_locations[codec->twopass.KF_idx] - |
1142 |
|
codec->twopass.keyframe_locations[codec->twopass.KF_idx - 1]); |
1143 |
|
|
1144 |
|
if (tempdiv > 1) |
1145 |
|
{ |
1146 |
|
// non-consecutive keyframes |
1147 |
|
codec->twopass.KFoverflow_partial = codec->twopass.KFoverflow / (tempdiv - 1); |
1148 |
|
} |
1149 |
|
else |
1150 |
|
{ |
1151 |
|
// consecutive keyframes |
1152 |
|
codec->twopass.overflow += codec->twopass.KFoverflow; |
1153 |
|
codec->twopass.KFoverflow = 0; |
1154 |
|
codec->twopass.KFoverflow_partial = 0; |
1155 |
|
} |
1156 |
|
codec->twopass.KF_idx++; |
1157 |
|
} |
1158 |
|
else |
1159 |
|
{ |
1160 |
|
codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length + |
1161 |
|
codec->twopass.KFoverflow_partial; |
1162 |
|
codec->twopass.KFoverflow -= codec->twopass.KFoverflow_partial; |
1163 |
|
} |
1164 |
|
} |
1165 |
|
else |
1166 |
|
{ |
1167 |
|
codec->twopass.overflow += codec->twopass.desired_bytes2 - frame->length; |
1168 |
|
|
1169 |
|
// ugly fix for credits.. |
1170 |
|
codec->twopass.overflow += codec->twopass.KFoverflow; |
1171 |
|
codec->twopass.KFoverflow = 0; |
1172 |
|
codec->twopass.KFoverflow_partial = 0; |
1173 |
|
// end of ugly fix. |
1174 |
|
} |
1175 |
|
|
1176 |
DEBUG2ND(frame->quant, quant_type, frame->intra, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos) |
DEBUG2ND(frame->quant, quant_type, frame->intra, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos) |
1177 |
break; |
break; |