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

Two pass rate control code changes.

This comitt brings accross changes from the public branch
commit number Icf74d13af77437c08602571dc7a97e747cce5066.

The main puurpose of this comit relates to CQ mode but it
also includes some refactoring of the two pass code which
I hope will make tuning the experimental branch for the new
quantizer range a little less painfull.

Change-Id: I278e989436a928fc1fe7761068960048f9d7a376
parent a0b7db22
This diff is collapsed.
......@@ -339,6 +339,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
......@@ -1553,11 +1556,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
......@@ -3812,12 +3820,13 @@ static void encode_frame_to_data_rate
(cpi->avg_frame_qindex < cpi->active_worst_quality) )
{
Q = cpi->avg_frame_qindex;
}
if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
(Q < cpi->oxcf.cq_level) )
{
Q = cpi->oxcf.cq_level;
}
// For constrained quality dont allow Q less than the cq level
if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
(Q < cpi->cq_target_quality) )
{
Q = cpi->cq_target_quality;
}
if ( cpi->pass == 2 )
......@@ -3828,6 +3837,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
......@@ -3838,7 +3854,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) )
{
......@@ -3891,8 +3907,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);
......@@ -4622,7 +4639,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",
......@@ -4633,13 +4650,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"
......@@ -4652,15 +4672,19 @@ 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);
if ( 0 )
{
FILE *fmodes = fopen("Modes.stt", "a");
int i;
......
......@@ -120,6 +120,7 @@ typedef struct
double MVrv;
double MVcv;
double mv_in_out_count;
double new_mv_count;
double duration;
double count;
}
......@@ -567,6 +568,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;
......@@ -574,10 +576,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