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

wm4 nfxjfg at googlemail.com
Tue Oct 1 01:10:59 CEST 2013


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.)

> > 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.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-swscale-add-API-to-convert-AVFrames-directly.patch
Type: text/x-patch
Size: 15725 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131001/de7c6302/attachment.bin>


More information about the ffmpeg-devel mailing list