History

Simplify the logics of computing gf_group_err etc

Move the logics of computing gf_group_err, gf_group_raw_error, gf_group_noise, gf_group_skip_pct, gf_group_inactive_zone_rowsa, gf_group_inter, gf_group_motion into one for loop The behavior stays the same.

angiebird committed 7 years ago

Commit b255d471 parent 821db082 files · +36 −28Browse files

Unified · Split

2 files
  1. vp9/encoder/vp9_firstpass.c +28 −28
  2. vp9/encoder/vp9_firstpass.h +8 −0
vp9/encoder/vp9_firstpass.c+28−28
@@ -2450,15 +2450,18 @@ static void adjust_group_arnr_filter(VP9_COMP *cpi, double section_noise, · 2449 unmodified lines
24502450 #define ARF_ABS_ZOOM_THRESH 4.0
24512451
24522452 #define MAX_GF_BOOST 5400
2453−static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
2453+static void define_gf_group(VP9_COMP *cpi) {
24542454 VP9_COMMON *const cm = &cpi->common;
24552455 RATE_CONTROL *const rc = &cpi->rc;
24562456 VP9EncoderConfig *const oxcf = &cpi->oxcf;
24572457 TWO_PASS *const twopass = &cpi->twopass;
24582458 const FRAME_INFO *frame_info = &cpi->frame_info;
2459+ const FIRST_PASS_INFO *first_pass_info = &twopass->first_pass_info;
24592460 FIRSTPASS_STATS next_frame;
24602461 const FIRSTPASS_STATS *const start_pos = twopass->stats_in;
2462+ const int gf_start_show_idx = cm->current_video_frame;
24612463 int i;
2464+ int j;
24622465
24632466 double gf_group_err = 0.0;
24642467 double gf_group_raw_error = 0.0;
@@ -2489,6 +2492,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 24 unmodified lines
24892492 int64_t gf_group_bits;
24902493 int gf_arf_bits;
24912494 const int is_key_frame = frame_is_intra_only(cm);
2495+ // If this is a key frame or the overlay from a previous arf then
2496+ // the error score / cost of this frame has already been accounted for.
24922497 const int arf_active_or_kf = is_key_frame || rc->source_alt_ref_active;
24932498 int is_alt_ref_flash = 0;
24942499
@@ -2504,20 +2509,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 9 unmodified lines
25042509 vpx_clear_system_state();
25052510 vp9_zero(next_frame);
25062511
2507− // If this is a key frame or the overlay from a previous arf then
2508− // the error score / cost of this frame has already been accounted for.
2509− if (arf_active_or_kf) {
2510− double gf_first_frame_err = calc_norm_frame_score(
2511− oxcf, frame_info, this_frame, mean_mod_score, av_err);
2512− gf_group_err -= gf_first_frame_err;
2513− gf_group_raw_error -= this_frame->coded_error;
2514− gf_group_noise -= this_frame->frame_noise_energy;
2515− gf_group_skip_pct -= this_frame->intra_skip_pct;
2516− gf_group_inactive_zone_rows -= this_frame->inactive_zone_rows;
2517− gf_group_inter -= this_frame->pcnt_inter;
2518− gf_group_motion -= this_frame->pcnt_motion;
2519− }
2520−
25212512 // Motion breakout threshold for loop below depends on image size.
25222513 mv_ratio_accumulator_thresh =
25232514 (cpi->initial_height + cpi->initial_width) / 4.0;
@@ -2580,16 +2571,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 56 unmodified lines
25802571 const FIRSTPASS_STATS *next_next_frame;
25812572 ++i;
25822573
2583− // Accumulate error score of frames in this gf group.
2584− gf_group_err += calc_norm_frame_score(oxcf, frame_info, this_frame,
2585− mean_mod_score, av_err);
2586− gf_group_raw_error += this_frame->coded_error;
2587− gf_group_noise += this_frame->frame_noise_energy;
2588− gf_group_skip_pct += this_frame->intra_skip_pct;
2589− gf_group_inactive_zone_rows += this_frame->inactive_zone_rows;
2590− gf_group_inter += this_frame->pcnt_inter;
2591− gf_group_motion += this_frame->pcnt_motion;
2592−
25932574 if (EOF == input_stats(twopass, &next_frame)) break;
25942575
25952576 // Test for the case where there is a brief flash but the prediction
@@ -2658,8 +2639,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 62 unmodified lines
26582639 (sr_accumulator > gop_intra_factor * next_frame.intra_error))) {
26592640 break;
26602641 }
2661−
2662− *this_frame = next_frame;
26632642 }
26642643
26652644 // Was the group length constrained by the requirement for a new KF?
@@ -2729,6 +2708,27 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 63 unmodified lines
27292708 if (rc->source_alt_ref_pending)
27302709 is_alt_ref_flash = detect_flash(twopass, rc->baseline_gf_interval);
27312710
2711+ {
2712+ // If the first frame is a key frame or the overlay from a previous arf then
2713+ // the error score / cost of this frame has already been accounted for.
2714+ int start_idx = arf_active_or_kf ? 1 : 0;
2715+ int num_show_frames = i;
2716+ for (j = start_idx; j < num_show_frames; ++j) {
2717+ int show_idx = gf_start_show_idx + j;
2718+ const FIRSTPASS_STATS *frame_stats =
2719+ fps_get_frame_stats(first_pass_info, show_idx);
2720+ // Accumulate error score of frames in this gf group.
2721+ gf_group_err += calc_norm_frame_score(oxcf, frame_info, frame_stats,
2722+ mean_mod_score, av_err);
2723+ gf_group_raw_error += frame_stats->coded_error;
2724+ gf_group_noise += frame_stats->frame_noise_energy;
2725+ gf_group_skip_pct += frame_stats->intra_skip_pct;
2726+ gf_group_inactive_zone_rows += frame_stats->inactive_zone_rows;
2727+ gf_group_inter += frame_stats->pcnt_inter;
2728+ gf_group_motion += frame_stats->pcnt_motion;
2729+ }
2730+ }
2731+
27322732 // Calculate the bits to be allocated to the gf/arf group as a whole
27332733 gf_group_bits = calculate_total_gf_group_bits(cpi, gf_group_err);
27342734
@@ -3396,7 +3396,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { · 661 unmodified lines
33963396
33973397 // Define a new GF/ARF group. (Should always enter here for key frames).
33983398 if (rc->frames_till_gf_update_due == 0) {
3399− define_gf_group(cpi, &this_frame);
3399+ define_gf_group(cpi);
34003400
34013401 rc->frames_till_gf_update_due = rc->baseline_gf_interval;
34023402
vp9/encoder/vp9_firstpass.h+8−0
@@ -158,6 +158,14 @@ static INLINE void fps_init_first_pass_info(FIRST_PASS_INFO *first_pass_info, · 157 unmodified lines
158158 first_pass_info->num_frames = num_frames;
159159 }
160160
161+static INLINE const FIRSTPASS_STATS *fps_get_frame_stats(
162+ const FIRST_PASS_INFO *first_pass_info, int show_idx) {
163+ if (show_idx >= first_pass_info->num_frames) {
164+ return NULL;
165+ }
166+ return &first_pass_info->stats[show_idx];
167+}
168+
161169 typedef struct {
162170 unsigned int section_intra_rating;
163171 unsigned int key_frame_section_intra_rating;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t