[Libav-user] JPEG YUV->RGB

Steffen Ebersbach ebersbac at hs-mittweida.de
Fri May 13 07:58:36 CEST 2011


Am 12.5.2011 16:09, schrieb Dmitriy K:
> Is there any examples of this conversion?
> I've found YUV_TO_RGB1 and YUV_TO_RGB2 in libavcodec/colorspace.h in documentation, but there is no this file in my system.

The right library is swscale, which is part of libav. For sample code 
have a look at output-example.c (in the path of libav). To convert the 
pixelformat first the source and destination format have to be 
initialized with

img_convert_ctx = sws_getContext(c->width, c->height,
                                            PIX_FMT_YUV420P,
                                            c->width, c->height,
                                            c->pix_fmt,
                                             sws_flags, NULL, NULL, NULL);


look at the documentation for the variables: 
http://ffmpeg.org/doxygen/trunk/swscale_8h.html#4d840b451d893c2cc27eec5fd1fada96


for every picture you have to converted the following function is used:

sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize, 0, 
c->height, picture->data, picture->linesize);


All things that have to do with integer variables, overflows and other 
stuff are handled by the library, so it works very well.


Steffen


More information about the Libav-user mailing list