History

Merge changes I2acc7d6b,I560dccfc,I3fb23f5c,Ifa24a501

* changes: Rename num_show_frames by num_coding_frames Use compute_arf_boost() in define_gf_group() Localize av_err mean_mod_score in define_gf_group Move code of deciding gop size into brackets

Angie Chiang committed 7 years ago

Commit 454877d2 parents 2be0ee5 ab7974d1 file · +100 −95Browse files

Unified · Split

vp9/encoder/vp9_firstpass.c+100−95
@@ -2496,21 +2496,10 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 2495 unmodified lines
24962496 double gf_group_inter = 0.0;
24972497 double gf_group_motion = 0.0;
24982498
2499− double mv_ratio_accumulator = 0.0;
25002499 double zero_motion_accumulator = 1.0;
2501− double loop_decay_rate = 1.00;
25022500
2503− double this_frame_mv_in_out = 0.0;
2504− double mv_in_out_accumulator = 0.0;
2505− double abs_mv_in_out_accumulator = 0.0;
2506− double mv_ratio_accumulator_thresh;
2507− double abs_mv_in_out_thresh;
2508− double sr_accumulator = 0.0;
2509− const double av_err = get_distribution_av_err(cpi, twopass);
2510− const double mean_mod_score = twopass->mean_mod_score;
25112501 unsigned int allow_alt_ref = is_altref_enabled(cpi);
25122502
2513− int flash_detected;
25142503 int active_max_gf_interval;
25152504 int active_min_gf_interval;
25162505 int64_t gf_group_bits;
@@ -2532,11 +2521,6 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 15 unmodified lines
25322521
25332522 vpx_clear_system_state();
25342523
2535− // Motion breakout threshold for loop below depends on image size.
2536− mv_ratio_accumulator_thresh =
2537− (cpi->initial_height + cpi->initial_width) / 4.0;
2538− abs_mv_in_out_thresh = ARF_ABS_ZOOM_THRESH;
2539−
25402524 // Set a maximum and minimum interval for the GF group.
25412525 // If the image appears almost completely static we can extend beyond this.
25422526 {
@@ -2590,87 +2574,101 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 47 unmodified lines
25902574 }
25912575
25922576 i = 0;
2593− while (i < rc->static_scene_max_gf_interval && i < rc->frames_to_key) {
2594− const FIRSTPASS_STATS *next_next_frame;
2595− const FIRSTPASS_STATS *next_frame;
2596− ++i;
2577+ {
2578+ double loop_decay_rate = 1.00;
2579+ double mv_ratio_accumulator = 0.0;
2580+ double this_frame_mv_in_out = 0.0;
2581+ double mv_in_out_accumulator = 0.0;
2582+ double abs_mv_in_out_accumulator = 0.0;
2583+ double sr_accumulator = 0.0;
2584+ // Motion breakout threshold for loop below depends on image size.
2585+ double mv_ratio_accumulator_thresh =
2586+ (cpi->initial_height + cpi->initial_width) / 4.0;
2587+
2588+ while (i < rc->static_scene_max_gf_interval && i < rc->frames_to_key) {
2589+ const FIRSTPASS_STATS *next_next_frame;
2590+ const FIRSTPASS_STATS *next_frame;
2591+ int flash_detected;
2592+ ++i;
2593+
2594+ next_frame = fps_get_frame_stats(first_pass_info, gf_start_show_idx + i);
2595+ if (next_frame == NULL) {
2596+ break;
2597+ }
25972598
2598− next_frame = fps_get_frame_stats(first_pass_info, gf_start_show_idx + i);
2599− if (next_frame == NULL) {
2600− break;
2601− }
2599+ // Test for the case where there is a brief flash but the prediction
2600+ // quality back to an earlier frame is then restored.
2601+ next_next_frame =
2602+ fps_get_frame_stats(first_pass_info, gf_start_show_idx + i + 1);
2603+ flash_detected = detect_flash_from_frame_stats(next_next_frame);
26022604
2603− // Test for the case where there is a brief flash but the prediction
2604− // quality back to an earlier frame is then restored.
2605− next_next_frame =
2606− fps_get_frame_stats(first_pass_info, gf_start_show_idx + i + 1);
2607− flash_detected = detect_flash_from_frame_stats(next_next_frame);
2605+ // Update the motion related elements to the boost calculation.
2606+ accumulate_frame_motion_stats(
2607+ next_frame, &this_frame_mv_in_out, &mv_in_out_accumulator,
2608+ &abs_mv_in_out_accumulator, &mv_ratio_accumulator);
26082609
2609− // Update the motion related elements to the boost calculation.
2610− accumulate_frame_motion_stats(
2611− next_frame, &this_frame_mv_in_out, &mv_in_out_accumulator,
2612− &abs_mv_in_out_accumulator, &mv_ratio_accumulator);
2610+ // Monitor for static sections.
2611+ if ((rc->frames_since_key + i - 1) > 1) {
2612+ zero_motion_accumulator =
2613+ VPXMIN(zero_motion_accumulator,
2614+ get_zero_motion_factor(frame_info, next_frame));
2615+ }
26132616
2614− // Monitor for static sections.
2615− if ((rc->frames_since_key + i - 1) > 1) {
2616− zero_motion_accumulator =
2617− VPXMIN(zero_motion_accumulator,
2618− get_zero_motion_factor(frame_info, next_frame));
2619− }
2617+ // Accumulate the effect of prediction quality decay.
2618+ if (!flash_detected) {
2619+ double last_loop_decay_rate = loop_decay_rate;
2620+ loop_decay_rate = get_prediction_decay_rate(frame_info, next_frame);
2621+
2622+ // Break clause to detect very still sections after motion. For example,
2623+ // a static image after a fade or other transition.
2624+ if (i > rc->min_gf_interval && loop_decay_rate >= 0.999 &&
2625+ last_loop_decay_rate < 0.9) {
2626+ int still_interval = 5;
2627+ if (check_transition_to_still(first_pass_info, gf_start_show_idx + i,
2628+ still_interval)) {
2629+ allow_alt_ref = 0;
2630+ break;
2631+ }
2632+ }
26202633
2621− // Accumulate the effect of prediction quality decay.
2622− if (!flash_detected) {
2623− double last_loop_decay_rate = loop_decay_rate;
2624− loop_decay_rate = get_prediction_decay_rate(frame_info, next_frame);
2625−
2626− // Break clause to detect very still sections after motion. For example,
2627− // a static image after a fade or other transition.
2628− if (i > rc->min_gf_interval && loop_decay_rate >= 0.999 &&
2629− last_loop_decay_rate < 0.9) {
2630− int still_interval = 5;
2631− if (check_transition_to_still(first_pass_info, gf_start_show_idx + i,
2632− still_interval)) {
2633− allow_alt_ref = 0;
2634− break;
2634+ // Update the accumulator for second ref error difference.
2635+ // This is intended to give an indication of how much the coded error is
2636+ // increasing over time.
2637+ if (i == 1) {
2638+ sr_accumulator += next_frame->coded_error;
2639+ } else {
2640+ sr_accumulator +=
2641+ (next_frame->sr_coded_error - next_frame->coded_error);
26352642 }
26362643 }
26372644
2638− // Update the accumulator for second ref error difference.
2639− // This is intended to give an indication of how much the coded error is
2640− // increasing over time.
2641− if (i == 1) {
2642− sr_accumulator += next_frame->coded_error;
2643− } else {
2644− sr_accumulator +=
2645− (next_frame->sr_coded_error - next_frame->coded_error);
2645+ // Break out conditions.
2646+ // Break at maximum of active_max_gf_interval unless almost totally
2647+ // static.
2648+ //
2649+ // Note that the addition of a test of rc->source_alt_ref_active is
2650+ // deliberate. The effect of this is that after a normal altref group even
2651+ // if the material is static there will be one normal length GF group
2652+ // before allowing longer GF groups. The reason for this is that in cases
2653+ // such as slide shows where slides are separated by a complex transition
2654+ // such as a fade, the arf group spanning the transition may not be coded
2655+ // at a very high quality and hence this frame (with its overlay) is a
2656+ // poor golden frame to use for an extended group.
2657+ if ((i >= active_max_gf_interval) &&
2658+ ((zero_motion_accumulator < 0.995) || (rc->source_alt_ref_active))) {
2659+ break;
2660+ }
2661+ if (
2662+ // Don't break out with a very short interval.
2663+ (i >= active_min_gf_interval) &&
2664+ // If possible dont break very close to a kf
2665+ ((rc->frames_to_key - i) >= rc->min_gf_interval) && (i & 0x01) &&
2666+ (!flash_detected) &&
2667+ ((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
2668+ (abs_mv_in_out_accumulator > ARF_ABS_ZOOM_THRESH) ||
2669+ (sr_accumulator > gop_intra_factor * next_frame->intra_error))) {
2670+ break;
26462671 }
2647− }
2648−
2649− // Break out conditions.
2650− // Break at maximum of active_max_gf_interval unless almost totally static.
2651− //
2652− // Note that the addition of a test of rc->source_alt_ref_active is
2653− // deliberate. The effect of this is that after a normal altref group even
2654− // if the material is static there will be one normal length GF group
2655− // before allowing longer GF groups. The reason for this is that in cases
2656− // such as slide shows where slides are separated by a complex transition
2657− // such as a fade, the arf group spanning the transition may not be coded
2658− // at a very high quality and hence this frame (with its overlay) is a
2659− // poor golden frame to use for an extended group.
2660− if ((i >= active_max_gf_interval) &&
2661− ((zero_motion_accumulator < 0.995) || (rc->source_alt_ref_active))) {
2662− break;
2663− }
2664− if (
2665− // Don't break out with a very short interval.
2666− (i >= active_min_gf_interval) &&
2667− // If possible dont break very close to a kf
2668− ((rc->frames_to_key - i) >= rc->min_gf_interval) && (i & 0x01) &&
2669− (!flash_detected) &&
2670− ((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
2671− (abs_mv_in_out_accumulator > abs_mv_in_out_thresh) ||
2672− (sr_accumulator > gop_intra_factor * next_frame->intra_error))) {
2673− break;
26742672 }
26752673 }
26762674
@@ -2696,8 +2694,16 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 19 unmodified lines
26962694 b_frames, avg_inter_frame_qindex);
26972695 rc->source_alt_ref_pending = 1;
26982696 } else {
2699− reset_fpf_position(twopass, start_pos);
2700− rc->gfu_boost = VPXMIN(MAX_GF_BOOST, calc_arf_boost(cpi, (i - 1), 0));
2697+ const int f_frames = i - 1;
2698+ const int b_frames = 0;
2699+ const int avg_inter_frame_qindex = rc->avg_frame_qindex[INTER_FRAME];
2700+ // TODO(angiebird): figure out why arf's location is assigned this way
2701+ const int gld_show_idx =
2702+ VPXMIN(gf_start_show_idx + 1, fps_get_num_frames(first_pass_info));
2703+ const int arf_boost =
2704+ compute_arf_boost(frame_info, first_pass_info, gld_show_idx, f_frames,
2705+ b_frames, avg_inter_frame_qindex);
2706+ rc->gfu_boost = VPXMIN(MAX_GF_BOOST, arf_boost);
27012707 rc->source_alt_ref_pending = 0;
27022708 }
27032709
@@ -2742,18 +2748,17 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 38 unmodified lines
27422748
27432749 rc->baseline_gf_interval = i - rc->source_alt_ref_pending;
27442750
2745− // Reset the file position.
2746− reset_fpf_position(twopass, start_pos);
2747−
27482751 if (rc->source_alt_ref_pending)
27492752 is_alt_ref_flash = detect_flash(twopass, rc->baseline_gf_interval);
27502753
27512754 {
2755+ const double av_err = get_distribution_av_err(cpi, twopass);
2756+ const double mean_mod_score = twopass->mean_mod_score;
27522757 // If the first frame is a key frame or the overlay from a previous arf then
27532758 // the error score / cost of this frame has already been accounted for.
27542759 int start_idx = arf_active_or_kf ? 1 : 0;
2755− int num_show_frames = i;
2756− for (j = start_idx; j < num_show_frames; ++j) {
2760+ int num_coding_frames = i;
2761+ for (j = start_idx; j < num_coding_frames; ++j) {
27572762 int show_idx = gf_start_show_idx + j;
27582763 const FIRSTPASS_STATS *frame_stats =
27592764 fps_get_frame_stats(first_pass_info, show_idx);

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