summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Wilkins <paulwilkins@google.com>2011-01-25 12:29:06 +0000
committerPaul Wilkins <paulwilkins@google.com>2011-01-25 12:29:06 +0000
commit336aa0b7da8a35ba57400ce92fc016fc7fb35233 (patch)
treea30d05e724a0958dc18acfb8ba8f7dd5dd5356be
parentd3e9409bb07e6411ff867935883bd5d56d2f9041 (diff)
downloadlibvpx-336aa0b7da8a35ba57400ce92fc016fc7fb35233.tar
libvpx-336aa0b7da8a35ba57400ce92fc016fc7fb35233.tar.gz
libvpx-336aa0b7da8a35ba57400ce92fc016fc7fb35233.tar.bz2
libvpx-336aa0b7da8a35ba57400ce92fc016fc7fb35233.zip
Incorrect bit allocation in forced KF groups.
The old 2 pass code estimated error distribution when coding a forced (by interval) key frame. The result of this was that in some cases, when allocating bits at the GF group level within a KF group there was either a glut of bits or starvation of bits at the end of the KF group. Added code to rescan and get the correct data once the position of a forced key frame has been determined. Change-Id: I0c811675ef3f9e4109d14bd049d7641682ffcf11
-rw-r--r--vp8/encoder/firstpass.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c
index a77ced78c..3e67bf53c 100644
--- a/vp8/encoder/firstpass.c
+++ b/vp8/encoder/firstpass.c
@@ -2423,12 +2423,35 @@ void vp8_find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
if (cpi->oxcf.auto_key
&& cpi->frames_to_key > (int)cpi->key_frame_frequency )
{
+ int current_pos = cpi->stats_in;
+ FIRSTPASS_STATS tmp_frame;
+
cpi->frames_to_key /= 2;
- // Estimate corrected kf group error
- kf_group_err /= 2.0;
- kf_group_intra_err /= 2.0;
- kf_group_coded_err /= 2.0;
+ // Copy first frame details
+ vpx_memcpy(&tmp_frame, &first_frame, sizeof(first_frame));
+
+ // Reset to the start of the group
+ reset_fpf_position(cpi, start_position);
+
+ kf_group_err = 0;
+ kf_group_intra_err = 0;
+ kf_group_coded_err = 0;
+
+ // Rescan to get the correct error data for the forced kf group
+ for( i = 0; i < cpi->frames_to_key; i++ )
+ {
+ // Accumulate kf group errors
+ kf_group_err += calculate_modified_err(cpi, &tmp_frame);
+ kf_group_intra_err += tmp_frame.intra_error;
+ kf_group_coded_err += tmp_frame.coded_error;
+
+ // Load a the next frame's stats
+ vp8_input_stats(cpi, &tmp_frame);
+ }
+
+ // Reset to the start of the group
+ reset_fpf_position(cpi, current_pos);
cpi->next_key_frame_forced = TRUE;
}