Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH] avfilter/vf_blackdetect_vulkan: fix black region reporting
Date: Mon,  2 Jun 2025 13:54:27 +0200
Message-ID: <20250602115427.47647-1-ffmpeg@haasn.xyz> (raw)

From: Niklas Haas <git@haasn.dev>

The old logic failed to take into account files that ended on ablack
region. The new logic matches the vf_blackdetect behavior.
---
 libavfilter/vf_blackdetect_vulkan.c | 30 +++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_blackdetect_vulkan.c b/libavfilter/vf_blackdetect_vulkan.c
index 4e977abe3d..fdebfd955a 100644
--- a/libavfilter/vf_blackdetect_vulkan.c
+++ b/libavfilter/vf_blackdetect_vulkan.c
@@ -42,7 +42,6 @@ typedef struct BlackDetectVulkanContext {
     int    alpha;
 
     int64_t black_start;
-    int64_t black_end;
 } BlackDetectVulkanContext;
 
 typedef struct BlackDetectPushData {
@@ -145,6 +144,7 @@ static av_cold int init_filter(AVFilterContext *ctx)
 
     RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));
 
+    s->black_start = AV_NOPTS_VALUE;
     s->initialized = 1;
 
 fail:
@@ -156,6 +156,22 @@ fail:
     return err;
 }
 
+static void report_black_region(AVFilterContext *ctx, int64_t black_end)
+{
+    BlackDetectVulkanContext *s = ctx->priv;
+    const AVFilterLink *inlink = ctx->inputs[0];
+    if (s->black_start == AV_NOPTS_VALUE)
+        return;
+
+    if ((black_end - s->black_start) >= s->black_min_duration_time / av_q2d(inlink->time_base)) {
+        av_log(s, AV_LOG_INFO,
+               "black_start:%s black_end:%s black_duration:%s\n",
+               av_ts2timestr(s->black_start, &inlink->time_base),
+               av_ts2timestr(black_end, &inlink->time_base),
+               av_ts2timestr(black_end - s->black_start, &inlink->time_base));
+    }
+}
+
 static void evaluate(AVFilterLink *link, AVFrame *in,
                      const BlackDetectBuf *sum)
 {
@@ -183,15 +199,9 @@ static void evaluate(AVFilterLink *link, AVFrame *in,
                 av_ts2timestr(in->pts, &in->time_base), 0);
         }
     } else if (s->black_start != AV_NOPTS_VALUE) {
+        report_black_region(ctx, in->pts);
         av_dict_set(&in->metadata, "lavfi.black_end",
             av_ts2timestr(in->pts, &in->time_base), 0);
-        if ((in->pts - s->black_start) >= s->black_min_duration_time / av_q2d(in->time_base)) {
-            av_log(s, AV_LOG_INFO,
-                   "black_start:%s black_end:%s black_duration:%s\n",
-                   av_ts2timestr(s->black_start, &in->time_base),
-                   av_ts2timestr(in->pts, &in->time_base),
-                   av_ts2timestr(in->pts - s->black_start, &in->time_base));
-        }
         s->black_start = AV_NOPTS_VALUE;
     }
 }
@@ -349,8 +359,12 @@ fail:
 static void blackdetect_vulkan_uninit(AVFilterContext *avctx)
 {
     BlackDetectVulkanContext *s = avctx->priv;
+    AVFilterLink *inlink = avctx->inputs[0];
+    FilterLink *inl = ff_filter_link(inlink);
     FFVulkanContext *vkctx = &s->vkctx;
 
+    report_black_region(avctx, inl->current_pts);
+
     ff_vk_exec_pool_free(vkctx, &s->e);
     ff_vk_shader_free(vkctx, &s->shd);
 
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

             reply	other threads:[~2025-06-02 11:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02 11:54 Niklas Haas [this message]
2025-06-03  9:26 ` Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250602115427.47647-1-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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