Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avfilter/vf_colordetect: only report detected properties on EOF (PR #20503)
@ 2025-09-12 11:19 Niklas Haas via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Niklas Haas via ffmpeg-devel @ 2025-09-12 11:19 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

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

Instead of reporting them also when the filtergraph is suddenly destroyed
mid-stream, e.g. during the `ffmpeg` tool's early init.


>From 113878b880bf0d25a0c683acd9e3c0dc91bc2a34 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Fri, 12 Sep 2025 13:18:07 +0200
Subject: [PATCH] avfilter/vf_colordetect: only report detected properties on
 EOF

Instead of reporting them also when the filtergraph is suddenly destroyed
mid-stream, e.g. during the `ffmpeg` tool's early init.
---
 libavfilter/vf_colordetect.c | 37 +++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_colordetect.c b/libavfilter/vf_colordetect.c
index ef7fb25130..5fd61a302c 100644
--- a/libavfilter/vf_colordetect.c
+++ b/libavfilter/vf_colordetect.c
@@ -204,7 +204,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     return ff_filter_frame(inlink->dst->outputs[0], in);
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
+static av_cold void report_detected_props(AVFilterContext *ctx)
 {
     ColorDetectContext *s = ctx->priv;
     if (!s->mode)
@@ -226,6 +226,38 @@ static av_cold void uninit(AVFilterContext *ctx)
     }
 }
 
+static int activate(AVFilterContext *ctx)
+{
+    AVFilterLink *inlink  = ctx->inputs[0];
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFrame *frame;
+    int64_t pts;
+    int ret;
+
+    ret = ff_outlink_get_status(outlink);
+    if (ret) {
+        ff_inlink_set_status(inlink, ret);
+        report_detected_props(ctx);
+        return 0;
+    }
+
+    ret = ff_inlink_consume_frame(inlink, &frame);
+    if (ret < 0) {
+        return ret;
+    } else if (ret) {
+        return filter_frame(inlink, frame);
+    }
+
+    if (ff_inlink_acknowledge_status(inlink, &ret, &pts)) {
+        ff_outlink_set_status(outlink, ret, pts);
+        report_detected_props(ctx);
+        return 0;
+    }
+
+    FF_FILTER_FORWARD_WANTED(outlink, inlink);
+    return FFERROR_NOT_READY;
+}
+
 av_cold void ff_color_detect_dsp_init(FFColorDetectDSPContext *dsp, int depth,
                                       enum AVColorRange color_range)
 {
@@ -248,7 +280,6 @@ static const AVFilterPad colordetect_inputs[] = {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
         .config_props  = config_input,
-        .filter_frame  = filter_frame,
     },
 };
 
@@ -261,5 +292,5 @@ const FFFilter ff_vf_colordetect = {
     FILTER_INPUTS(colordetect_inputs),
     FILTER_OUTPUTS(ff_video_default_filterpad),
     FILTER_QUERY_FUNC2(query_format),
-    .uninit        = uninit,
+    .activate      = activate,
 };
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-09-12 11:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-12 11:19 [FFmpeg-devel] [PATCH] avfilter/vf_colordetect: only report detected properties on EOF (PR #20503) Niklas Haas via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git