Two Pass VBR change

Further experiment with restriction of the Q range.

This uses the average non KF/GF/ARF quantizer,  instead
of just relying on the initial value. It is not such a strong constraint
but there may be a reduced risk of rate misses.

Change-Id: I424fe782a37a2f4e18c70805e240db55bfaa25ec
This commit is contained in:
Paul Wilkins 2011-01-10 16:41:53 +00:00
parent 405499d835
commit cf7c4732e5
2 changed files with 43 additions and 22 deletions

View File

@ -989,6 +989,19 @@ static int estimate_max_q(VP8_COMP *cpi, double section_err, int section_target_
//Q = cpi->oxcf.cq_target_quality; //Q = cpi->oxcf.cq_target_quality;
} }
// Adjust maxq_min_limit and maxq_max_limit limits based on
// averaga q observed in clip for non kf/gf.arf frames
// Give average a chance to settle though.
if ( (cpi->ni_frames >
((unsigned int)cpi->total_stats->count >> 8)) &&
(cpi->ni_frames > 150) )
{
cpi->maxq_max_limit = ((cpi->ni_av_qi + 32) < cpi->worst_quality)
? (cpi->ni_av_qi + 32) : cpi->worst_quality;
cpi->maxq_min_limit = ((cpi->ni_av_qi - 32) > cpi->best_quality)
? (cpi->ni_av_qi - 32) : cpi->best_quality;
}
return Q; return Q;
} }
static int estimate_q(VP8_COMP *cpi, double section_err, int section_target_bandwitdh, int Height, int Width) static int estimate_q(VP8_COMP *cpi, double section_err, int section_target_bandwitdh, int Height, int Width)
@ -2121,7 +2134,7 @@ void vp8_second_pass(VP8_COMP *cpi)
cpi->common.Width); cpi->common.Width);
// Limit the maxq value returned subsequently. // Limit the maxq value returned subsequently.
// This increases the risk of overspend if the initial // This increases the risk of overspend or underspend if the initial
// estimate for the clip is bad, but helps prevent excessive // estimate for the clip is bad, but helps prevent excessive
// variation in Q, especially near the end of a clip // variation in Q, especially near the end of a clip
// where for example a small overspend may cause Q to crash // where for example a small overspend may cause Q to crash

View File

@ -4442,15 +4442,23 @@ static void encode_frame_to_data_rate
{ {
cpi->ni_frames++; cpi->ni_frames++;
// Calculate the average Q for normal inter frames (not key or GFU frames) // Calculate the average Q for normal inter frames (not key or GFU
// This is used as a basis for setting active worst quality. // frames).
if ( cpi->pass == 2 )
{
cpi->ni_tot_qi += Q;
cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
}
else
{
// Damp value for first few frames
if (cpi->ni_frames > 150 ) if (cpi->ni_frames > 150 )
{ {
cpi->ni_tot_qi += Q; cpi->ni_tot_qi += Q;
cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames); cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
} }
// Early in the clip ... average the current frame Q value with the default // For one pass, early in the clip ... average the current frame Q
// entered by the user as a dampening measure // value with the worstq entered by the user as a dampening measure
else else
{ {
cpi->ni_tot_qi += Q; cpi->ni_tot_qi += Q;
@ -4465,7 +4473,7 @@ static void encode_frame_to_data_rate
// itterations around the recode loop. // itterations around the recode loop.
if (Q > cpi->ni_av_qi) if (Q > cpi->ni_av_qi)
cpi->ni_av_qi = Q - 1; cpi->ni_av_qi = Q - 1;
}
} }
#if 0 #if 0
@ -4559,7 +4567,7 @@ static void encode_frame_to_data_rate
if (cpi->total_coded_error_left != 0.0) if (cpi->total_coded_error_left != 0.0)
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6ld %6ld" fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6ld %6ld"
"%6ld %6ld %5ld %5ld %5ld %8ld %8.2f %10d %10.3f" "%6ld %6ld %6ld %5ld %5ld %5ld %8ld %8.2f %10d %10.3f"
"%10.3f %8ld\n", "%10.3f %8ld\n",
cpi->common.current_video_frame, cpi->this_frame_target, cpi->common.current_video_frame, cpi->this_frame_target,
cpi->projected_frame_size, cpi->projected_frame_size,
@ -4568,7 +4576,7 @@ static void encode_frame_to_data_rate
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target), (cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
(int)cpi->total_actual_bits, cm->base_qindex, (int)cpi->total_actual_bits, cm->base_qindex,
cpi->active_best_quality, cpi->active_worst_quality, cpi->active_best_quality, cpi->active_worst_quality,
cpi->cq_target_quality, cpi->zbin_over_quant, cpi->ni_av_qi, cpi->cq_target_quality, cpi->zbin_over_quant,
//cpi->avg_frame_qindex, cpi->zbin_over_quant, //cpi->avg_frame_qindex, cpi->zbin_over_quant,
cm->refresh_golden_frame, cm->refresh_alt_ref_frame, cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
cm->frame_type, cpi->gfu_boost, cm->frame_type, cpi->gfu_boost,
@ -4578,7 +4586,7 @@ static void encode_frame_to_data_rate
cpi->tot_recode_hits); cpi->tot_recode_hits);
else else
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6ld %6ld" fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6ld %6ld"
"%6ld %6ld %5ld %5ld %5ld %8ld %8.2f %10d %10.3f" "%6ld %6ld %6ld %5ld %5ld %5ld %8ld %8.2f %10d %10.3f"
"%8ld\n", "%8ld\n",
cpi->common.current_video_frame, cpi->common.current_video_frame,
cpi->this_frame_target, cpi->projected_frame_size, cpi->this_frame_target, cpi->projected_frame_size,
@ -4587,7 +4595,7 @@ static void encode_frame_to_data_rate
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target), (cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
(int)cpi->total_actual_bits, cm->base_qindex, (int)cpi->total_actual_bits, cm->base_qindex,
cpi->active_best_quality, cpi->active_worst_quality, cpi->active_best_quality, cpi->active_worst_quality,
cpi->cq_target_quality, cpi->zbin_over_quant, cpi->ni_av_qi, cpi->cq_target_quality, cpi->zbin_over_quant,
//cpi->avg_frame_qindex, cpi->zbin_over_quant, //cpi->avg_frame_qindex, cpi->zbin_over_quant,
cm->refresh_golden_frame, cm->refresh_alt_ref_frame, cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
cm->frame_type, cpi->gfu_boost, cm->frame_type, cpi->gfu_boost,