From 2ac0c4b6bab752c92ffa615c028cd4582441f680 Mon Sep 17 00:00:00 2001
From: Kevin Mitchell <[email protected]>
Date: Sat, 1 Nov 2014 05:38:35 -0700
Subject: [PATCH 2/3] avfilter/vf_idet: add a "reset_count" option like
cropdetect
This can be useful for videos in which the interlacing pattern changes.
Also log the total number of frames as metadata and with avlog.
---
doc/filters.texi | 7 +++++++
libavfilter/version.h | 2 +-
libavfilter/vf_idet.c | 45 +++++++++++++++++++++++++++++++++------------
libavfilter/vf_idet.h | 2 ++
4 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 33f842b..2896978 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -5583,6 +5583,9 @@ Multiple frame detection incorporates the classification history of previous fra
The filter will log these metadata values:
@table @option
+@item frames_total
+Total number of frames considered in current statistics.
+
@item single.current_frame
Detected type of current frame using single-frame detection. One of:
``tff'' (top field first), ``bff'' (bottom field first),
@@ -5625,6 +5628,10 @@ The filter accepts the following options:
Set interlacing threshold.
@item prog_thres
Set progressive threshold.
+@item reset_count
+Number of frames after which idet will reset all previously collected
+statistics. The current statistics are logged before being
+destroyed. The default of 0 indicates 'never reset'.
@end table
@section il
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 440c587..dab9b45 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,7 +31,7 @@
#define LIBAVFILTER_VERSION_MAJOR 5
#define LIBAVFILTER_VERSION_MINOR 2
-#define LIBAVFILTER_VERSION_MICRO 101
+#define LIBAVFILTER_VERSION_MICRO 102
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_idet.c b/libavfilter/vf_idet.c
index 6f99f39..79dc9be 100644
--- a/libavfilter/vf_idet.c
+++ b/libavfilter/vf_idet.c
@@ -32,6 +32,7 @@
static const AVOption idet_options[] = {
{ "intl_thres", "set interlacing threshold", OFFSET(interlace_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 1.04}, -1, FLT_MAX, FLAGS },
{ "prog_thres", "set progressive threshold", OFFSET(progressive_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 1.5}, -1, FLT_MAX, FLAGS },
+ { "reset_count", "drop statistics after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ NULL }
};
@@ -74,6 +75,25 @@ int ff_idet_filter_line_c_16bit(const uint16_t *a, const uint16_t *b, const uint
return ret;
}
+static void log_cumulative_stats(AVFilterContext *ctx)
+{
+ IDETContext *idet = ctx->priv;
+ av_log(ctx, AV_LOG_INFO, "Single frame detection: TFF:%d BFF:%d Progressive:%d Undetermined:%d Total: %d\n",
+ idet->prestat[TFF],
+ idet->prestat[BFF],
+ idet->prestat[PROGRESSIVE],
+ idet->prestat[UNDETERMINED],
+ idet->frames_total
+ );
+ av_log(ctx, AV_LOG_INFO, "Multi frame detection: TFF:%d BFF:%d Progressive:%d Undetermined:%d Total: %d\n",
+ idet->poststat[TFF],
+ idet->poststat[BFF],
+ idet->poststat[PROGRESSIVE],
+ idet->poststat[UNDETERMINED],
+ idet->frames_total
+ );
+}
+
static void filter(AVFilterContext *ctx)
{
IDETContext *idet = ctx->priv;
@@ -84,6 +104,15 @@ static void filter(AVFilterContext *ctx)
int match = 0;
AVDictionary **metadata = avpriv_frame_get_metadatap(idet->cur);
+ // Reset the statistics every reset_count frames, if reset_count is > 0
+ if (0 < idet->reset_count && idet->reset_count <= idet->frames_total ) {
+ log_cumulative_stats(ctx);
+ memset(idet->prestat, 0 , 4*sizeof(int));
+ memset(idet->poststat, 0 , 4*sizeof(int));
+ memset(idet->history, UNDETERMINED, HIST_SIZE);
+ idet->frames_total=0;
+ }
+
for (i = 0; i < idet->csp->nb_components; i++) {
int w = idet->cur->width;
int h = idet->cur->height;
@@ -146,11 +175,14 @@ static void filter(AVFilterContext *ctx)
idet->cur->interlaced_frame = 0;
}
+ idet->frames_total ++;
idet->prestat [ type] ++;
idet->poststat[idet->last_type] ++;
av_log(ctx, AV_LOG_DEBUG, "Single frame:%12s, Multi frame:%12s\n", type2str(type), type2str(idet->last_type));
+ av_dict_set_int(metadata, "lavfi.idet.frames_total", idet->frames_total, 0);
+
av_dict_set (metadata, "lavfi.idet.single.current_frame", type2str(type), 0);
av_dict_set_int(metadata, "lavfi.idet.single.tff", idet->prestat[TFF], 0);
av_dict_set_int(metadata, "lavfi.idet.single.bff", idet->prestat[BFF], 0);
@@ -228,18 +260,7 @@ static av_cold void uninit(AVFilterContext *ctx)
{
IDETContext *idet = ctx->priv;
- av_log(ctx, AV_LOG_INFO, "Single frame detection: TFF:%d BFF:%d Progressive:%d Undetermined:%d\n",
- idet->prestat[TFF],
- idet->prestat[BFF],
- idet->prestat[PROGRESSIVE],
- idet->prestat[UNDETERMINED]
- );
- av_log(ctx, AV_LOG_INFO, "Multi frame detection: TFF:%d BFF:%d Progressive:%d Undetermined:%d\n",
- idet->poststat[TFF],
- idet->poststat[BFF],
- idet->poststat[PROGRESSIVE],
- idet->poststat[UNDETERMINED]
- );
+ log_cumulative_stats(ctx);
av_frame_free(&idet->prev);
av_frame_free(&idet->cur );
diff --git a/libavfilter/vf_idet.h b/libavfilter/vf_idet.h
index 57332df..97a7e3f 100644
--- a/libavfilter/vf_idet.h
+++ b/libavfilter/vf_idet.h
@@ -37,8 +37,10 @@ typedef struct {
const AVClass *class;
float interlace_threshold;
float progressive_threshold;
+ int reset_count;
Type last_type;
+ int frames_total;
int prestat[4];
int poststat[4];
--
2.1.1
_______________________________________________
ffmpeg-devel mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel