|
|
|
|
@@ -247,8 +247,8 @@ static void avg_stats(FIRSTPASS_STATS *section) {
|
|
|
|
|
|
|
|
|
|
// Calculate a modified Error used in distributing bits between easier and harder frames
|
|
|
|
|
static double calculate_modified_err(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
|
|
|
|
|
double av_err = (cpi->twopass.total_stats->ssim_weighted_pred_err /
|
|
|
|
|
cpi->twopass.total_stats->count);
|
|
|
|
|
double av_err = (cpi->twopass.total_stats.ssim_weighted_pred_err /
|
|
|
|
|
cpi->twopass.total_stats.count);
|
|
|
|
|
double this_err = this_frame->ssim_weighted_pred_err;
|
|
|
|
|
double modified_err;
|
|
|
|
|
|
|
|
|
|
@@ -328,7 +328,7 @@ static int frame_max_bits(VP9_COMP *cpi) {
|
|
|
|
|
// For VBR base this on the bits and frames left plus the
|
|
|
|
|
// two_pass_vbrmax_section rate passed in by the user.
|
|
|
|
|
max_bits = (int) (((double) cpi->twopass.bits_left
|
|
|
|
|
/ (cpi->twopass.total_stats->count - (double) cpi->common
|
|
|
|
|
/ (cpi->twopass.total_stats.count - (double) cpi->common
|
|
|
|
|
.current_video_frame))
|
|
|
|
|
* ((double) cpi->oxcf.two_pass_vbrmax_section / 100.0));
|
|
|
|
|
|
|
|
|
|
@@ -340,11 +340,11 @@ static int frame_max_bits(VP9_COMP *cpi) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vp9_init_first_pass(VP9_COMP *cpi) {
|
|
|
|
|
zero_stats(cpi->twopass.total_stats);
|
|
|
|
|
zero_stats(&cpi->twopass.total_stats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vp9_end_first_pass(VP9_COMP *cpi) {
|
|
|
|
|
output_stats(cpi, cpi->output_pkt_list, cpi->twopass.total_stats);
|
|
|
|
|
output_stats(cpi, cpi->output_pkt_list, &cpi->twopass.total_stats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void zz_motion_search(VP9_COMP *cpi, MACROBLOCK *x, YV12_BUFFER_CONFIG *recon_buffer, int *best_motion_err, int recon_yoffset) {
|
|
|
|
|
@@ -754,20 +754,20 @@ void vp9_first_pass(VP9_COMP *cpi) {
|
|
|
|
|
- cpi->source->ts_start);
|
|
|
|
|
|
|
|
|
|
// don't want to do output stats with a stack variable!
|
|
|
|
|
memcpy(cpi->twopass.this_frame_stats,
|
|
|
|
|
memcpy(&cpi->twopass.this_frame_stats,
|
|
|
|
|
&fps,
|
|
|
|
|
sizeof(FIRSTPASS_STATS));
|
|
|
|
|
output_stats(cpi, cpi->output_pkt_list, cpi->twopass.this_frame_stats);
|
|
|
|
|
accumulate_stats(cpi->twopass.total_stats, &fps);
|
|
|
|
|
output_stats(cpi, cpi->output_pkt_list, &cpi->twopass.this_frame_stats);
|
|
|
|
|
accumulate_stats(&cpi->twopass.total_stats, &fps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy the previous Last Frame back into gf and and arf buffers if
|
|
|
|
|
// the prediction is good enough... but also dont allow it to lag too far
|
|
|
|
|
if ((cpi->twopass.sr_update_lag > 3) ||
|
|
|
|
|
((cm->current_video_frame > 0) &&
|
|
|
|
|
(cpi->twopass.this_frame_stats->pcnt_inter > 0.20) &&
|
|
|
|
|
((cpi->twopass.this_frame_stats->intra_error /
|
|
|
|
|
DOUBLE_DIVIDE_CHECK(cpi->twopass.this_frame_stats->coded_error)) >
|
|
|
|
|
(cpi->twopass.this_frame_stats.pcnt_inter > 0.20) &&
|
|
|
|
|
((cpi->twopass.this_frame_stats.intra_error /
|
|
|
|
|
DOUBLE_DIVIDE_CHECK(cpi->twopass.this_frame_stats.coded_error)) >
|
|
|
|
|
2.0))) {
|
|
|
|
|
vp8_yv12_copy_frame(lst_yv12, gld_yv12);
|
|
|
|
|
cpi->twopass.sr_update_lag = 1;
|
|
|
|
|
@@ -998,7 +998,7 @@ static int estimate_max_q(VP9_COMP *cpi,
|
|
|
|
|
// Give average a chance to settle though.
|
|
|
|
|
// PGW TODO.. This code is broken for the extended Q range
|
|
|
|
|
if ((cpi->ni_frames >
|
|
|
|
|
((int)cpi->twopass.total_stats->count >> 8)) &&
|
|
|
|
|
((int)cpi->twopass.total_stats.count >> 8)) &&
|
|
|
|
|
(cpi->ni_frames > 25)) {
|
|
|
|
|
adjust_maxq_qrange(cpi);
|
|
|
|
|
}
|
|
|
|
|
@@ -1055,8 +1055,8 @@ static int estimate_cq(VP9_COMP *cpi,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// II ratio correction factor for clip as a whole
|
|
|
|
|
clip_iiratio = cpi->twopass.total_stats->intra_error /
|
|
|
|
|
DOUBLE_DIVIDE_CHECK(cpi->twopass.total_stats->coded_error);
|
|
|
|
|
clip_iiratio = cpi->twopass.total_stats.intra_error /
|
|
|
|
|
DOUBLE_DIVIDE_CHECK(cpi->twopass.total_stats.coded_error);
|
|
|
|
|
clip_iifactor = 1.0 - ((clip_iiratio - 10.0) * 0.025);
|
|
|
|
|
if (clip_iifactor < 0.80)
|
|
|
|
|
clip_iifactor = 0.80;
|
|
|
|
|
@@ -1101,14 +1101,14 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
if (two_pass_min_rate < lower_bounds_min_rate)
|
|
|
|
|
two_pass_min_rate = lower_bounds_min_rate;
|
|
|
|
|
|
|
|
|
|
zero_stats(cpi->twopass.total_stats);
|
|
|
|
|
zero_stats(cpi->twopass.total_left_stats);
|
|
|
|
|
zero_stats(&cpi->twopass.total_stats);
|
|
|
|
|
zero_stats(&cpi->twopass.total_left_stats);
|
|
|
|
|
|
|
|
|
|
if (!cpi->twopass.stats_in_end)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
*cpi->twopass.total_stats = *cpi->twopass.stats_in_end;
|
|
|
|
|
*cpi->twopass.total_left_stats = *cpi->twopass.total_stats;
|
|
|
|
|
cpi->twopass.total_stats = *cpi->twopass.stats_in_end;
|
|
|
|
|
cpi->twopass.total_left_stats = cpi->twopass.total_stats;
|
|
|
|
|
|
|
|
|
|
// each frame can have a different duration, as the frame rate in the source
|
|
|
|
|
// isn't guaranteed to be constant. The frame rate prior to the first frame
|
|
|
|
|
@@ -1116,13 +1116,13 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
// Its calculated based on the actual durations of all frames from the first
|
|
|
|
|
// pass.
|
|
|
|
|
vp9_new_frame_rate(cpi,
|
|
|
|
|
10000000.0 * cpi->twopass.total_stats->count /
|
|
|
|
|
cpi->twopass.total_stats->duration);
|
|
|
|
|
10000000.0 * cpi->twopass.total_stats.count /
|
|
|
|
|
cpi->twopass.total_stats.duration);
|
|
|
|
|
|
|
|
|
|
cpi->output_frame_rate = cpi->oxcf.frame_rate;
|
|
|
|
|
cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats->duration *
|
|
|
|
|
cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats.duration *
|
|
|
|
|
cpi->oxcf.target_bandwidth / 10000000.0);
|
|
|
|
|
cpi->twopass.bits_left -= (int64_t)(cpi->twopass.total_stats->duration *
|
|
|
|
|
cpi->twopass.bits_left -= (int64_t)(cpi->twopass.total_stats.duration *
|
|
|
|
|
two_pass_min_rate / 10000000.0);
|
|
|
|
|
|
|
|
|
|
// Calculate a minimum intra value to be used in determining the IIratio
|
|
|
|
|
@@ -1148,7 +1148,8 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
sum_iiratio += IIRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cpi->twopass.avg_iiratio = sum_iiratio / DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats->count);
|
|
|
|
|
cpi->twopass.avg_iiratio = sum_iiratio /
|
|
|
|
|
DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats.count);
|
|
|
|
|
|
|
|
|
|
// Reset file position
|
|
|
|
|
reset_fpf_position(cpi, start_pos);
|
|
|
|
|
@@ -1831,7 +1832,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
|
|
|
|
|
// where cpi->twopass.kf_group_bits is tied to cpi->twopass.bits_left.
|
|
|
|
|
// This is also important for short clips where there may only be one
|
|
|
|
|
// key frame.
|
|
|
|
|
if (cpi->twopass.frames_to_key >= (int)(cpi->twopass.total_stats->count -
|
|
|
|
|
if (cpi->twopass.frames_to_key >= (int)(cpi->twopass.total_stats.count -
|
|
|
|
|
cpi->common.current_video_frame)) {
|
|
|
|
|
cpi->twopass.kf_group_bits =
|
|
|
|
|
(cpi->twopass.bits_left > 0) ? cpi->twopass.bits_left : 0;
|
|
|
|
|
@@ -2099,7 +2100,7 @@ static int adjust_active_maxq(int old_maxqi, int new_maxqi) {
|
|
|
|
|
|
|
|
|
|
void vp9_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
int tmp_q;
|
|
|
|
|
int frames_left = (int)(cpi->twopass.total_stats->count -
|
|
|
|
|
int frames_left = (int)(cpi->twopass.total_stats.count -
|
|
|
|
|
cpi->common.current_video_frame);
|
|
|
|
|
|
|
|
|
|
FIRSTPASS_STATS this_frame;
|
|
|
|
|
@@ -2124,7 +2125,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
|
|
|
|
|
est_cq =
|
|
|
|
|
estimate_cq(cpi,
|
|
|
|
|
cpi->twopass.total_left_stats,
|
|
|
|
|
&cpi->twopass.total_left_stats,
|
|
|
|
|
(int)(cpi->twopass.bits_left / frames_left));
|
|
|
|
|
|
|
|
|
|
cpi->cq_target_quality = cpi->oxcf.cq_level;
|
|
|
|
|
@@ -2138,7 +2139,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
|
|
|
|
|
tmp_q = estimate_max_q(
|
|
|
|
|
cpi,
|
|
|
|
|
cpi->twopass.total_left_stats,
|
|
|
|
|
&cpi->twopass.total_left_stats,
|
|
|
|
|
(int)(cpi->twopass.bits_left / frames_left));
|
|
|
|
|
|
|
|
|
|
cpi->active_worst_quality = tmp_q;
|
|
|
|
|
@@ -2161,15 +2162,15 @@ void vp9_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
// radical adjustments to the allowed quantizer range just to use up a
|
|
|
|
|
// few surplus bits or get beneath the target rate.
|
|
|
|
|
else if ((cpi->common.current_video_frame <
|
|
|
|
|
(((unsigned int)cpi->twopass.total_stats->count * 255) >> 8)) &&
|
|
|
|
|
(((unsigned int)cpi->twopass.total_stats.count * 255) >> 8)) &&
|
|
|
|
|
((cpi->common.current_video_frame + cpi->baseline_gf_interval) <
|
|
|
|
|
(unsigned int)cpi->twopass.total_stats->count)) {
|
|
|
|
|
(unsigned int)cpi->twopass.total_stats.count)) {
|
|
|
|
|
if (frames_left < 1)
|
|
|
|
|
frames_left = 1;
|
|
|
|
|
|
|
|
|
|
tmp_q = estimate_max_q(
|
|
|
|
|
cpi,
|
|
|
|
|
cpi->twopass.total_left_stats,
|
|
|
|
|
&cpi->twopass.total_left_stats,
|
|
|
|
|
(int)(cpi->twopass.bits_left / frames_left));
|
|
|
|
|
|
|
|
|
|
// Make a damped adjustment to active max Q
|
|
|
|
|
@@ -2248,7 +2249,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
|
|
|
|
|
cpi->twopass.frames_to_key--;
|
|
|
|
|
|
|
|
|
|
// Update the total stats remaining structure
|
|
|
|
|
subtract_stats(cpi->twopass.total_left_stats, &this_frame);
|
|
|
|
|
subtract_stats(&cpi->twopass.total_left_stats, &this_frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int test_candidate_kf(VP9_COMP *cpi,
|
|
|
|
|
|