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
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;
25092501 const double av_err = get_distribution_av_err(cpi, twopass);
25102502 const double mean_mod_score = twopass->mean_mod_score;
25112503 unsigned int allow_alt_ref = is_altref_enabled(cpi);
25122504
2513− int flash_detected;
25142505 int active_max_gf_interval;
25152506 int active_min_gf_interval;
25162507 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
25322523
25332524 vpx_clear_system_state();
25342525
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−
25402526 // Set a maximum and minimum interval for the GF group.
25412527 // If the image appears almost completely static we can extend beyond this.
25422528 {
@@ -2590,87 +2576,101 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { · 47 unmodified lines
25902576 }
25912577
25922578 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;
2579+ {
2580+ double loop_decay_rate = 1.00;
2581+ double mv_ratio_accumulator = 0.0;
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+ }
25972600
2598− next_frame = fps_get_frame_stats(first_pass_info, gf_start_show_idx + i);
2599− if (next_frame == NULL) {
2600− break;
2601− }
2601+ // Test for the case where there is a brief flash but the prediction
2602+ // quality back to an earlier frame is then restored.
2603+ next_next_frame =
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);
26022606
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);
2607+ // Update the motion related elements to the boost calculation.
2608+ accumulate_frame_motion_stats(
2609+ next_frame, &this_frame_mv_in_out, &mv_in_out_accumulator,
2610+ &abs_mv_in_out_accumulator, &mv_ratio_accumulator);
26082611
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);
2612+ // Monitor for static sections.
2613+ if ((rc->frames_since_key + i - 1) > 1) {
2614+ zero_motion_accumulator =
2615+ VPXMIN(zero_motion_accumulator,
2616+ get_zero_motion_factor(frame_info, next_frame));
2617+ }
26132618
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− }
2619+ // Accumulate the effect of prediction quality decay.
2620+ if (!flash_detected) {
2621+ double last_loop_decay_rate = loop_decay_rate;
2622+ loop_decay_rate = get_prediction_decay_rate(frame_info, next_frame);
2623+
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+ }
26202635
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;
2636+ // Update the accumulator for second ref error difference.
2637+ // This is intended to give an indication of how much the coded error is
2638+ // increasing over time.
2639+ if (i == 1) {
2640+ sr_accumulator += next_frame->coded_error;
2641+ } else {
2642+ sr_accumulator +=
2643+ (next_frame->sr_coded_error - next_frame->coded_error);
26352644 }
26362645 }
26372646
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);
2647+ // Break out conditions.
2648+ // Break at maximum of active_max_gf_interval unless almost totally
2649+ // static.
2650+ //
2651+ // Note that the addition of a test of rc->source_alt_ref_active is
2652+ // deliberate. The effect of this is that after a normal altref group even
2653+ // if the material is static there will be one normal length GF group
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;
26462673 }
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;
26742674 }
26752675 }
26762676

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