[FFmpeg-devel] [PATCH 2/3] idet improvements: add reset_count feature

Michael Niedermayer michaelni at gmx.at
Sun Nov 2 12:04:52 CET 2014


On Sat, Nov 01, 2014 at 05:59:20PM -0700, Kevin Mitchell wrote:
> Ok, changed to half life.
> 
> On Sat, Nov 1, 2014 at 10:52 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Sat, Nov 01, 2014 at 07:08:53AM -0700, Kevin Mitchell wrote:
> >>
> >
> >>  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(-)
> >> 5d2c485705ed33022dda83da39bd9f1fc28a97e5  0002-avfilter-vf_idet-add-a-reset_count-option-like-cropd.patch
> >> From 2ac0c4b6bab752c92ffa615c028cd4582441f680 Mon Sep 17 00:00:00 2001
> >> From: Kevin Mitchell <kevmitch at gmail.com>
> >> 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
> >> + at 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.
> >> + at 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
> >
> > some kind of FIR or IIR filtering/windowing of the per frame data is
> > probably better than sharply discarding data at data independant
> > intervalls
> >
> >
> > [...]
> >
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >

>  doc/filters.texi      |   16 ++++++++--
>  libavfilter/version.h |    2 -
>  libavfilter/vf_idet.c |   79 ++++++++++++++++++++++++++++++++++----------------
>  libavfilter/vf_idet.h |    8 +++--
>  4 files changed, 75 insertions(+), 30 deletions(-)
> e5ff94b6949f8ed02bf5d6b2ccc1251d91144dd5  0001-avfilter-vf_idet-add-a-half_life-option-for-statisti.patch
> From fa3c0a70a41afb2432278b7a16b5b0de4a5f354a Mon Sep 17 00:00:00 2001
> From: Kevin Mitchell <kevmitch at gmail.com>
> Date: Sat, 1 Nov 2014 17:17:04 -0700
> Subject: [PATCH 1/2] avfilter/vf_idet: add a "half_life" option for statistics
> 
> 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      | 16 +++++++++--
>  libavfilter/version.h |  2 +-
>  libavfilter/vf_idet.c | 79 +++++++++++++++++++++++++++++++++++----------------
>  libavfilter/vf_idet.h |  8 ++++--
>  4 files changed, 75 insertions(+), 30 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 33f842b..b12beae 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -5574,15 +5574,19 @@ value.
>  
>  Detect video interlacing type.
>  
> -This filter tries to detect if the input is interlaced or progressive,
> +This filter tries to detect the input frames as interlaced, 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.
> +There are two detection modes. Single frame detection considers only
> +immediately adjacent frames when classifying each frame.  Multiple frame
> +detection incorporates the classification history of previous frames.

these sounds independant of the rest of the patch, and should thus
be a seperate patch


>  
>  The filter will log these metadata values:
>  
>  @table @option
> + at 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),

> @@ -5616,6 +5620,7 @@ Cumulative number of frames that could not be classified using single-frame dete
>  
>  @item multiple.undetermined
>  Cumulative number of frames that could not be classified using multiple-frame detection.
> +
>  @end table
>  
>  The filter accepts the following options:

is that intended ?


