PR #25371 opened by Kyle Swanson (kylophone)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25371
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25371.patch

Signed-off-by: Kyle Swanson <[email protected]>

# Summary of changes

Maps color info from AVFrame into VmafPicture. Also drops vf_libvmaf's 
dimension check during init, which libvmaf will reject a mismatch at runtime.


>From bd3d2f996a5fea8bd59d6836e998b13b08537c8b Mon Sep 17 00:00:00 2001
From: Kyle Swanson <[email protected]>
Date: Thu, 22 Oct 2026 18:30:26 +0000
Subject: [PATCH] avfilter/vf_libvmaf: pass frame colorimetry to libvmaf

Signed-off-by: Kyle Swanson <[email protected]>
---
 configure                |  6 +++--
 libavfilter/vf_libvmaf.c | 50 ++++++++++++++++++++++++++++++++--------
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/configure b/configure
index c8b25c26d94..d8abff0d208 100755
--- a/configure
+++ b/configure
@@ -2658,6 +2658,7 @@ HAVE_LIST="
     ioctl_posix
     iokit
     libdrm_getfb2
+    libvmaf_picture_convert
     makeinfo_html
     opencl_d3d11
     opencl_drm_arm
@@ -7366,8 +7367,9 @@ enabled libtwolame        && require libtwolame twolame.h 
twolame_init -ltwolame
 enabled libuavs3d         && require_pkg_config libuavs3d "uavs3d >= 1.1.41" 
uavs3d.h uavs3d_decode
 enabled libv4l2           && require_pkg_config libv4l2 libv4l2 libv4l2.h 
v4l2_ioctl
 enabled libvidstab        && require_pkg_config libvidstab "vidstab >= 0.98" 
vid.stab/libvidstab.h vsMotionDetectInit
-enabled libvmaf           && require_pkg_config libvmaf "libvmaf >= 2.0.0" 
libvmaf.h vmaf_init
-enabled libvmaf           && check_pkg_config libvmaf_cuda "libvmaf >= 2.0.0" 
libvmaf_cuda.h vmaf_cuda_state_init
+enabled libvmaf           && require_pkg_config libvmaf "libvmaf >= 2.0.0" 
libvmaf.h vmaf_init &&
+                             { check_pkg_config libvmaf_cuda "libvmaf >= 
2.0.0" libvmaf_cuda.h vmaf_cuda_state_init;
+                               check_pkg_config libvmaf_picture_convert 
"libvmaf >= 2.0.0" libvmaf.h vmaf_picture_convert; }
 enabled libvo_amrwbenc    && { check_pkg_config libvo_amrwbenc vo-amrwbenc 
vo-amrwbenc/enc_if.h E_IF_init ||
                                require libvo_amrwbenc vo-amrwbenc/enc_if.h 
E_IF_init -lvo-amrwbenc; }
 enabled libvorbis         && require_pkg_config libvorbis vorbis 
vorbis/codec.h vorbis_info_init &&
diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
index 47715416642..34566c1cc71 100644
--- a/libavfilter/vf_libvmaf.c
+++ b/libavfilter/vf_libvmaf.c
@@ -24,6 +24,7 @@
  * Calculate the VMAF between two input videos.
  */
 
+#include "config.h"
 #include "config_components.h"
 
 #include <libvmaf.h>
@@ -105,6 +106,41 @@ static enum VmafPixelFormat pix_fmt_map(enum AVPixelFormat 
av_pix_fmt)
     }
 }
 
+#if HAVE_LIBVMAF_PICTURE_CONVERT
+static VmafColor color_map(const AVFrame *f)
+{
+    VmafColor c = { 0 };
+
+    switch (f->color_range) {
+    case AVCOL_RANGE_MPEG: c.range = VMAF_COLOR_RANGE_LIMITED; break;
+    case AVCOL_RANGE_JPEG: c.range = VMAF_COLOR_RANGE_FULL;    break;
+    default:               c.range = VMAF_COLOR_RANGE_UNKNOWN; break;
+    }
+
+    switch (f->color_primaries) {
+    case AVCOL_PRI_BT709:    c.primaries = VMAF_COLOR_PRIMARIES_BT709;    
break;
+    case AVCOL_PRI_BT2020:   c.primaries = VMAF_COLOR_PRIMARIES_BT2020;   
break;
+    case AVCOL_PRI_SMPTE432: c.primaries = VMAF_COLOR_PRIMARIES_SMPTE432; 
break;
+    default:                 c.primaries = VMAF_COLOR_PRIMARIES_UNKNOWN;  
break;
+    }
+
+    switch (f->color_trc) {
+    case AVCOL_TRC_BT709:     c.trc = VMAF_COLOR_TRC_BT709;     break;
+    case AVCOL_TRC_SMPTE2084: c.trc = VMAF_COLOR_TRC_SMPTE2084; break;
+    default:                  c.trc = VMAF_COLOR_TRC_UNKNOWN;   break;
+    }
+
+    switch (f->colorspace) {
+    case AVCOL_SPC_BT709:      c.matrix = VMAF_COLOR_MATRIX_BT709;      break;
+    case AVCOL_SPC_BT2020_NCL: c.matrix = VMAF_COLOR_MATRIX_BT2020_NCL; break;
+    case AVCOL_SPC_ICTCP:      c.matrix = VMAF_COLOR_MATRIX_ICTCP;      break;
+    default:                   c.matrix = VMAF_COLOR_MATRIX_UNKNOWN;    break;
+    }
+
+    return c;
+}
+#endif
+
 static int copy_picture_data(AVFrame *src, VmafPicture *dst, unsigned bpc)
 {
     const int bytes_per_value = bpc > 8 ? 2 : 1;
@@ -113,6 +149,10 @@ static int copy_picture_data(AVFrame *src, VmafPicture 
*dst, unsigned bpc)
     if (err)
         return AVERROR(ENOMEM);
 
+#if HAVE_LIBVMAF_PICTURE_CONVERT
+    dst->color = color_map(src);
+#endif
+
     for (unsigned i = 0; i < 3; i++) {
         uint8_t *src_data = src->data[i];
         uint8_t *dst_data = dst->data[i];
@@ -474,16 +514,6 @@ static int config_input_ref(AVFilterLink *inlink)
     const AVPixFmtDescriptor *desc;
     int err = 0;
 
-    if (ctx->inputs[0]->w != ctx->inputs[1]->w) {
-        av_log(ctx, AV_LOG_ERROR, "input width must match.\n");
-        err |= AVERROR(EINVAL);
-    }
-
-    if (ctx->inputs[0]->h != ctx->inputs[1]->h) {
-        av_log(ctx, AV_LOG_ERROR, "input height must match.\n");
-        err |= AVERROR(EINVAL);
-    }
-
     if (ctx->inputs[0]->format != ctx->inputs[1]->format) {
         av_log(ctx, AV_LOG_ERROR, "input pix_fmt must match.\n");
         err |= AVERROR(EINVAL);
-- 
2.54.0

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

Reply via email to