Cleaning up vp9_twopass_worst_quality().
Change-Id: Ie144e9ece57f2d59c230704a2f166bda1042adeb
This commit is contained in:
parent
3dff8aa36b
commit
c3de569bb9
@ -901,39 +901,38 @@ static double calc_correction_factor(double err_per_mb,
|
|||||||
return fclamp(pow(error_term, power_term), 0.05, 5.0);
|
return fclamp(pow(error_term, power_term), 0.05, 5.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vp9_twopass_worst_quality(VP9_COMP *cpi, FIRSTPASS_STATS *fpstats,
|
static int get_twopass_worst_quality(const VP9_COMP *cpi,
|
||||||
int section_target_bandwitdh) {
|
const FIRSTPASS_STATS *stats,
|
||||||
int q;
|
int section_target_bandwidth) {
|
||||||
const int num_mbs = cpi->common.MBs;
|
|
||||||
int target_norm_bits_per_mb;
|
|
||||||
const RATE_CONTROL *const rc = &cpi->rc;
|
const RATE_CONTROL *const rc = &cpi->rc;
|
||||||
|
|
||||||
const double section_err = fpstats->coded_error / fpstats->count;
|
if (section_target_bandwidth <= 0) {
|
||||||
const double err_per_mb = section_err / num_mbs;
|
|
||||||
const double speed_term = 1.0 + ((double)cpi->speed * 0.04);
|
|
||||||
|
|
||||||
if (section_target_bandwitdh <= 0)
|
|
||||||
return rc->worst_quality; // Highest value allowed
|
return rc->worst_quality; // Highest value allowed
|
||||||
|
} else {
|
||||||
target_norm_bits_per_mb =
|
const int num_mbs = cpi->common.MBs;
|
||||||
((uint64_t)section_target_bandwitdh << BPER_MB_NORMBITS) / num_mbs;
|
const double section_err = stats->coded_error / stats->count;
|
||||||
|
const double err_per_mb = section_err / num_mbs;
|
||||||
|
const double speed_term = 1.0 + 0.04 * cpi->speed;
|
||||||
|
const int target_norm_bits_per_mb = ((uint64_t)section_target_bandwidth <<
|
||||||
|
BPER_MB_NORMBITS) / num_mbs;
|
||||||
|
int q;
|
||||||
|
|
||||||
// Try and pick a max Q that will be high enough to encode the
|
// Try and pick a max Q that will be high enough to encode the
|
||||||
// content at the given rate.
|
// content at the given rate.
|
||||||
for (q = rc->best_quality; q < rc->worst_quality; ++q) {
|
for (q = rc->best_quality; q < rc->worst_quality; ++q) {
|
||||||
const double err_correction_factor = calc_correction_factor(err_per_mb,
|
const double factor = calc_correction_factor(err_per_mb, ERR_DIVISOR,
|
||||||
ERR_DIVISOR, 0.5, 0.90, q);
|
0.5, 0.90, q);
|
||||||
const int bits_per_mb_at_this_q =
|
const int bits_per_mb = vp9_rc_bits_per_mb(INTER_FRAME, q,
|
||||||
vp9_rc_bits_per_mb(INTER_FRAME, q, (err_correction_factor * speed_term));
|
factor * speed_term);
|
||||||
if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
|
if (bits_per_mb <= target_norm_bits_per_mb)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restriction on active max q for constrained quality mode.
|
// Restriction on active max q for constrained quality mode.
|
||||||
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
|
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
|
||||||
q = MAX(q, cpi->cq_target_quality);
|
q = MAX(q, cpi->cq_target_quality);
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void vp9_new_framerate(VP9_COMP *cpi, double framerate);
|
extern void vp9_new_framerate(VP9_COMP *cpi, double framerate);
|
||||||
@ -2242,7 +2241,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
|
|||||||
// Special case code for first frame.
|
// Special case code for first frame.
|
||||||
const int section_target_bandwidth = (int)(twopass->bits_left /
|
const int section_target_bandwidth = (int)(twopass->bits_left /
|
||||||
frames_left);
|
frames_left);
|
||||||
const int tmp_q = vp9_twopass_worst_quality(cpi, &twopass->total_left_stats,
|
const int tmp_q = get_twopass_worst_quality(cpi, &twopass->total_left_stats,
|
||||||
section_target_bandwidth);
|
section_target_bandwidth);
|
||||||
twopass->active_worst_quality = tmp_q;
|
twopass->active_worst_quality = tmp_q;
|
||||||
rc->ni_av_qi = tmp_q;
|
rc->ni_av_qi = tmp_q;
|
||||||
|
@ -91,8 +91,6 @@ void vp9_end_first_pass(struct VP9_COMP *cpi);
|
|||||||
|
|
||||||
void vp9_init_second_pass(struct VP9_COMP *cpi);
|
void vp9_init_second_pass(struct VP9_COMP *cpi);
|
||||||
void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
|
void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
|
||||||
int vp9_twopass_worst_quality(struct VP9_COMP *cpi, FIRSTPASS_STATS *fpstats,
|
|
||||||
int section_target_bandwitdh);
|
|
||||||
|
|
||||||
// Post encode update of the rate control parameters for 2-pass
|
// Post encode update of the rate control parameters for 2-pass
|
||||||
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
|
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user