Unified · Split
| @@ -3098,51 +3098,56 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { · 3097 unmodified lines | |||
| 3098 | // Initialize the decay rates for the recent frames to check | 3098 | // Initialize the decay rates for the recent frames to check |
| 3099 | for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) recent_loop_decay[j] = 1.0; | 3099 | for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) recent_loop_decay[j] = 1.0; |
| 3100 | 3100 | ||
| 3101 | // Find the next keyframe. | 3101 | { |
| 3102 | if (!oxcf->auto_key) { | 3102 | int frames_to_key; |
| 3103 | rc->frames_to_key = first_pass_info->num_frames - kf_show_idx; | 3103 | int max_frames_to_key = first_pass_info->num_frames - kf_show_idx; |
| 3104 | rc->frames_to_key = VPXMIN(oxcf->key_freq, rc->frames_to_key); | 3104 | max_frames_to_key = VPXMIN(max_frames_to_key, oxcf->key_freq); |
| 3105 | } else { | 3105 | // Find the next keyframe. |
| 3106 | int i = 0; | 3106 | if (!oxcf->auto_key) { |
| 3107 | while (kf_show_idx + i + 1 < first_pass_info->num_frames && | 3107 | frames_to_key = max_frames_to_key; |
| 3108 | rc->frames_to_key < cpi->oxcf.key_freq) { | 3108 | } else { |
| 3109 | // Provided that we are not at the end of the file... | 3109 | frames_to_key = 1; |
| 3110 | if (kf_show_idx + i + 2 < first_pass_info->num_frames) { | 3110 | while (frames_to_key < max_frames_to_key) { |
| 3111 | double loop_decay_rate; | 3111 | // Provided that we are not at the end of the file... |
| 3112 | const FIRSTPASS_STATS *next_frame = | 3112 | if (kf_show_idx + frames_to_key + 1 < first_pass_info->num_frames) { |
| 3113 | fps_get_frame_stats(first_pass_info, kf_show_idx + i + 2); | 3113 | double loop_decay_rate; |
| 3114 | 3114 | const FIRSTPASS_STATS *next_frame = fps_get_frame_stats( | |
| 3115 | // Check for a scene cut. | 3115 | first_pass_info, kf_show_idx + frames_to_key + 1); |
| 3116 | if (test_candidate_kf(first_pass_info, kf_show_idx + i + 1)) break; | 3116 | |
| 3117 | 3117 | // Check for a scene cut. | |
| 3118 | // How fast is the prediction quality decaying? | 3118 | if (test_candidate_kf(first_pass_info, kf_show_idx + frames_to_key)) |
| 3119 | loop_decay_rate = | ||
| 3120 | get_prediction_decay_rate(&cpi->frame_info, next_frame); | ||
| 3121 | |||
| 3122 | // We want to know something about the recent past... rather than | ||
| 3123 | // as used elsewhere where we are concerned with decay in prediction | ||
| 3124 | // quality since the last GF or KF. | ||
| 3125 | recent_loop_decay[i % FRAMES_TO_CHECK_DECAY] = loop_decay_rate; | ||
| 3126 | decay_accumulator = 1.0; | ||
| 3127 | for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) | ||
| 3128 | decay_accumulator *= recent_loop_decay[j]; | ||
| 3129 | |||
| 3130 | // Special check for transition or high motion followed by a | ||
| 3131 | // static scene. | ||
| 3132 | if (i > rc->min_gf_interval && loop_decay_rate >= 0.999 && | ||
| 3133 | decay_accumulator < 0.9) { | ||
| 3134 | int still_interval = oxcf->key_freq - i; | ||
| 3135 | // TODO(angiebird): Figure out why we use "+1" here | ||
| 3136 | int show_idx = kf_show_idx + i + 1; | ||
| 3137 | if (check_transition_to_still(first_pass_info, show_idx, | ||
| 3138 | still_interval)) { | ||
| 3139 | break; | 3119 | break; |
| 3120 | |||
| 3121 | // How fast is the prediction quality decaying? | ||
| 3122 | loop_decay_rate = | ||
| 3123 | get_prediction_decay_rate(&cpi->frame_info, next_frame); | ||
| 3124 | |||
| 3125 | // We want to know something about the recent past... rather than | ||
| 3126 | // as used elsewhere where we are concerned with decay in prediction | ||
| 3127 | // quality since the last GF or KF. | ||
| 3128 | recent_loop_decay[(frames_to_key - 1) % FRAMES_TO_CHECK_DECAY] = | ||
| 3129 | loop_decay_rate; | ||
| 3130 | decay_accumulator = 1.0; | ||
| 3131 | for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) | ||
| 3132 | decay_accumulator *= recent_loop_decay[j]; | ||
| 3133 | |||
| 3134 | // Special check for transition or high motion followed by a | ||
| 3135 | // static scene. | ||
| 3136 | if ((frames_to_key - 1) > rc->min_gf_interval && | ||
| 3137 | loop_decay_rate >= 0.999 && decay_accumulator < 0.9) { | ||
| 3138 | int still_interval = oxcf->key_freq - (frames_to_key - 1); | ||
| 3139 | // TODO(angiebird): Figure out why we use "+1" here | ||
| 3140 | int show_idx = kf_show_idx + frames_to_key; | ||
| 3141 | if (check_transition_to_still(first_pass_info, show_idx, | ||
| 3142 | still_interval)) { | ||
| 3143 | break; | ||
| 3144 | } | ||
| 3140 | } | 3145 | } |
| 3141 | } | 3146 | } |
| 3147 | ++frames_to_key; | ||
| 3142 | } | 3148 | } |
| 3143 | ++rc->frames_to_key; | ||
| 3144 | ++i; | ||
| 3145 | } | 3149 | } |
| 3150 | rc->frames_to_key = frames_to_key; | ||
| 3146 | } | 3151 | } |
| 3147 | 3152 | ||
| 3148 | // If there is a max kf interval set by the user we must obey it. | 3153 | // If there is a max kf interval set by the user we must obey it. |