Commit bc08a58571 for aom

commit bc08a5857109a23e353e0cde66b7a10f3a43aeae
Author: Lin Zheng <linzhen@google.com>
Date:   Mon Oct 26 21:34:42 2026 +0000

    Enable screen content tools on high-variance keyframes

    When disable_extra_sc_testing skips two-pass keyframe testing, enable
    screen content tools if sc_high_var_blocks is detected. It helps few
    corner-case clips in ugc1080p testset for speed 4 - 6.

    Change-Id: I3a16b86459fe1710012b0ebbb8ad3ec3e0625355

diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 3633b2ffc6..0795123ee3 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2083,6 +2083,9 @@ static void estimate_screen_content(AV1_COMP *cpi, FeatureFlags *features) {
   cpi->is_screen_content_type =
       features->allow_intrabc || (counts_1 * kBlockArea * 10 > area * 4 &&
                                   counts_2 * kBlockArea * 30 > area);
+  cpi->sc_high_var_blocks = !features->allow_screen_content_tools &&
+                            counts_1 * kBlockArea * 15 > area &&
+                            counts_2 * kBlockArea * 15 > area;
 }

 // Macro that helps debug the screen content mode 2 mechanism
@@ -2424,6 +2427,7 @@ static void estimate_screen_content_antialiasing_aware(AV1_COMP *cpi,

 void av1_set_screen_content_options(AV1_COMP *cpi, FeatureFlags *features) {
   const AV1_COMMON *const cm = &cpi->common;
+  cpi->sc_high_var_blocks = 0;

   if (cm->seq_params->force_screen_content_tools != 2) {
     features->allow_screen_content_tools = features->allow_intrabc =
@@ -3317,8 +3321,18 @@ static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest,

 #if !CONFIG_RD_COMMAND
   // Determine whether to use screen content tools using two fast encoding.
-  if (!cpi->sf.hl_sf.disable_extra_sc_testing && !cpi->use_ducky_encode)
+  if (!cpi->sf.hl_sf.disable_extra_sc_testing && !cpi->use_ducky_encode) {
     av1_determine_sc_tools_with_encoding(cpi, q);
+  } else if (cpi->sf.hl_sf.disable_extra_sc_testing == 1 &&
+             !cpi->use_ducky_encode &&
+             cm->current_frame.frame_type == KEY_FRAME &&
+             !cpi->use_screen_content_tools && cpi->sc_high_var_blocks) {
+    // Fallback for keyframes when two-pass encoding test is skipped: enable
+    // screen content tools if block histogram detected high-variance blocks.
+    cm->features.allow_screen_content_tools = 1;
+    cpi->use_screen_content_tools = 1;
+    cpi->is_screen_content_type = 1;
+  }
 #endif  // !CONFIG_RD_COMMAND

 #if CONFIG_TUNE_VMAF
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index db6e16367d..19936386bf 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -3407,6 +3407,12 @@ typedef struct AV1_COMP {
    */
   int is_screen_content_type;

+  /*!
+   * A flag to indicate moderate screen content blocks with high variance when
+   * allow_screen_content_tools is not directly enabled by the strict threshold.
+   */
+  int sc_high_var_blocks;
+
 #if CONFIG_COLLECT_PARTITION_STATS
   /*!
    * Accumulates the partition timing stat over the whole frame.