From fa1f92a4f1c0890e501dcafcea8bc9ed5caa53e5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 5 Apr 2012 08:26:09 +0200 Subject: [PATCH] vf_idet: clean detected frame types based on a 4 frame history. Signed-off-by: Michael Niedermayer --- libavfilter/vf_idet.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_idet.c b/libavfilter/vf_idet.c index 9cf01e6a04..9376ee8a16 100644 --- a/libavfilter/vf_idet.c +++ b/libavfilter/vf_idet.c @@ -26,6 +26,8 @@ #undef NDEBUG #include +#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; ihistory[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;