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

Michael Niedermayer michaelni
Sun Feb 15 20:41:30 CET 2009


On Fri, Feb 13, 2009 at 02:13:38AM +0100, Stefano Sabatini wrote:
> On date Monday 2009-02-09 19:45:06 +0100, Michael Niedermayer encoded:
> > On Sun, Feb 08, 2009 at 11:45:34PM +0100, Stefano Sabatini wrote:
> > > On date Sunday 2009-02-08 03:01:37 +0100, Michael Niedermayer encoded:
> > > > On Sat, Feb 07, 2009 at 08:30:01PM +0100, Stefano Sabatini wrote:
> [...]
> > > > > But I agree on the limitation of the libswscale API, ideally maybe we
> > > > > should be able to pass in the opaque a pointer to an already allocated
> > > > > swscale context already containing sws flags + vectors + whatever,
> > > > > which we could allocate with something like:
> > > > 
> > > > am i missing something that make this opaque stuff needed, compared to
> > > > simply passing char* ?
> > > 
> > > I'd like to avoid to convert the sws_flags of the AVFilterGraph to a
> > > string when creating and inserting the scale filter.
> > > 
> > > The scale filter should be able to accept in input the sws context
> > > parameters from the args string.
> > > 
> > > But using the args interface for passing the flags from the
> > > AVFilterGraph sws_flags to the scale filter is quite awkward, and
> > > involves doing snprintf in the
> > > query_formats/avfilter_graph_config_formats() code.
> > 
> > i think i prefer if args is used instead of doing funny things with
> > opaque dummy contexts
> 
> New patch, but I still would prefer a solution using somehow a
> SwsContext in the AVFilterGraph.
> 
> Regression tests passed.
> 
> Regards.
> -- 
> FFmpeg = Friendly and Friendly Meaningless Portable Elastic Geek

> Index: libavfilter-soc/ffmpeg/libavfilter/vf_scale.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/vf_scale.c	2009-02-12 23:38:53.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/vf_scale.c	2009-02-13 01:53:42.000000000 +0100
> @@ -22,6 +22,7 @@
>  #include <stdio.h>
>  
>  #include "avfilter.h"
> +#include "libavcodec/opt.h"
>  #include "libswscale/swscale.h"
>  
>  typedef struct
> @@ -35,19 +36,48 @@
>       */
>      int w, h;
>  
> +    int sws_flags;
>      int sliceY;                 ///< top of current output slice
>  } ScaleContext;
>  
>  static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
>  {
>      ScaleContext *scale = ctx->priv;
> +    char sws_opts[255] = "";
>  
>      /* default to no scaling */
>      scale->w =
>      scale->h = 0;
> +    scale->sws_flags = SWS_BILINEAR;
>  
>      if(args)
> -        sscanf(args, "%d:%d", &scale->w, &scale->h);
> +        sscanf(args, "%d:%d:%255s", &scale->w, &scale->h, sws_opts);
> +
> +    if(*sws_opts) {
> +        const char *p;
> +        char sws_flags[255];
> +        struct SwsContext *sws_ctx;
> +

> +        if (!(sws_ctx = sws_getContext(16,16,0, 16,16,0, scale->sws_flags, NULL,NULL,NULL)))
> +            return -1;

i dont like this


[...]
> Index: libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/avfiltergraph.c	2009-02-13 01:52:15.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.c	2009-02-13 02:03:08.000000000 +0100
> @@ -111,13 +111,15 @@
>                  if(!avfilter_merge_formats(link->in_formats,
>                                             link->out_formats)) {
>                      AVFilterContext *scale;
> +                    char sws_flags_str[128];
>                      /* 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(sws_flags_str, sizeof(sws_flags_str), "0:0:sws_flags=%d", graph->sws_flags);
> +                    if(!scale || scale->filter->init(scale, sws_flags_str, NULL) ||
>                                   avfilter_insert_filter(link, scale, 0, 0)) {
>                          avfilter_destroy(scale);
>                          return -1;

why is this needed?
there should be a char * variable in the context and that should be passed as
arg string to each scale vf or what am i missing?


> Index: libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.h
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/avfiltergraph.h	2009-02-13 01:52:15.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/avfiltergraph.h	2009-02-13 01:57:52.000000000 +0100
> @@ -27,6 +27,8 @@
>  typedef struct AVFilterGraph {
>      unsigned filter_count;
>      AVFilterContext **filters;
> +
> +    int sws_flags; ///< flags to be used for the auto-inserted scale filters
>  } AVFilterGraph;
>  
>  /**

char *



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

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus
-------------- 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/20090215/2dda3871/attachment.pgp>



More information about the ffmpeg-devel mailing list