PR #24434 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24434
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24434.patch

av_get_frame_filename() is a trivial function that uses no lavf API, only lavu, 
so it can be duplicated here to save an unnecessary dependency.

Signed-off-by: James Almer <[email protected]>


>From 7f8c631e702eb108dfb23b8c3b0294ca63e96de7 Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Wed, 9 Sep 2026 17:31:36 -0300
Subject: [PATCH] avfilter/vf_signature: remove dependency on libavformat

av_get_frame_filename() is a trivial function that uses no lavf API, only lavu,
so it can be duplicated here to save an unnecessary dependency.

Signed-off-by: James Almer <[email protected]>
---
 configure                  |  4 +--
 libavfilter/vf_signature.c | 59 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 79731eb188..14da1532bc 100755
--- a/configure
+++ b/configure
@@ -4292,7 +4292,7 @@ select_filter_select="scene_sad"
 sharpness_vaapi_filter_deps="vaapi"
 showcqt_filter_deps="avformat swscale"
 showcqt_filter_suggest="libfontconfig libfreetype"
-signature_filter_deps="gpl avcodec avformat"
+signature_filter_deps="gpl avcodec"
 smartblur_filter_deps="gpl swscale"
 sobel_opencl_filter_deps="opencl"
 sofalizer_filter_deps="libmysofa"
@@ -8257,7 +8257,7 @@ enabled sab_filter          && prepend avfilter_deps 
"swscale"
 enabled scale_filter        && prepend avfilter_deps "swscale"
 enabled scale2ref_filter    && prepend avfilter_deps "swscale"
 enabled showcqt_filter      && prepend avfilter_deps "avformat swscale"
-enabled signature_filter    && prepend avfilter_deps "avcodec avformat"
+enabled signature_filter    && prepend avfilter_deps "avcodec"
 enabled smartblur_filter    && prepend avfilter_deps "swscale"
 enabled spp_filter          && prepend avfilter_deps "avcodec"
 enabled sr_filter           && prepend avfilter_deps "avformat swscale"
diff --git a/libavfilter/vf_signature.c b/libavfilter/vf_signature.c
index 76fab4d6fa..b655b08a87 100644
--- a/libavfilter/vf_signature.c
+++ b/libavfilter/vf_signature.c
@@ -25,8 +25,8 @@
  */
 
 #include "libavcodec/put_bits.h"
-#include "libavformat/avformat.h"
 #include "libavutil/mem.h"
+#include "libavutil/bprint.h"
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
 #include "libavutil/file_open.h"
@@ -555,6 +555,59 @@ static int binary_export(AVFilterContext *ctx, 
StreamContext *sc, const char* fi
     return 0;
 }
 
+static int get_frame_filename(char *buf, int buf_size, const char *path, 
int64_t number)
+{
+    AVBPrint bp;
+    const char *p;
+    char c;
+    int nd, percentd_found;
+
+    av_bprint_init_for_buffer(&bp, buf, buf_size);
+    p = path;
+    percentd_found = 0;
+    for (;;) {
+        c = *p++;
+        if (c == '\0')
+            break;
+        if (c == '%') {
+            do {
+                nd = 0;
+                while (av_isdigit(*p)) {
+                    if (nd >= INT_MAX / 10 - 255)
+                        goto fail;
+                    nd = nd * 10 + *p++ - '0';
+                }
+                c = *p++;
+            } while (av_isdigit(c));
+
+            switch (c) {
+            case '%':
+                goto addchar;
+            case 'd':
+                if (!percentd_found)
+                    goto fail;
+                percentd_found = 1;
+                if (number < 0)
+                    nd += 1;
+                av_bprintf(&bp, "%0*" PRId64, nd, number);
+                break;
+            default:
+                goto fail;
+            }
+        } else {
+addchar:
+            av_bprint_chars(&bp, c, 1);
+        }
+    }
+    if (!percentd_found)
+        goto fail;
+    if (!av_bprint_is_complete(&bp))
+        return AVERROR(ENOMEM);
+    return 0;
+fail:
+    return AVERROR(EINVAL);
+}
+
 static int export(AVFilterContext *ctx, StreamContext *sc, int input)
 {
     SignatureContext* sic = ctx->priv;
@@ -562,7 +615,7 @@ static int export(AVFilterContext *ctx, StreamContext *sc, 
int input)
 
     if (sic->nb_inputs > 1) {
         /* error already handled */
-        av_assert0(av_get_frame_filename(filename, sizeof(filename), 
sic->filename, input) == 0);
+        av_assert0(get_frame_filename(filename, sizeof(filename), 
sic->filename, input) == 0);
     } else {
         if (av_strlcpy(filename, sic->filename, sizeof(filename)) >= 
sizeof(filename))
             return AVERROR(EINVAL);
@@ -673,7 +726,7 @@ static av_cold int init(AVFilterContext *ctx)
     }
 
     /* check filename */
-    if (sic->nb_inputs > 1 && strlen(sic->filename) > 0 && 
av_get_frame_filename(tmp, sizeof(tmp), sic->filename, 0) == -1) {
+    if (sic->nb_inputs > 1 && strlen(sic->filename) > 0 && 
get_frame_filename(tmp, sizeof(tmp), sic->filename, 0) == -1) {
         av_log(ctx, AV_LOG_ERROR, "The filename must contain %%d or %%0nd, if 
you have more than one input.\n");
         return AVERROR(EINVAL);
     }
-- 
2.52.0

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

Reply via email to