[FFmpeg-devel] [RFC/PATCH] Add mode to enable disable deinterlacing based on input interlaced flag to yadif

Stefano Sabatini stefano.sabatini-lala at poste.it
Tue Jun 28 12:39:36 CEST 2011


On date Friday 2011-06-24 01:23:18 +0200, Joakim Plate encoded:
> Hi,
> 
> Here is a patch that allows yadif to enable/disable based on the input
> frame's interlaced flag.
> 
> It still incurs one frame additional decode delay. Avoiding that would have
> been preferable as it forces a memcpy. But I could not see any clean way of
> doing so right now.
> 
> /Joakim

> From a67b70a0dea39c9008300c76751afea1315e6c5d Mon Sep 17 00:00:00 2001
> From: Joakim <elupus at ecce.se>
> Date: Fri, 24 Jun 2011 01:16:18 +0200
> Subject: [PATCH] Add mode to enable/disable based on input "interlaced" flag to yadif
> 
> Signed-off-by: Joakim Plate <elupus at ecce.se>
> ---
>  libavfilter/vf_yadif.c |   34 +++++++++++++++++++++++++++++++---
>  1 files changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
> index 296328b..f89490a 100644
> --- a/libavfilter/vf_yadif.c
> +++ b/libavfilter/vf_yadif.c
> @@ -43,6 +43,13 @@ typedef struct {
>      int parity;
>  
>      int frame_pending;
> +    int skip;
> +
> +    /**
> +     *  0: deinterlace all frames
> +     *  1: only deinterlace frames marked as interlaced
> +     */
> +    int auto_enable;
>  
>      AVFilterBufferRef *cur;
>      AVFilterBufferRef *next;
> @@ -236,10 +243,21 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
>      yadif->prev = yadif->cur;
>      yadif->cur  = yadif->next;
>      yadif->next = picref;
> +    yadif->skip = 0;
>  
>      if (!yadif->cur)
>          return;
>  
> +    if (yadif->auto_enable && !yadif->cur->video->interlaced) {
> +        yadif->out  = yadif->cur;
> +        avfilter_unref_buffer(yadif->prev);
> +        yadif->cur  = NULL;
> +        yadif->prev = NULL;
> +        yadif->skip = 1;
> +        avfilter_start_frame(ctx->outputs[0], yadif->out);
> +        return;
> +    }
> +
>      if (!yadif->prev)
>          yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
>  
> @@ -256,6 +274,12 @@ static void end_frame(AVFilterLink *link)
>      AVFilterContext *ctx = link->dst;
>      YADIFContext *yadif = ctx->priv;
>  
> +    if (yadif->skip) {
> +        avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1);
> +        avfilter_end_frame(ctx->outputs[0]);
> +        return;
> +    }
> +
>      if (!yadif->out)
>          return;
>  
> @@ -277,7 +301,7 @@ static int request_frame(AVFilterLink *link)
>  
>          if ((ret = avfilter_request_frame(link->src->inputs[0])))
>              return ret;
> -    } while (!yadif->cur);
> +    } while (!yadif->out);
>  
>      return 0;
>  }
> @@ -299,6 +323,9 @@ static int poll_frame(AVFilterLink *link)
>      }
>      assert(yadif->next || !val);
>  
> +    if (yadif->skip)
> +        return val;
> +
>      return val * ((yadif->mode&1)+1);
>  }
>  
> @@ -344,9 +371,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
>  
>      yadif->mode = 0;
>      yadif->parity = -1;
> +    yadif->auto_enable = 0;
>      yadif->csp = NULL;
>  
> -    if (args) sscanf(args, "%d:%d", &yadif->mode, &yadif->parity);
> +    if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable);
>  
>      yadif->filter_line = filter_line_c;
>      if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
> @@ -356,7 +384,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
>      else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
>          yadif->filter_line = ff_yadif_filter_line_mmx;
>  
> -    av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d\n", yadif->mode, yadif->parity);
> +    av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable);

Please add mention of the new option on the manual, in
doc/filters.texi.

As for the patch it looks fine to me, but I'd prefer if Michael could
review it.
-- 
FFmpeg = Freak Formidable Muttering Plastic Eretic Gem


More information about the ffmpeg-devel mailing list