[Libav-user] A question about sws_scale and pointer types

Jonathan Arnold jdarnold at buddydog.org
Wed Sep 28 14:42:22 CEST 2011

On Tue, 27 Sep 2011 19:06:49 -0700
James Felix Black <jfb at homonculus.net> wrote:

> All,
> I have a chunk of code that creates an AVPicture from a raw stream of
> YUV420P, and rescales it.  Easy-peasy, but I'm getting the error:
> zc_libav.c:29: error: passing argument 2 of ‘sws_scale’ from
> incompatible pointer type
> (I run -pedantic-errors when building test builds.)
> Looking at libswscale/swscale.h, I see that the function signature is:
> int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[],
>               const int srcStride[], int srcSliceY, int srcSliceH,
>               uint8_t* const dst[], const int dstStride[]);
> My code (assume that in_pic and out_pic are properly generated
> AVPictures):
>   sws_scale(sws_ctx, 
>             in_pic->data,
>             in_pic->linesize, 
>             0, 
>             in->y, 
>             out_pic->data, 
>             out_pic->linesize); 
> I'm happy to cast that 'in_pic->data' to get the compiler to shut up,
> but I don't know how.  If I turn off errors (-pedantic), it compiles
> and runs fine.  So this is really about my neurotic need not to see
> warnings, I guess.  But I'm still curious as to how someone with more
> C experience would handle this.  Am I doomed to special-casing this
> makefile rule to turn off -pedantic-errors?  That would make me sad,
> but then again, there is much that makes me sad.

The prototype says sws_scale wants a const uint8_t * const *, but the
data array is not declared as such. so you need the following typecast:

            (const uint8_t* const*)in_pic->linesize, 

Hope this helps.
Jonathan Arnold        Webstream: http://hieronymus.soup.io

Talent wins games, but team work and intelligence wins championships.
Michael Jordan

More information about the Libav-user mailing list