This was requested following my initial patch adding the metadata.
Should resolve http://trac.ffmpeg.org/ticket/3832
From 2c4f9c042a863ae370ff21058c9aa72e0d0c6d7e Mon Sep 17 00:00:00 2001
From: Kevin Mitchell <kevmi...@gmail.com>
Date: Sat, 1 Nov 2014 04:10:15 -0700
Subject: [PATCH 1/3] avfilter/idet: add current frame classification to
 metadata

resolves #3832

also, add metadata to "current" frame instead of "next" frame and do
next to the av_log call
---
 doc/filters.texi      | 13 +++++++++++++
 libavfilter/version.h |  2 +-
 libavfilter/vf_idet.c | 36 ++++++++++++++++++++----------------
 3 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 7be29de..33f842b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -5577,9 +5577,17 @@ Detect video interlacing type.
 This filter tries to detect if the input is interlaced or progressive,
 top or bottom field first.
 
+Single frame detection considers only immediately adjacent frames when classifying each frame.
+Multiple frame detection incorporates the classification history of previous frames.
+
 The filter will log these metadata values:
 
 @table @option
+@item single.current_frame
+Detected type of current frame using single-frame detection. One of:
+``tff'' (top field first), ``bff'' (bottom field first),
+``progressive'', or ``undetermined''
+
 @item single.tff
 Cumulative number of frames detected as top field first using single-frame detection.
 
@@ -5589,6 +5597,11 @@ Cumulative number of frames detected as top field first using multiple-frame det
 @item single.bff
 Cumulative number of frames detected as bottom field first using single-frame detection.
 
+@item multiple.current_frame
+Detected type of current frame using multiple-frame detection. One of:
+``tff'' (top field first), ``bff'' (bottom field first),
+``progressive'', or ``undetermined''
+
 @item multiple.bff
 Cumulative number of frames detected as bottom field first using multiple-frame detection.
 
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 2fa15eb..440c587 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 100
+#define LIBAVFILTER_VERSION_MICRO 101
 
 #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 b9c4070..6f99f39 100644
--- a/libavfilter/vf_idet.c
+++ b/libavfilter/vf_idet.c
@@ -40,10 +40,10 @@ AVFILTER_DEFINE_CLASS(idet);
 static const char *type2str(Type type)
 {
     switch(type) {
-        case TFF          : return "Top Field First   ";
-        case BFF          : return "Bottom Field First";
-        case PROGRESSIVE  : return "Progressive       ";
-        case UNDETERMINED : return "Undetermined      ";
+        case TFF          : return "tff";
+        case BFF          : return "bff";
+        case PROGRESSIVE  : return "progressive";
+        case UNDETERMINED : return "undetermined";
     }
     return NULL;
 }
@@ -82,6 +82,7 @@ static void filter(AVFilterContext *ctx)
     int64_t delta=0;
     Type type, best_type;
     int match = 0;
+    AVDictionary **metadata = avpriv_frame_get_metadatap(idet->cur);
 
     for (i = 0; i < idet->csp->nb_components; i++) {
         int w = idet->cur->width;
@@ -147,14 +148,27 @@ static void filter(AVFilterContext *ctx)
 
     idet->prestat [           type] ++;
     idet->poststat[idet->last_type] ++;
-    av_log(ctx, AV_LOG_DEBUG, "Single frame:%s, Multi frame:%s\n", type2str(type), type2str(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    (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);
+    av_dict_set_int(metadata, "lavfi.idet.single.progressive", idet->prestat[PROGRESSIVE], 0);
+    av_dict_set_int(metadata, "lavfi.idet.single.undetermined", idet->prestat[UNDETERMINED], 0);
+
+    av_dict_set    (metadata, "lavfi.idet.multiple.current_frame", type2str(idet->last_type), 0);
+    av_dict_set_int(metadata, "lavfi.idet.multiple.tff", idet->poststat[TFF], 0);
+    av_dict_set_int(metadata, "lavfi.idet.multiple.bff", idet->poststat[BFF], 0);
+    av_dict_set_int(metadata, "lavfi.idet.multiple.progressive", idet->poststat[PROGRESSIVE], 0);
+    av_dict_set_int(metadata, "lavfi.idet.multiple.undetermined", idet->poststat[UNDETERMINED], 0);
+
 }
 
 static int filter_frame(AVFilterLink *link, AVFrame *picref)
 {
     AVFilterContext *ctx = link->dst;
     IDETContext *idet = ctx->priv;
-    AVDictionary **metadata = avpriv_frame_get_metadatap(picref);
 
     if (idet->prev)
         av_frame_free(&idet->prev);
@@ -178,16 +192,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *picref)
 
     filter(ctx);
 
-    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);
-    av_dict_set_int(metadata, "lavfi.idet.single.progressive", idet->prestat[PROGRESSIVE], 0);
-    av_dict_set_int(metadata, "lavfi.idet.single.undetermined", idet->prestat[UNDETERMINED], 0);
-
-    av_dict_set_int(metadata, "lavfi.idet.multiple.tff", idet->poststat[TFF], 0);
-    av_dict_set_int(metadata, "lavfi.idet.multiple.bff", idet->poststat[BFF], 0);
-    av_dict_set_int(metadata, "lavfi.idet.multiple.progressive", idet->poststat[PROGRESSIVE], 0);
-    av_dict_set_int(metadata, "lavfi.idet.multiple.undetermined", idet->poststat[UNDETERMINED], 0);
-
     return ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->cur));
 }
 
-- 
2.1.1

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

Reply via email to