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 <g...@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-le...@ffmpeg.org