[FFmpeg-cvslog] vf_idet: clean detected frame types based on a 4 frame history.

Michael Niedermayer git at videolan.org
Thu Apr 5 09:15:38 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Apr  5 08:26:09 2012 +0200| [fa1f92a4f1c0890e501dcafcea8bc9ed5caa53e5] | committer: Michael Niedermayer

vf_idet: clean detected frame types based on a 4 frame history.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fa1f92a4f1c0890e501dcafcea8bc9ed5caa53e5
---

 libavfilter/vf_idet.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_idet.c b/libavfilter/vf_idet.c
index 9cf01e6..9376ee8 100644
--- a/libavfilter/vf_idet.c
+++ b/libavfilter/vf_idet.c
@@ -26,6 +26,8 @@
 #undef NDEBUG
 #include <assert.h>
 
+#define HIST_SIZE 4
+
 typedef enum {
     TFF,
     BFF,
@@ -41,6 +43,8 @@ typedef struct {
     Type prestat[4];
     Type poststat[4];
 
+    uint8_t history[HIST_SIZE];
+
     AVFilterBufferRef *cur;
     AVFilterBufferRef *next;
     AVFilterBufferRef *prev;
@@ -91,7 +95,8 @@ static void filter(AVFilterContext *ctx)
     int y, i;
     int64_t alpha[2]={0};
     int64_t delta=0;
-    Type type;
+    Type type, best_type;
+    int match = 0;
 
     for (i = 0; i < idet->csp->nb_components; i++) {
         int w = idet->cur->video->w;
@@ -127,8 +132,27 @@ static void filter(AVFilterContext *ctx)
         type = UNDETERMINED;
     }
 
-    if (type != UNDETERMINED)
-        idet->last_type = type;
+    memmove(idet->history+1, idet->history, HIST_SIZE-1);
+    idet->history[0] = type;
+    best_type = UNDETERMINED;
+    for(i=0; i<HIST_SIZE; i++){
+        if(idet->history[i] != UNDETERMINED){
+            if(best_type == UNDETERMINED)
+                best_type = idet->history[i];
+
+            if(idet->history[i] == best_type) {
+                match++;
+            }else{
+                match=0;
+                break;
+            }
+        }
+    }
+    if(idet->last_type == UNDETERMINED){
+        if(match  ) idet->last_type = best_type;
+    }else{
+        if(match>2) idet->last_type = best_type;
+    }
 
     if      (idet->last_type == TFF){
         idet->cur->video->top_field_first = 1;
@@ -281,6 +305,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     if (args) sscanf(args, "%f:%f", &idet->interlace_threshold, &idet->progressive_threshold);
 
     idet->last_type = UNDETERMINED;
+    memset(idet->history, UNDETERMINED, HIST_SIZE);
 
     idet->filter_line = filter_line_c;
 



More information about the ffmpeg-cvslog mailing list