History

Move code of deciding gop size into brackets

Identify the internal params used for deciding gop size

angiebird committed 7 years ago

Commit 8f730ce1 parent 9d377ff1 file · +86 −86Browse files

Unified · Split

vp9/encoder/vp9_firstpass.c+86−86
@@ -2496,21 +2496,12 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 2495 unmodified lines
2496 double gf_group_inter = 0.0;2496 double gf_group_inter = 0.0;
2497 double gf_group_motion = 0.0;2497 double gf_group_motion = 0.0;
2498 2498
2499 double mv_ratio_accumulator = 0.0;
2500 double zero_motion_accumulator = 1.0;2499 double zero_motion_accumulator = 1.0;
2501 double loop_decay_rate = 1.00;
2502 2500
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);2501 const double av_err = get_distribution_av_err(cpi, twopass);
2510 const double mean_mod_score = twopass->mean_mod_score;2502 const double mean_mod_score = twopass->mean_mod_score;
2511 unsigned int allow_alt_ref = is_altref_enabled(cpi);2503 unsigned int allow_alt_ref = is_altref_enabled(cpi);
2512 2504
2513 int flash_detected;
2514 int active_max_gf_interval;2505 int active_max_gf_interval;
2515 int active_min_gf_interval;2506 int active_min_gf_interval;
2516 int64_t gf_group_bits;2507 int64_t gf_group_bits;
@@ -2532,11 +2523,6 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 15 unmodified lines
2532 2523
2533 vpx_clear_system_state();2524 vpx_clear_system_state();
2534 2525
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
2540 // Set a maximum and minimum interval for the GF group.2526 // Set a maximum and minimum interval for the GF group.
2541 // If the image appears almost completely static we can extend beyond this.2527 // If the image appears almost completely static we can extend beyond this.
2542 {2528 {
@@ -2590,87 +2576,101 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 47 unmodified lines
2590 }2576 }
2591 2577
2592 i = 0;2578 i = 0;
2593 while (i < rc->static_scene_max_gf_interval && i < rc->frames_to_key) {2579 {
2594 const FIRSTPASS_STATS *next_next_frame;2580 double loop_decay_rate = 1.00;
2595 const FIRSTPASS_STATS *next_frame;2581 double mv_ratio_accumulator = 0.0;
2596 ++i;2582 double this_frame_mv_in_out = 0.0;
2583 double mv_in_out_accumulator = 0.0;
2584 double abs_mv_in_out_accumulator = 0.0;
2585 double sr_accumulator = 0.0;
2586 // Motion breakout threshold for loop below depends on image size.
2587 double mv_ratio_accumulator_thresh =
2588 (cpi->initial_height + cpi->initial_width) / 4.0;
2589
2590 while (i < rc->static_scene_max_gf_interval && i < rc->frames_to_key) {
2591 const FIRSTPASS_STATS *next_next_frame;
2592 const FIRSTPASS_STATS *next_frame;
2593 int flash_detected;
2594 ++i;
2595
2596 next_frame = fps_get_frame_stats(first_pass_info, gf_start_show_idx + i);
2597 if (next_frame == NULL) {
2598 break;
2599 }
2597 2600
2598 next_frame = fps_get_frame_stats(first_pass_info, gf_start_show_idx + i);2601 // Test for the case where there is a brief flash but the prediction
2599 if (next_frame == NULL) {2602 // quality back to an earlier frame is then restored.
2600 break;2603 next_next_frame =
2601 }2604 fps_get_frame_stats(first_pass_info, gf_start_show_idx + i + 1);
2605 flash_detected = detect_flash_from_frame_stats(next_next_frame);
2602 2606
2603 // Test for the case where there is a brief flash but the prediction2607 // Update the motion related elements to the boost calculation.
2604 // quality back to an earlier frame is then restored.2608 accumulate_frame_motion_stats(
2605 next_next_frame =2609 next_frame, &this_frame_mv_in_out, &mv_in_out_accumulator,
2606 fps_get_frame_stats(first_pass_info, gf_start_show_idx + i + 1);2610 &abs_mv_in_out_accumulator, &mv_ratio_accumulator);
2607 flash_detected = detect_flash_from_frame_stats(next_next_frame);
2608 2611
2609 // Update the motion related elements to the boost calculation.2612 // Monitor for static sections.
2610 accumulate_frame_motion_stats(2613 if ((rc->frames_since_key + i - 1) > 1) {
2611 next_frame, &this_frame_mv_in_out, &mv_in_out_accumulator,2614 zero_motion_accumulator =
2612 &abs_mv_in_out_accumulator, &mv_ratio_accumulator);2615 VPXMIN(zero_motion_accumulator,
2616 get_zero_motion_factor(frame_info, next_frame));
2617 }
2613 2618
2614 // Monitor for static sections.2619 // Accumulate the effect of prediction quality decay.
2615 if ((rc->frames_since_key + i - 1) > 1) {2620 if (!flash_detected) {
2616 zero_motion_accumulator =2621 double last_loop_decay_rate = loop_decay_rate;
2617 VPXMIN(zero_motion_accumulator,2622 loop_decay_rate = get_prediction_decay_rate(frame_info, next_frame);
2618 get_zero_motion_factor(frame_info, next_frame));2623
2619 }2624 // Break clause to detect very still sections after motion. For example,
2625 // a static image after a fade or other transition.
2626 if (i > rc->min_gf_interval && loop_decay_rate >= 0.999 &&
2627 last_loop_decay_rate < 0.9) {
2628 int still_interval = 5;
2629 if (check_transition_to_still(first_pass_info, gf_start_show_idx + i,
2630 still_interval)) {
2631 allow_alt_ref = 0;
2632 break;
2633 }
2634 }
2620 2635
2621 // Accumulate the effect of prediction quality decay.2636 // Update the accumulator for second ref error difference.
2622 if (!flash_detected) {2637 // This is intended to give an indication of how much the coded error is
2623 double last_loop_decay_rate = loop_decay_rate;2638 // increasing over time.
2624 loop_decay_rate = get_prediction_decay_rate(frame_info, next_frame);2639 if (i == 1) {
2625 2640 sr_accumulator += next_frame->coded_error;
2626 // Break clause to detect very still sections after motion. For example,2641 } else {
2627 // a static image after a fade or other transition.2642 sr_accumulator +=
2628 if (i > rc->min_gf_interval && loop_decay_rate >= 0.999 &&2643 (next_frame->sr_coded_error - next_frame->coded_error);
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;
2635 }2644 }
2636 }2645 }
2637 2646
2638 // Update the accumulator for second ref error difference.2647 // Break out conditions.
2639 // This is intended to give an indication of how much the coded error is2648 // Break at maximum of active_max_gf_interval unless almost totally
2640 // increasing over time.2649 // static.
2641 if (i == 1) {2650 //
2642 sr_accumulator += next_frame->coded_error;2651 // Note that the addition of a test of rc->source_alt_ref_active is
2643 } else {2652 // deliberate. The effect of this is that after a normal altref group even
2644 sr_accumulator +=2653 // if the material is static there will be one normal length GF group
2645 (next_frame->sr_coded_error - next_frame->coded_error);2654 // before allowing longer GF groups. The reason for this is that in cases
2655 // such as slide shows where slides are separated by a complex transition
2656 // such as a fade, the arf group spanning the transition may not be coded
2657 // at a very high quality and hence this frame (with its overlay) is a
2658 // poor golden frame to use for an extended group.
2659 if ((i >= active_max_gf_interval) &&
2660 ((zero_motion_accumulator < 0.995) || (rc->source_alt_ref_active))) {
2661 break;
2662 }
2663 if (
2664 // Don't break out with a very short interval.
2665 (i >= active_min_gf_interval) &&
2666 // If possible dont break very close to a kf
2667 ((rc->frames_to_key - i) >= rc->min_gf_interval) && (i & 0x01) &&
2668 (!flash_detected) &&
2669 ((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
2670 (abs_mv_in_out_accumulator > ARF_ABS_ZOOM_THRESH) ||
2671 (sr_accumulator > gop_intra_factor * next_frame->intra_error))) {
2672 break;
2646 }2673 }
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;
2674 }2674 }
2675 }2675 }
2676 2676

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