> @@ -5625,6 +5630,11 @@ The filter accepts the following options:
>  Set interlacing threshold.
>  @item prog_thres
>  Set progressive threshold.
> + at item half_life
> +Number of frames after which a given frame's contribution to the
> +statistics is halved (i.e., it contributes only 0.5 to it's
> +classification). The default of 0 means that all frames seen are given
> +full weight of 1.0 forever.
>  @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..b6a42ce 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 },
> +    { "half_life", "half life of cumulative statistics", OFFSET(half_life),     AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -1, INT_MAX, FLAGS },
>      { NULL }
>  };
>  
> @@ -48,6 +49,14 @@ static const char *type2str(Type type)
>      return NULL;
>  }
>  
> +static int av_dict_set_float(AVDictionary **pm, const char *key, float value,
> +                int flags)
> +{
> +    char valuestr[22];
> +    snprintf(valuestr, sizeof(valuestr), "%.1f", value);
> +    return av_dict_set(pm, key, valuestr, flags);
> +}
> +
>  int ff_idet_filter_line_c(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w)
>  {
>      int x;
> @@ -74,6 +83,26 @@ 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:%6.1f BFF:%6.1f Progressive:%6.1f Undetermined:%6.1f Total: %6.1f\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:%6.1f BFF:%6.1f Progressive:%6.1f Undetermined:%6.1f Total: %6.1f\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;
> @@ -146,23 +175,31 @@ static void filter(AVFilterContext *ctx)
>          idet->cur->interlaced_frame = 0;
>      }
>  
> -    idet->prestat [           type] ++;
> -    idet->poststat[idet->last_type] ++;
> +    idet->frames_total    *= idet->decay_coefficient;
> +    for(i=0; i<4; i++){
> +        idet->prestat [i] *= idet->decay_coefficient;
> +        idet->poststat[i] *= idet->decay_coefficient;
> +    }
> +
> +    idet->frames_total              += 1.0;
> +    idet->prestat [           type] += 1.0;
> +    idet->poststat[idet->last_type] += 1.0;
>  
>      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_float(metadata, "lavfi.idet.frames_total", idet->frames_total, 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);
> +    av_dict_set      (metadata, "lavfi.idet.single.current_frame", type2str(type), 0);
> +    av_dict_set_float(metadata, "lavfi.idet.single.tff", idet->prestat[TFF], 0);
> +    av_dict_set_float(metadata, "lavfi.idet.single.bff", idet->prestat[BFF], 0);
> +    av_dict_set_float(metadata, "lavfi.idet.single.progressive", idet->prestat[PROGRESSIVE], 0);
> +    av_dict_set_float(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_float(metadata, "lavfi.idet.multiple.tff", idet->poststat[TFF], 0);
> +    av_dict_set_float(metadata, "lavfi.idet.multiple.bff", idet->poststat[BFF], 0);
> +    av_dict_set_float(metadata, "lavfi.idet.multiple.progressive", idet->poststat[PROGRESSIVE], 0);
> +    av_dict_set_float(metadata, "lavfi.idet.multiple.undetermined", idet->poststat[UNDETERMINED], 0);
>  }
>  
>  static int filter_frame(AVFilterLink *link, AVFrame *picref)
> @@ -228,18 +265,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 );
> @@ -290,6 +316,11 @@ static av_cold int init(AVFilterContext *ctx)
>      idet->last_type = UNDETERMINED;
>      memset(idet->history, UNDETERMINED, HIST_SIZE);
>  
> +    if( idet->half_life > 0 )
> +        idet->decay_coefficient = pow(2.0,-1.0/idet->half_life);
> +    else
> +        idet->decay_coefficient = 1.0;
> +
>      idet->filter_line = ff_idet_filter_line_c;
>  
>      if (ARCH_X86)
> diff --git a/libavfilter/vf_idet.h b/libavfilter/vf_idet.h
> index 57332df..005ac67 100644
> --- a/libavfilter/vf_idet.h
> +++ b/libavfilter/vf_idet.h
> @@ -37,16 +37,20 @@ typedef struct {
>      const AVClass *class;
>      float interlace_threshold;
>      float progressive_threshold;
> +    float half_life;
> +    float decay_coefficient;
>  
>      Type last_type;

> -    int prestat[4];
> -    int poststat[4];
> +    float frames_total;
> +    float prestat[4];
> +    float poststat[4];

to reduce the amount of differences between platforms, its better
if these stay as some kind of integer / fixpoint type (for
stuff like fate tests for example)
    
the user interface can probably/hopefully saftely be float

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141102/1717a555/attachment.asc>


More information about the ffmpeg-devel mailing list