[FFmpeg-devel] [PATCH] libavfilter-soc: make scale algorithm configurable

Michael Niedermayer michaelni
Sun Feb 22 20:43:14 CET 2009


On Sun, Feb 22, 2009 at 07:32:19PM +0100, Stefano Sabatini wrote:
> On date Tuesday 2009-02-17 01:40:47 +0100, Stefano Sabatini encoded:
> [...]
> > New round, no hurry to review it since I want to think something more
> > about it.
> 
> Patches cleaned-up, some bug fixed, choosen a better name for
> AVFilterGraph::sws_opts (now is scale_sws_opts).
> 
> Summary:
> * vf-scale-use-getcached-ctx.patch
>   Use sws_getCacehdContext() in config_props, the context is alloced
>   in the first place in init(), while the srcSlice h/w, dst h/w are
>   set in config_props.
> 
>   This allows to avoid to create a context just to store the
>   sws_flags.
> 
> * vf-scale-cosmetics.patch
>   Reindent + minor cosmetics.
> 
> * vf-scale-set-scale-sws-opts.patch
> 
>   Implement the sws-opts parsing, in particular parse the sws_flags
>   option in the sws_opts eventually provided in the args (mmh, maybe
>   this should be split).
> 
>   The sws_flags is set in the context, this value is re-set in
>   config_props() when sws_getCachedContext() is used to create the new
>   sws context with the srcSlice h/w, dst h/w parameters.
> 
> * filtergraph-scale-sws-opts.patch
>   Implement the scale_sws_opts in the graph, the scale_sws_opts will
>   be appended to the args to pass to the auto-inserted scale filters.
> 
> * ffmpeg-send-scale-sws-opts.patch
>   Make possible to set in ffmpeg the scale_sws_opts to use for the
>   auto-inserted scale filters, and set the sws_flags CLI option in the
>   filters graph.
> 
>   Fixes regressions test.
> 
> * ffplay-send-sws-flags.patch
>   Set the scale_sws_opts value to use in the auto-inserted scale filters,
>   setting it in the graph.
> 
>   IMO it should be possible for the user to set this value in some way
>   similar to what ffmpeg does after the last patch, now it is
>   currently hardcoded.
> 
> ...
> 
> Regards.
> -- 
> FFmpeg = Free and Faboulous Murdering Problematic Egregious Glue

> Index: libavfilter-soc/ffmpeg/libavfilter/vf_scale.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/vf_scale.c	2009-02-22 17:59:11.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/vf_scale.c	2009-02-22 18:38:51.000000000 +0100
> @@ -46,6 +46,9 @@
>      scale->w =
>      scale->h = 0;
>  
> +    if (!(scale->sws = sws_getContext(16,16,0, 16,16,0, SWS_BILINEAR, NULL,NULL,NULL)))
> +        return -1;
> +
>      if(args)
>          sscanf(args, "%d:%d", &scale->w, &scale->h);
>  
> @@ -87,9 +90,6 @@
>      ScaleContext *scale = link->src->priv;
>      int w, h;
>  
> -    if(scale->sws)
> -        sws_freeContext(scale->sws);
> -
>      w = scale->w;
>      h = scale->h;
>      if(!w)      w = link->src->inputs[0]->w;
> @@ -98,7 +98,7 @@
>      if(h == -1) h = scale->w*link->src->inputs[0]->h/link->src->inputs[0]->w;
>  
>      /* TODO: make algorithm configurable */
> -    scale->sws = sws_getContext(link->src->inputs[0]->w,
> +    scale->sws = sws_getCachedContext(scale->sws, link->src->inputs[0]->w,
>                                  link->src->inputs[0]->h,
>                                  link->src->inputs[0]->format,
>                                  w, h, link->format, SWS_BILINEAR,

ok


[...]

> Index: libavfilter-soc/ffmpeg/libavfilter/vf_scale.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/vf_scale.c	2009-02-22 19:12:04.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/vf_scale.c	2009-02-22 19:12:06.000000000 +0100
> @@ -22,6 +22,7 @@
>  #include <stdio.h>
>  
>  #include "avfilter.h"
> +#include "libavcodec/opt.h"
>  #include "libswscale/swscale.h"
>  
>  typedef struct
> @@ -41,6 +42,8 @@
>  static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
>  {
>      ScaleContext *scale = ctx->priv;
> +    char sws_opts[256];
> +    const char *p;
>  
>      /* default to no scaling */
>      scale->w =
> @@ -49,8 +52,24 @@
>      if (!(scale->sws = sws_getContext(16,16,0, 16,16,0, SWS_BILINEAR, NULL,NULL,NULL)))
>          return -1;
>  
> -    if(args)
> +     if(args)

ehm?

[...]

> Index: libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/avfiltergraph.c	2009-02-22 19:11:44.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.c	2009-02-22 19:14:12.000000000 +0100
> @@ -111,13 +111,15 @@
>                  if(!avfilter_merge_formats(link->in_formats,
>                                             link->out_formats)) {
>                      AVFilterContext *scale;
> +                    char scale_args[256];
>                      /* couldn't merge format lists. auto-insert scale filter */
>                      snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d",
>                               scaler_count);
>                      scale =
>                          avfilter_open(avfilter_get_by_name("scale"),inst_name);
>  
> -                    if(!scale || scale->filter->init(scale, NULL, NULL) ||
> +                    snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);
> +                    if(!scale || scale->filter->init(scale, scale_args, NULL) ||
>                                   avfilter_insert_filter(link, scale, 0, 0)) {
>                          avfilter_destroy(scale);
>                          return -1;
> Index: libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.h
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/avfiltergraph.h	2009-02-22 19:11:44.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.h	2009-02-22 19:13:12.000000000 +0100
> @@ -27,6 +27,8 @@
>  typedef struct AVFilterGraph {
>      unsigned filter_count;
>      AVFilterContext **filters;
> +
> +    const char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
>  } AVFilterGraph;
>  
>  /**

ok


> Index: libavfilter-soc/ffmpeg/ffmpeg.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/ffmpeg.c	2009-02-22 19:11:44.000000000 +0100
> +++ libavfilter-soc/ffmpeg/ffmpeg.c	2009-02-22 19:16:45.000000000 +0100
> @@ -438,9 +438,10 @@
>          (frame_padtop + frame_padbottom))) {
>          char crop_args[255];
>          AVFilterContext *filt_scale;
> -        snprintf(crop_args, 255, "%d:%d",
> +        int sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
> +        snprintf(crop_args, 255, "%d:%d:sws_flags=%d",
>                   codec->width  - (frame_padleft + frame_padright),
> -                 codec->height - (frame_padtop  + frame_padbottom));
> +                 codec->height - (frame_padtop  + frame_padbottom), sws_flags);
>          filt_scale = avfilter_open(avfilter_get_by_name("scale"), NULL);
>          if (!filt_scale)
>              return -1;
> @@ -473,6 +474,12 @@
>              return -1;
>      }
>  
> +    {
> +        char scale_sws_opts[128];
> +        snprintf(scale_sws_opts, sizeof(scale_sws_opts), "sws_flags=%d", (int)av_get_int(sws_opts, "sws_flags", NULL));
> +        filt_graph_all->scale_sws_opts = scale_sws_opts;
> +    }
> +
>      /* configure all the filter links */
>      if(avfilter_graph_check_validity(filt_graph_all, NULL))
>          return -1;

ehm, you are storing a pointer to the stack in the context ...


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090222/3851c2c7/attachment.pgp>



More information about the ffmpeg-devel mailing list