Fix gf group length bug when altref is not used.
When alt_ref is not used, there was a bug that still adds the
overlay frame to the next gf group, which was causing a
segmentation fault. This patch fixes it.
Change-Id: I3f3c104d33f62e74755787d209e532d85032b02e
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index ebcce75..747dd62 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -1566,6 +1566,7 @@
if (i - roll_back >= active_min_gf_interval + 1) {
alt_offset = -roll_back;
i -= roll_back;
+ rc->intervals_till_gf_calculate_due = 0;
}
}
}
@@ -1605,10 +1606,12 @@
// if possible, merge the last two gf groups
if (rc->frames_to_key <= active_max_gf_interval) {
rc->baseline_gf_interval = rc->frames_to_key;
+ rc->intervals_till_gf_calculate_due = 0;
// if merging the last two gf groups creates a group that is too long,
// split them and force the last gf group to be the MIN_FWD_KF_INTERVAL
} else {
rc->baseline_gf_interval = rc->frames_to_key - MIN_FWD_KF_INTERVAL;
+ rc->intervals_till_gf_calculate_due = 0;
}
} else {
rc->baseline_gf_interval = i - rc->source_alt_ref_pending;
@@ -1616,6 +1619,15 @@
} else {
rc->baseline_gf_interval = i - rc->source_alt_ref_pending;
}
+ // rc->gf_intervals assumes the usage of alt_ref, therefore adding one overlay
+ // frame to the next gf. If no alt_ref is used, should substract 1 frame from
+ // the next gf group.
+ // TODO(bohanli): should incorporate the usage of alt_ref into
+ // calculate_gf_length
+ if (rc->source_alt_ref_pending == 0 &&
+ rc->intervals_till_gf_calculate_due > 0) {
+ rc->gf_intervals[rc->cur_gf_index]--;
+ }
#define LAST_ALR_BOOST_FACTOR 0.2f
rc->arf_boost_factor = 1.0;