[FFmpeg-devel] [PATCH v3] libavfilter/vf_blackdetect.c
Jonathan Baecker
jonbae77 at gmail.com
Sun Dec 10 21:30:44 EET 2017
Here the cleanup version from the patch.
-------------- next part --------------
From b6b6e4ab885f9b35a6696492286e504a4b3d6d92 Mon Sep 17 00:00:00 2001
From: Jonathan <jonbae77 at gmail.com>
Date: Mon, 4 Dec 2017 16:05:48 +0100
Subject: [PATCH] unify blackdetect with af_silencedetect. Is more useful for
monitoring streams.
---
libavfilter/vf_blackdetect.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/libavfilter/vf_blackdetect.c b/libavfilter/vf_blackdetect.c
index 06ef9988d..92ea39b33 100644
--- a/libavfilter/vf_blackdetect.c
+++ b/libavfilter/vf_blackdetect.c
@@ -38,6 +38,7 @@ typedef struct BlackDetectContext {
int64_t black_end; ///< pts end time of the last black picture
int64_t last_picref_pts; ///< pts of the last input picture
int black_started;
+ int black_match;
double picture_black_ratio_th;
double pixel_black_th;
@@ -107,15 +108,20 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
-static void check_black_end(AVFilterContext *ctx)
+static void check_black(AVFilterContext *ctx)
{
BlackDetectContext *blackdetect = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
- if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration) {
+ if (blackdetect->last_picref_pts - blackdetect->black_start >= blackdetect->black_min_duration && blackdetect->black_match == 0) {
av_log(blackdetect, AV_LOG_INFO,
- "black_start:%s black_end:%s black_duration:%s\n",
- av_ts2timestr(blackdetect->black_start, &inlink->time_base),
+ "black_start:%s\n",
+ av_ts2timestr(blackdetect->black_start, &inlink->time_base));
+ blackdetect->black_match = 1;
+ }
+ if (blackdetect->black_end - blackdetect->black_start >= blackdetect->black_min_duration && blackdetect->black_started == 1) {
+ av_log(blackdetect, AV_LOG_INFO,
+ "black_end:%s | black_duration:%s\n",
av_ts2timestr(blackdetect->black_end, &inlink->time_base),
av_ts2timestr(blackdetect->black_end - blackdetect->black_start, &inlink->time_base));
}
@@ -131,7 +137,7 @@ static int request_frame(AVFilterLink *outlink)
if (ret == AVERROR_EOF && blackdetect->black_started) {
// FIXME: black_end should be set to last_picref_pts + last_picref_duration
blackdetect->black_end = blackdetect->last_picref_pts;
- check_black_end(ctx);
+ check_black(ctx);
}
return ret;
}
@@ -163,15 +169,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
if (!blackdetect->black_started) {
/* black starts here */
blackdetect->black_started = 1;
+ blackdetect->black_match = 0;
blackdetect->black_start = picref->pts;
av_dict_set(&picref->metadata, "lavfi.black_start",
av_ts2timestr(blackdetect->black_start, &inlink->time_base), 0);
}
+ check_black(ctx);
} else if (blackdetect->black_started) {
/* black ends here */
- blackdetect->black_started = 0;
blackdetect->black_end = picref->pts;
- check_black_end(ctx);
+ check_black(ctx);
+ blackdetect->black_started = 0;
av_dict_set(&picref->metadata, "lavfi.black_end",
av_ts2timestr(blackdetect->black_end, &inlink->time_base), 0);
}
--
2.15.1
More information about the ffmpeg-devel
mailing list