PR #25252 opened by kierank
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25252
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25252.patch

When the bottom-left (or top-right) reference samples cross the picture
edge, the part outside the picture was filled from the last in-picture
sample before the constrained_intra_pred substitution, which only runs up
to the picture edge. If that sample belongs to an inter CU, its raw value
stayed in the out-of-picture part instead of the substituted one
(8.4.4.2.2), and the prediction no longer matched the encoder or HM.

Seen with x265 at 1080p, 64x64 CTBs and constrained intra prediction:
TUs in the partial bottom CTB row next to inter CUs mismatch from there
on.

Written by AI

# Summary of changes

Briefly describe what this PR does and why.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 5c2fa2b0a5697083af39007d741285fdd3af34c8 Mon Sep 17 00:00:00 2001
From: Kieran Kunhya <[email protected]>
Date: Tue, 20 Oct 2026 09:23:58 -0400
Subject: [PATCH] avcodec/hevc/pred_template: substitute out-of-picture samples
 with constrained intra pred

When the bottom-left (or top-right) reference samples cross the picture
edge, the part outside the picture was filled from the last in-picture
sample before the constrained_intra_pred substitution, which only runs up
to the picture edge. If that sample belongs to an inter CU, its raw value
stayed in the out-of-picture part instead of the substituted one
(8.4.4.2.2), and the prediction no longer matched the encoder or HM.

Seen with x265 at 1080p, 64x64 CTBs and constrained intra prediction:
TUs in the partial bottom CTB row next to inter CUs mismatch from there
on.
---
 libavcodec/hevc/pred_template.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/hevc/pred_template.c b/libavcodec/hevc/pred_template.c
index 9b27e539662..63e075e2827 100644
--- a/libavcodec/hevc/pred_template.c
+++ b/libavcodec/hevc/pred_template.c
@@ -291,6 +291,14 @@ do {                                  \
                 a = PIXEL_SPLAT_X4(left[-1]);
                 EXTEND_RIGHT_CIP(top, 0, size_max_x);
             }
+            // Samples past the picture edge repeat the substituted last
+            // sample, not the one read before the substitution.
+            if (cand_bottom_left && bottom_left_size < size)
+                EXTEND(left + size + bottom_left_size, left[size + 
bottom_left_size - 1],
+                       size - bottom_left_size);
+            if (cand_up_right && top_right_size < size)
+                EXTEND(top + size + top_right_size, top[size + top_right_size 
- 1],
+                       size - top_right_size);
         }
     }
     // Infer the unavailable samples
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to