[FFmpeg-devel] [PATCH] swscale: add API to convert AVFrames directly

Michael Niedermayer michaelni at gmx.at
Tue Oct 1 01:43:36 CEST 2013


On Tue, Oct 01, 2013 at 01:10:59AM +0200, wm4 wrote:
> On Mon, 30 Sep 2013 17:39:37 +0200
> Michael Niedermayer <michaelni at gmx.at> wrote:
> 
> > On Sun, Sep 29, 2013 at 08:21:35PM +0200, wm4 wrote:
> > > On Sun, 29 Sep 2013 17:50:52 +0200
> > > Michael Niedermayer <michaelni at gmx.at> wrote:
> > [...]
> > > > 
> > > > 
> > > > > diff --git a/libswscale/swscale.h b/libswscale/swscale.h
> > > > > index 42702b7..60733f0 100644
> > > > > --- a/libswscale/swscale.h
> > > > > +++ b/libswscale/swscale.h
> > > > > @@ -39,6 +39,8 @@
> > > > >  #include "libavutil/pixfmt.h"
> > > > >  #include "version.h"
> > > > >  
> > > > > +struct AVFrame;
> > > > > +
> > > > >  /**
> > > > >   * Return the LIBSWSCALE_VERSION_INT constant.
> > > > >   */
> > > > > @@ -169,6 +171,81 @@ struct SwsContext *sws_alloc_context(void);
> > > > >  int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);
> > > > >  
> > > > >  /**
> > > > > + * Set source filter. This works only with sws_reinit_cached_context() and
> > > > > + * sws_scale_frame().
> > > > > + *
> > > > > + * @return zero or positive value on success, a negative value on
> > > > > + * error
> > > > > + */
> > > > > +int sws_set_src_filter(struct SwsContext *sws_context, SwsFilter *srcFilter);
> > > > > +
> > > > > +/**
> > > > > + * Set destination filter. This works only with sws_reinit_cached_context() and
> > > > > + * sws_scale_frame().
> > > > > + *
> > > > > + * @return zero or positive value on success, a negative value on
> > > > > + * error
> > > > > + */
> > > > > +int sws_set_dst_filter(struct SwsContext *sws_context, SwsFilter *dstFilter);
> > > > 
> > > > would it make sense to allow seting the filter via AVOption as a
> > > > char* ?
> > > > iam wondering because this maybe would avoid these 2 functions
> > > 
> > > SwsFilter is a struct with 4 SwsVector members, so I'm not sure how
> > > that would work. Also, I need to know if the filter changes. These
> > > functions basically set a flag that they changed, and if they use the
> > > AVOption API, I'd have to compare the SwsFilters with the old state to
> > > detect a change.
> > 
> > the char * string could allow something like
> > 
> > "1,2,1" (simple lowpass applied to luma & chroma & horizontal and vertical)
> > "v:1,2,1" same lowpass applied only to vertical luma & chroma that is poor deinterlace
> > "lh:0,0,1,ch:0,0.5,0.5" horizontal shift luma by 1 pixelm chroma by half a pixel
> > 
> > thats just a quick and random idea for a syntax and probably a bit of topic
> > so its more for consideration of future design direction ...
> 
> That really goes beyond of being able to set SwsFilters. My main
> problem here was that the SwsFilters can be set only with
> sws_init_context, 
> 

> > one advantage of such string based system with AVOptions is that it
> > shouldnt require any specific code in a user application that supports
> > avoptions
> 
> Passing through AVOptions in user facing applications is more than
> awkward.

> The worst about it is that you typically don't have the list
> of valid AVOptions in advance, only once you created the object. (And
> even then I'm not sure if you can list them at all... but I don't know
> the API too well.)

sws_get_class() will return the AVClass with the AVOption array
you can just go over the array entries and do whatever you want with
the options build a GUI list, print help (like av_opt_show2() does) or
something else



> 
> > > By the way, I'm not all that sure whether my patch is correct.
> > > libswscale is very scary, and there could be some things I missed. In
> > > particular, there's the question whether sws_uninit_context followed
> > > sws_init_context really does full reinitialization, or if there are
> > > additional members that must be reset in sws_uninit_context. (Members
> > > which are set only by some init code paths, but are read by everything
> > > would belong into this category.)
> > 
> > you could try to memset the context to some non 0 value on alloc
> > and clear just the values from uninit and then try fate
> 
> I implemented this. It should be relatively "safe" now, because it
> redoes everything as if sws_alloc_context() had been called. The
> copy_settings() function copies back the old settings.
> 
> New patch attached. (I didn't run any extensive tests though - because
> it's a new API and nothing uses it.)

[...]
> @@ -303,6 +385,7 @@ SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
>                                  float lumaSharpen, float chromaSharpen,
>                                  float chromaHShift, float chromaVShift,
>                                  int verbose);
> +SwsFilter *sws_cloneFilter(SwsFilter *filter);
>  void sws_freeFilter(SwsFilter *filter);
>  
>  /**

this could be a seperate patch

the rest of teh API looks reasonable, ill apply it in a few days
if there are no comments from others

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131001/fe7923e3/attachment.asc>


More information about the ffmpeg-devel mailing list