From a2ff5eb55f6eb34569d46b5a44104f7a2617d422 Mon Sep 17 00:00:00 2001 From: Kieran Kunhya 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 9b27e53966..63e075e282 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