PR #24176 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24176
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24176.patch

This does not change the existing precedent of only operating on luma planes 
(except the debatable addition of packed YA8, which is treated similarly to 
RGBA in that the alpha channel is compared as well).


>From 6cd5ce6f7ee6017648556c41cbb629fac0cdfe96 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Mon, 17 Aug 2026 10:53:30 +0200
Subject: [PATCH 1/2] avfilter/vf_scdet: expand format list

This filter works by running the SAD function on the first plane, which
works for any (native endian) format that starts with an unshifted luma
plane. This notably includes formats like nv12, yuva420p, and grayscale
formats, as well as luma-alpha formats. The last addition is debatable,
but the precedent here is the existing support for RGBA, which also
dilutes scene scores by including the alpha component in the SAD
calculation).

This is an exhaustive listing as of the current set of formats.
Tested by looping over `format=<pixfmt>,scdet` and verifying that the
scene SAD score doesn't (meaningfully) change, except for expected
deviations (e.g. larger scores for full range vs limited range, and
lowered scores for packed alpha formats).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <[email protected]>
---
 libavfilter/vf_scdet.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_scdet.c b/libavfilter/vf_scdet.c
index 6b1de13610..0e4ee06fe1 100644
--- a/libavfilter/vf_scdet.c
+++ b/libavfilter/vf_scdet.c
@@ -62,14 +62,40 @@ AVFILTER_DEFINE_CLASS(scdet);
 
 static const enum AVPixelFormat pix_fmts[] = {
         AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, AV_PIX_FMT_RGBA,
-        AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA,
+
+        AV_PIX_FMT_GBRP,   AV_PIX_FMT_GBRP9,   AV_PIX_FMT_GBRP10,
+        AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14,  AV_PIX_FMT_GBRP16,
+        AV_PIX_FMT_GBRAP,  AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12,
+        AV_PIX_FMT_GBRAP14, AV_PIX_FMT_GBRAP16,
+
+        AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10,
+        AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
+        AV_PIX_FMT_YA8, AV_PIX_FMT_YA16,
+
+        AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUVJ411P,
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P,
         AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
         AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
         AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
-        AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV420P12,
-        AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12,
-        AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12,
+        AV_PIX_FMT_YUV420P9,  AV_PIX_FMT_YUV422P9,  AV_PIX_FMT_YUV444P9,
+        AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10,
+        AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV444P10,
+        AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12,
+        AV_PIX_FMT_YUV440P12, AV_PIX_FMT_YUV444P12,
+        AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
+        AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
+
+        AV_PIX_FMT_YUVA420P,   AV_PIX_FMT_YUVA422P,   AV_PIX_FMT_YUVA444P,
+        AV_PIX_FMT_YUVA420P9,  AV_PIX_FMT_YUVA422P9,  AV_PIX_FMT_YUVA444P9,
+        AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
+                               AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
+        AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
+
+        AV_PIX_FMT_NV12, AV_PIX_FMT_NV21, AV_PIX_FMT_NV16,
+        AV_PIX_FMT_NV24, AV_PIX_FMT_NV42, AV_PIX_FMT_NV20,
+        AV_PIX_FMT_P016, AV_PIX_FMT_P216, AV_PIX_FMT_P416,
+
         AV_PIX_FMT_NONE
 };
 
-- 
2.52.0


>From 45512e1272fa24c7be6978da844af431aab801e3 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Mon, 17 Aug 2026 11:14:21 +0200
Subject: [PATCH 2/2] avfilter/vf_scdet: add support for MSB-aligned pixel
 formats

This is trivial since the SAD result is already safe to 16 bits, and
the result is already normalized by the bit depth.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <[email protected]>
---
 libavfilter/vf_scdet.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_scdet.c b/libavfilter/vf_scdet.c
index 0e4ee06fe1..5453b8d7bc 100644
--- a/libavfilter/vf_scdet.c
+++ b/libavfilter/vf_scdet.c
@@ -68,6 +68,7 @@ static const enum AVPixelFormat pix_fmts[] = {
         AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14,  AV_PIX_FMT_GBRP16,
         AV_PIX_FMT_GBRAP,  AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12,
         AV_PIX_FMT_GBRAP14, AV_PIX_FMT_GBRAP16,
+        AV_PIX_FMT_GBRP10MSB, AV_PIX_FMT_GBRP12MSB,
 
         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10,
         AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
@@ -92,8 +93,12 @@ static const enum AVPixelFormat pix_fmts[] = {
                                AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
         AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
 
+        AV_PIX_FMT_YUV444P10MSB, AV_PIX_FMT_YUV444P12MSB,
+
         AV_PIX_FMT_NV12, AV_PIX_FMT_NV21, AV_PIX_FMT_NV16,
         AV_PIX_FMT_NV24, AV_PIX_FMT_NV42, AV_PIX_FMT_NV20,
+        AV_PIX_FMT_P010, AV_PIX_FMT_P210, AV_PIX_FMT_P410,
+        AV_PIX_FMT_P012, AV_PIX_FMT_P212, AV_PIX_FMT_P412,
         AV_PIX_FMT_P016, AV_PIX_FMT_P216, AV_PIX_FMT_P416,
 
         AV_PIX_FMT_NONE
@@ -108,7 +113,9 @@ static int config_input(AVFilterLink *inlink)
         (desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
         desc->nb_components >= 3;
 
-    s->bitdepth = desc->comp[0].depth;
+    /* SAD scores are normalize by the bit-depth, so MSB-aligned formats are
+     * equivalent to their corresponding full depth representation */
+    s->bitdepth = desc->comp[0].depth + desc->comp[0].shift;
     s->nb_planes = is_yuv ? 1 : av_pix_fmt_count_planes(inlink->format);
 
     for (int plane = 0; plane < 4; plane++) {
-- 
2.52.0

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

Reply via email to