Merge "Moved ref frame calculations"
diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c
index 75502cc..c596138 100644
--- a/vp8/encoder/firstpass.c
+++ b/vp8/encoder/firstpass.c
@@ -980,10 +980,10 @@
// Restriction on active max q for constrained quality mode.
if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
(Q < cpi->cq_target_quality) )
- //(Q < cpi->oxcf.cq_target_quality) )
+ //(Q < cpi->oxcf.cq_level;) )
{
Q = cpi->cq_target_quality;
- //Q = cpi->oxcf.cq_target_quality;
+ //Q = cpi->oxcf.cq_level;
}
// Adjust maxq_min_limit and maxq_max_limit limits based on
@@ -2286,6 +2286,9 @@
cpi->common.frame_type = KEY_FRAME;
+ // is this a forced key frame by interval
+ cpi->this_key_frame_forced = cpi->next_key_frame_forced;
+
// Clear the alt ref active flag as this can never be active on a key frame
cpi->source_alt_ref_active = FALSE;
@@ -2348,7 +2351,11 @@
kf_group_err /= 2.0;
kf_group_intra_err /= 2.0;
kf_group_coded_err /= 2.0;
+
+ cpi->next_key_frame_forced = TRUE;
}
+ else
+ cpi->next_key_frame_forced = FALSE;
// Special case for the last frame of the file
if (cpi->stats_in >= cpi->stats_in_end)
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 1284a2a..470a9ac 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -2272,6 +2272,8 @@
cpi->frames_since_key = 8; // Give a sensible default for the first frame.
cpi->key_frame_frequency = cpi->oxcf.key_freq;
+ cpi->this_key_frame_forced = FALSE;
+ cpi->next_key_frame_forced = FALSE;
cpi->source_alt_ref_pending = FALSE;
cpi->source_alt_ref_active = FALSE;
@@ -3791,37 +3793,56 @@
}
// Set an active best quality and if necessary active worst quality
- if (cpi->pass == 2 || (cm->current_video_frame > 150))
+ // There is some odd behaviour for one pass here that needs attention.
+ if ( (cpi->pass == 2) || (cpi->ni_frames > 150))
{
- int Q;
- //int tmp;
-
vp8_clear_system_state();
Q = cpi->active_worst_quality;
- if ((cm->frame_type == KEY_FRAME) || cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame)
+ if ( cm->frame_type == KEY_FRAME )
{
- if (cm->frame_type != KEY_FRAME)
+ // Special case for key frames forced because we have reached
+ // the maximum key frame interval. Here force the Q to a range
+ // close to but just below the ambient Q to minimize the risk
+ // of popping
+ if ( cpi->this_key_frame_forced )
{
- if (cpi->avg_frame_qindex < cpi->active_worst_quality)
- Q = cpi->avg_frame_qindex;
+ cpi->active_worst_quality = cpi->avg_frame_qindex * 7/8;
+ cpi->active_best_quality = cpi->avg_frame_qindex * 2/3;
+ }
+ else
+ {
+ if ( cpi->pass == 2 )
+ {
+ if (cpi->gfu_boost > 600)
+ cpi->active_best_quality = kf_low_motion_minq[Q];
+ else
+ cpi->active_best_quality = kf_high_motion_minq[Q];
+ }
+ // One pass more conservative
+ else
+ cpi->active_best_quality = kf_high_motion_minq[Q];
+ }
+ }
- if ( cpi->gfu_boost > 1000 )
+ else if (cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame)
+ {
+ if (cpi->avg_frame_qindex < cpi->active_worst_quality)
+ Q = cpi->avg_frame_qindex;
+
+ if ( cpi->pass == 2 )
+ {
+ if ( cpi->gfu_boost > 1000 )
cpi->active_best_quality = gf_low_motion_minq[Q];
else if ( cpi->gfu_boost < 400 )
cpi->active_best_quality = gf_high_motion_minq[Q];
else
cpi->active_best_quality = gf_mid_motion_minq[Q];
- }
- // KEY FRAMES
- else
- {
- if (cpi->gfu_boost > 600)
- cpi->active_best_quality = kf_low_motion_minq[Q];
- else
- cpi->active_best_quality = kf_high_motion_minq[Q];
- }
+ }
+ // One pass more conservative
+ else
+ cpi->active_best_quality = gf_high_motion_minq[Q];
}
else
{
@@ -3851,7 +3872,6 @@
cpi->active_best_quality -= min_qadjustment;
}
-
}
}
diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h
index 6bffd98..6b07e2f 100644
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -317,7 +317,8 @@
unsigned int frames_since_key;
unsigned int key_frame_frequency;
- unsigned int next_key;
+ unsigned int this_key_frame_forced;
+ unsigned int next_key_frame_forced;
unsigned int mode_check_freq[MAX_MODES];
unsigned int mode_test_hit_counts[MAX_MODES];