// Don't allow a gf too near the next kf
if ((cpi->rc.frames_to_key - i) < MIN_GF_INTERVAL) {
- while (i < cpi->rc.frames_to_key) {
+ while (i < (cpi->rc.frames_to_key + !cpi->rc.next_key_frame_forced)) {
i++;
if (EOF == input_stats(&cpi->twopass, this_frame))
if (allow_alt_ref &&
(i < cpi->oxcf.lag_in_frames) &&
(i >= MIN_GF_INTERVAL) &&
+ // for real scene cuts (not forced kfs) dont allow arf very near kf.
+ (cpi->rc.next_key_frame_forced ||
+ (i <= (cpi->rc.frames_to_key - MIN_GF_INTERVAL))) &&
((next_frame.pcnt_inter > 0.75) ||
(next_frame.pcnt_second_ref > 0.5)) &&
((mv_in_out_accumulator / (double)i > -0.2) ||
input_stats(&cpi->twopass, &tmp_frame);
}
cpi->rc.next_key_frame_forced = 1;
+ } else if (cpi->twopass.stats_in == cpi->twopass.stats_in_end) {
+ cpi->rc.next_key_frame_forced = 1;
} else {
cpi->rc.next_key_frame_forced = 0;
}