[Libav-user] How to Convert AV_PIX_FMT_RGB24 to AV_PIX_FMT_YUV420P

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Feb 14 13:28:43 CET 2013

Chris Share <cpsmusic at ...> writes:

> Chris Share <cpsmusic at ...> writes:
> >> The scaling_video.c is close to what I need however the 
> >> conversion is the opposite of what I want. What I'm
> >> not clear about is how to change the "fill_yuv_image" 
> >> function to something like "fill_rgb_image".
> >The function is used to provide an artificial source image.
> >You don't need it since you already have an input image.
> >> How does the RGB data get written into the 
> >> "uint8_t *data[4]"? Is it written consecutively (all R 
> >> values get written to data[0], all G values to data[1], etc.)?
> >That would be planar RGB, see PIX_FMT_GBR.
> >RGB is a packed format, see libavutil/pixfmt.h
> Does that mean I should use AV_PIX_FMT_GBRP as the input format?

It does not mean that.

You should use the input format that your "RGB (0 - 255) 
image data" input uses.

> In pixfmt.h it mentions the following: "///< planar 
> GBR 4:4:4 24bpp". Does this mean that each color 
> value needs to be set to a 24-bit data type?

No, please read the cited line again (carefully).

> Also, I'm still not clear about how to get the RGB data 
> into the "uint8_t *src_data[4]" - how do I actually do 
> this?

You shouldn't.
You set src_data[4] to your input data.

> >Note that all this has limited relevance for you if you 
> >don't rescale yourself but use the scale filter (or 
> >libswscale directly).
> Sorry, but I'm not sure what you mean.

You don't have to do anything with your input data 
(assuming it really is in RGB format), you only 
have to tell the scale filter / libswscale which 
format your data has.

Or in other words: The reason you should understand 
pixfmt.h is not that you have to change your input 
format into something else but that you find the 
corresponding FFmpeg pixel format.

Carl Eugen

More information about the Libav-user mailing list