ref: ade9693a30821af5c28b947090aa6d41cb27ea20
parent: 976f7f42c1ad1ff3cc0792572f9c4f41f05bb375
author: paulwilkins <[email protected]>
date: Thu May 14 13:16:36 EDT 2015
Fix issues with mixed ARF and GF groups. This patch addresses two issues that can occur when the encoder chooses to use a mixture of ARF and GF groups. The first issue relates to a failure to reset the "ARF active" flag correctly when transitioning from coding ARF groups to coding GF groups. This caused some golden frames to be encoded with an incorrect bit rate target as if they were ARF overlay frames. The second issue relates to the encoding of a single short GF group just before a key frame. Where the last group before a key frame is an ARF group we expect the final frame before the key frame to be an low data rate overlay frame. However, when the last group is a GF group, the final frame before the key frame should be a normal frame with a normal bit allocation. This issue had the potential to cause a single poorly coded frame just before a key frame. If that key frame were a forced key frame rather than a real scene cut, this might cause pulsing. Change-Id: Idf1eb5eaf63a231495a74de7899236e1ead9fb00
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -2795,7 +2795,7 @@
recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
if (cpi->twopass.total_left_stats.coded_error != 0.0)
- fprintf(f, "%10u %dx%d %10d %10d %10d %10d"
+ fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d"
"%10"PRId64" %10"PRId64" %10"PRId64" %10"PRId64" %10d "
"%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf"
"%6d %6d %5d %5d %5d "
@@ -2803,6 +2803,8 @@
"%10lf %8u %10"PRId64" %10d %10d\n",
cpi->common.current_video_frame,
cm->width, cm->height,
+ cpi->rc.source_alt_ref_pending,
+ cpi->rc.source_alt_ref_active,
cpi->rc.this_frame_target,
cpi->rc.projected_frame_size,
cpi->rc.projected_frame_size / cpi->common.MBs,
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -1696,7 +1696,7 @@
mid_frame_idx = frame_index + (rc->baseline_gf_interval >> 1) - 1;
// Allocate bits to the other frames in the group.
- for (i = 0; i < rc->baseline_gf_interval - 1; ++i) {
+ for (i = 0; i < rc->baseline_gf_interval - rc->source_alt_ref_pending; ++i) {
int arf_idx = 0;
if (EOF == input_stats(twopass, &frame_stats))
break;
@@ -1934,8 +1934,26 @@
// Was the group length constrained by the requirement for a new KF?
rc->constrained_gf_group = (i >= rc->frames_to_key) ? 1 : 0;
+ // Should we use the alternate reference frame.
+ if (allow_alt_ref &&
+ (i < cpi->oxcf.lag_in_frames) &&
+ (i >= rc->min_gf_interval)) {
+ // Calculate the boost for alt ref.
+ rc->gfu_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost,
+ &b_boost);
+ rc->source_alt_ref_pending = 1;
+
+ // Test to see if multi arf is appropriate.
+ cpi->multi_arf_enabled =
+ (cpi->multi_arf_allowed && (rc->baseline_gf_interval >= 6) &&
+ (zero_motion_accumulator < 0.995)) ? 1 : 0;
+ } else {
+ rc->gfu_boost = MAX((int)boost_score, MIN_ARF_GF_BOOST);
+ rc->source_alt_ref_pending = 0;
+ }
+
// Set the interval until the next gf.
- if (is_key_frame || rc->source_alt_ref_active)
+ if (is_key_frame || rc->source_alt_ref_pending)
rc->baseline_gf_interval = i - 1;
else
rc->baseline_gf_interval = i;
@@ -1959,24 +1977,6 @@
}
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-
- // Should we use the alternate reference frame.
- if (allow_alt_ref &&
- (i < cpi->oxcf.lag_in_frames) &&
- (i >= rc->min_gf_interval)) {
- // Calculate the boost for alt ref.
- rc->gfu_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost,
- &b_boost);
- rc->source_alt_ref_pending = 1;
-
- // Test to see if multi arf is appropriate.
- cpi->multi_arf_enabled =
- (cpi->multi_arf_allowed && (rc->baseline_gf_interval >= 6) &&
- (zero_motion_accumulator < 0.995)) ? 1 : 0;
- } else {
- rc->gfu_boost = MAX((int)boost_score, MIN_ARF_GF_BOOST);
- rc->source_alt_ref_pending = 0;
- }
// Reset the file position.
reset_fpf_position(twopass, start_pos);
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -1207,11 +1207,9 @@
// this frame refreshes means next frames don't unless specified by user
rc->frames_since_golden = 0;
- if (cpi->oxcf.pass == 2) {
- if (!rc->source_alt_ref_pending &&
- cpi->twopass.gf_group.rf_level[0] == GF_ARF_STD)
- rc->source_alt_ref_active = 0;
- } else if (!rc->source_alt_ref_pending) {
+ // If we are not using alt ref in the up and coming group clear the arf
+ // active flag.
+ if (!rc->source_alt_ref_pending) {
rc->source_alt_ref_active = 0;
}