Commit b6e27d5f authored by Paul Wilkins's avatar Paul Wilkins
Browse files

CQ and two pass rate control.

Changes to the selection of Q limits for two pass
and two pass CQ mode.

Allowance made for Mode and motion vector costs.
Some refactoring of common code.

For Derf and YT sets CQ mode average improvement
circa 1% (SSIM and Global PSNR).

Some increased tendency to undershoot even when
user CQ not reached.

Patch2: Removed some test code accidentally merged.

Change-Id: Icf74d13af77437c08602571dc7a97e747cce5066
parent e47306eb
This diff is collapsed.
......@@ -309,6 +309,9 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
vpx_free(cpi->twopass.total_stats);
cpi->twopass.total_stats = 0;
vpx_free(cpi->twopass.total_left_stats);
cpi->twopass.total_left_stats = 0;
vpx_free(cpi->twopass.this_frame_stats);
cpi->twopass.this_frame_stats = 0;
#endif
......@@ -1335,11 +1338,16 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
cpi->twopass.total_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
vpx_free(cpi->twopass.total_left_stats);
cpi->twopass.total_left_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
vpx_free(cpi->twopass.this_frame_stats);
cpi->twopass.this_frame_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
if(!cpi->twopass.total_stats || !cpi->twopass.this_frame_stats)
if( !cpi->twopass.total_stats ||
!cpi->twopass.total_left_stats ||
!cpi->twopass.this_frame_stats)
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
"Failed to allocate firstpass stats");
#endif
......@@ -3511,12 +3519,13 @@ static void encode_frame_to_data_rate
(cpi->avg_frame_qindex < cpi->active_worst_quality) )
{
Q = cpi->avg_frame_qindex;
}
// For constrained quality dont allow Q less than the cq level
if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
(Q < cpi->oxcf.cq_level) )
(Q < cpi->cq_target_quality) )
{
Q = cpi->oxcf.cq_level;
}
Q = cpi->cq_target_quality;
}
if ( cpi->pass == 2 )
......@@ -3527,6 +3536,13 @@ static void encode_frame_to_data_rate
cpi->active_best_quality = gf_high_motion_minq[Q];
else
cpi->active_best_quality = gf_mid_motion_minq[Q];
// Constrained quality use slightly lower active best.
if ( cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY )
{
cpi->active_best_quality =
cpi->active_best_quality * 15/16;
}
}
// One pass more conservative
else
......@@ -3537,7 +3553,7 @@ static void encode_frame_to_data_rate
cpi->active_best_quality = inter_minq[Q];
// For the constant/constrained quality mode we dont want
// the quality to rise above the cq level.
// q to fall below the cq level.
if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
(cpi->active_best_quality < cpi->cq_target_quality) )
{
......@@ -3590,8 +3606,9 @@ static void encode_frame_to_data_rate
if (cpi->active_best_quality < cpi->best_quality)
cpi->active_best_quality = cpi->best_quality;
else if (cpi->active_best_quality > cpi->active_worst_quality)
cpi->active_best_quality = cpi->active_worst_quality;
if ( cpi->active_worst_quality < cpi->active_best_quality )
cpi->active_worst_quality = cpi->active_best_quality;
// Determine initial Q to try
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
......@@ -4294,7 +4311,7 @@ static void encode_frame_to_data_rate
vp8_clear_system_state(); //__asm emms;
if (cpi->twopass.total_coded_error_left != 0.0)
if (cpi->twopass.total_left_stats.coded_error != 0.0)
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6d %6d"
"%6d %6d %6d %5d %5d %5d %8d %8.2f %10d %10.3f"
"%10.3f %8d\n",
......@@ -4305,13 +4322,16 @@ static void encode_frame_to_data_rate
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
(int)cpi->total_actual_bits, cm->base_qindex,
cpi->active_best_quality, cpi->active_worst_quality,
cpi->ni_av_qi, 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,
cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
cm->frame_type, cpi->gfu_boost,
cpi->twopass.est_max_qcorrection_factor, (int)cpi->twopass.bits_left,
cpi->twopass.total_coded_error_left,
(double)cpi->twopass.bits_left / cpi->twopass.total_coded_error_left,
cpi->twopass.est_max_qcorrection_factor,
(int)cpi->twopass.bits_left,
cpi->twopass.total_left_stats.coded_error,
(double)cpi->twopass.bits_left /
cpi->twopass.total_left_stats.coded_error,
cpi->tot_recode_hits);
else
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6d %6d"
......@@ -4324,12 +4344,15 @@ static void encode_frame_to_data_rate
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
(int)cpi->total_actual_bits, cm->base_qindex,
cpi->active_best_quality, cpi->active_worst_quality,
cpi->ni_av_qi, 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,
cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
cm->frame_type, cpi->gfu_boost,
cpi->twopass.est_max_qcorrection_factor, (int)cpi->twopass.bits_left,
cpi->twopass.total_coded_error_left, cpi->tot_recode_hits);
cpi->twopass.est_max_qcorrection_factor,
(int)cpi->twopass.bits_left,
cpi->twopass.total_left_stats.coded_error,
cpi->tot_recode_hits);
fclose(f);
......
......@@ -108,6 +108,7 @@ typedef struct
double MVrv;
double MVcv;
double mv_in_out_count;
double new_mv_count;
double duration;
double count;
}
......@@ -523,6 +524,7 @@ typedef struct VP8_COMP
FIRSTPASS_STATS *total_stats;
FIRSTPASS_STATS *this_frame_stats;
FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
FIRSTPASS_STATS *total_left_stats;
int first_pass_done;
int64_t bits_left;
int64_t clip_bits_total;
......@@ -530,10 +532,6 @@ typedef struct VP8_COMP
double modified_error_total;
double modified_error_used;
double modified_error_left;
double total_error_left;
double total_intra_error_left;
double total_coded_error_left;
double start_tot_err_left;
double kf_intra_err_min;
double gf_intra_err_min;
int frames_to_key;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment