[FFmpeg-devel] [PATCH] yadif: Improve pts calculation.

Robert Nagy ronag89 at gmail.com
Sun May 6 22:10:18 CEST 2012


Not sure how well link time_base is handled by other filters. But I believe
this patch simplifies and improves the accuracy of pts calculations for the
yadif filter.

NOTE, not tested.

> From b19990debe1148e5b2f9074405a08dad81612c51 Mon Sep 17 00:00:00 2001
> From: Robert Nagy <ronag89 at gmail.com>
> Date: Sun, 6 May 2012 22:01:10 +0200
> Subject: [PATCH] yadif: Improve pts calculation.
>
> ---
>  libavfilter/vf_yadif.c |   52
+++++++++++++++++++++--------------------------
>  1 files changed, 23 insertions(+), 29 deletions(-)
>
> diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
> index d8e2ad6..fa66dc3 100644
> --- a/libavfilter/vf_yadif.c
> +++ b/libavfilter/vf_yadif.c
> @@ -206,6 +206,8 @@ static void return_frame(AVFilterContext *ctx, int
is_second)
>                                                 AV_PERM_REUSE, link->w,
link->h);
>          avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
>          yadif->out->video->interlaced = 0;
> +        if(yadif->out->pts != AV_NOPTS_VALUE)
> +            yadif->out->pts += 1;
>      }
>
>      if (!yadif->csp)
> @@ -215,28 +217,9 @@ static void return_frame(AVFilterContext *ctx, int
is_second)
>
>      filter(ctx, yadif->out, tff ^ !is_second, tff);
>
> -    if (is_second) {
> -        if (yadif->next->pts != AV_NOPTS_VALUE &&
> -            yadif->cur->pts != AV_NOPTS_VALUE) {
> -            uint64_t next_pts = yadif->next->pts;
> -            uint64_t cur_pts  = yadif->cur->pts;
> -            uint64_t prev_pts = yadif->prev->pts;
> -
> -            uint64_t ft = FFMIN3( cur_pts-prev_pts,
> -                                  next_pts-cur_pts,
> -                                 (next_pts-prev_pts)/2);
> -
> -            if(next_pts - cur_pts < 2*ft)
> -                yadif->out->pts =
> -                    (next_pts&cur_pts) +
> -                    ((next_pts^cur_pts)>>1);
> -            else
> -                yadif->out->pts = cur_pts + ft/2;
> -        } else {
> -            yadif->out->pts = AV_NOPTS_VALUE;
> -        }
> +    if (is_second)
>          avfilter_start_frame(ctx->outputs[0], yadif->out);
> -    }
> +
>      avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1);
>      avfilter_end_frame(ctx->outputs[0]);
>
> @@ -256,14 +239,15 @@ static void start_frame(AVFilterLink *link,
AVFilterBufferRef *picref)
>      yadif->prev = yadif->cur;
>      yadif->cur  = yadif->next;
>      yadif->next = picref;
> -
> +
>      if (!yadif->cur)
>          return;
>
>      if (yadif->auto_enable && !yadif->cur->video->interlaced) {
>          yadif->out  = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
> -        avfilter_unref_buffer(yadif->prev);
> -        yadif->prev = NULL;
> +        avfilter_unref_bufferp(&yadif->prev);
> +        if(yadif->out->pts != AV_NOPTS_VALUE)
> +            yadif->out->pts *= 2;
>          avfilter_start_frame(ctx->outputs[0], yadif->out);
>          return;
>      }
> @@ -273,9 +257,11 @@ static void start_frame(AVFilterLink *link,
AVFilterBufferRef *picref)
>
>      yadif->out = avfilter_get_video_buffer(ctx->outputs[0],
AV_PERM_WRITE | AV_PERM_PRESERVE |
>                                         AV_PERM_REUSE, link->w, link->h);
> -
>      avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
>      yadif->out->video->interlaced = 0;
> +    if(yadif->out->pts != AV_NOPTS_VALUE)
> +        yadif->out->pts *= 2;
> +
>      avfilter_start_frame(ctx->outputs[0], yadif->out);
>  }
>
> @@ -347,9 +333,9 @@ static av_cold void uninit(AVFilterContext *ctx)
>  {
>      YADIFContext *yadif = ctx->priv;
>
> -    if (yadif->prev) avfilter_unref_buffer(yadif->prev);
> -    if (yadif->cur ) avfilter_unref_buffer(yadif->cur );
> -    if (yadif->next) avfilter_unref_buffer(yadif->next);
> +    avfilter_unref_bufferp(&yadif->prev);
> +    avfilter_unref_bufferp(&yadif->cur );
> +    avfilter_unref_bufferp(&yadif->next);
>  }
>
>  static int query_formats(AVFilterContext *ctx)
> @@ -407,6 +393,13 @@ static av_cold int init(AVFilterContext *ctx, const
char *args, void *opaque)
>      return 0;
>  }
>
> +static int out_config_props(AVFilterLink* link)
> +{
> +    link->time_base.den *= 2;
> +
> +    return 0;
> +}
> +
>  static void null_draw_slice(AVFilterLink *link, int y, int h, int
slice_dir) { }
>
>  AVFilter avfilter_vf_yadif = {
> @@ -430,6 +423,7 @@ AVFilter avfilter_vf_yadif = {
>      .outputs   = (const AVFilterPad[]) {{ .name       = "default",
>                                      .type             =
AVMEDIA_TYPE_VIDEO,
>                                      .poll_frame       = poll_frame,
> -                                    .request_frame    = request_frame, },
> +                                    .request_frame    = request_frame,
> +                                    .config_props     =
out_config_props, },
>                                    { .name = NULL}},
>  };
> --
> 1.7.6.msysgit.0


More information about the ffmpeg-devel mailing list