Change key frame detection criteria

(a). Port in a feature from VP9 to detect slide transtions.
(b). Modify a threshold to remove false positive keyframes reported
in the bug below.

BUG=aomedia:2926

STATS_CHANGED

Change-Id: I847f4323a2fb665de9283a85d72f2b677da47612
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 7f506f4..b1c52bd 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -2627,7 +2627,7 @@
 #define VERY_LOW_INTER_THRESH 0.05
 // Maximum threshold for the relative ratio of intra error score vs best
 // inter error score.
-#define KF_II_ERR_THRESHOLD 2.5
+#define KF_II_ERR_THRESHOLD 1.9
 // In real scene cuts there is almost always a sharp change in the intra
 // or inter error score.
 #define ERR_CHANGE_THRESHOLD 0.4
@@ -2635,6 +2635,25 @@
 // ratio in the next frame.
 #define II_IMPROVEMENT_THRESHOLD 3.5
 #define KF_II_MAX 128.0
+// Intra / Inter threshold very low
+#define VERY_LOW_II 1.5
+// Clean slide transitions we expect a sharp single frame spike in error.
+#define ERROR_SPIKE 5.0
+
+// Slide show transition detection.
+// Tests for case where there is very low error either side of the current frame
+// but much higher just for this frame. This can help detect key frames in
+// slide shows even where the slides are pictures of different sizes.
+// Also requires that intra and inter errors are very similar to help eliminate
+// harmful false positives.
+// It will not help if the transition is a fade or other multi-frame effect.
+static int slide_transition(const FIRSTPASS_STATS *this_frame,
+                            const FIRSTPASS_STATS *last_frame,
+                            const FIRSTPASS_STATS *next_frame) {
+  return (this_frame->intra_error < (this_frame->coded_error * VERY_LOW_II)) &&
+         (this_frame->coded_error > (last_frame->coded_error * ERROR_SPIKE)) &&
+         (this_frame->coded_error > (next_frame->coded_error * ERROR_SPIKE));
+}
 
 // Threshold for use of the lagging second reference frame. High second ref
 // usage may point to a transient event like a flash or occlusion rather than
@@ -2692,6 +2711,7 @@
       (this_frame->pcnt_second_ref < second_ref_usage_thresh) &&
       (next_frame->pcnt_second_ref < second_ref_usage_thresh) &&
       ((this_frame->pcnt_inter < VERY_LOW_INTER_THRESH) ||
+       slide_transition(this_frame, last_frame, next_frame) ||
        ((pcnt_intra > MIN_INTRA_LEVEL) &&
         (pcnt_intra > (INTRA_VS_INTER_THRESH * modified_pcnt_inter)) &&
         ((this_frame->intra_error /