[FFmpeg-user] How can I convert rbg to yuv420p loseless?

Andy Furniss adf.lists at gmail.com
Tue Aug 20 01:16:27 CEST 2013

bert1974 wrote:
> PIX_FMT_BGRA contains alpha(=transparency) information.. to get the
> transparent edges right, you will have to blend/draw on a background color
> when converting from bgra to rgb. don't know how to do with SwsContext,
> maybe convert/blend rgba->rgb manual, than convert rgb to yuv using
> SwsContext
> (it looks like the image in your mail is blended on black instead of white)

I don't think this is it as the alpha seems to be 255 everywhere on the 
png and the artifacts seem to arise on conversion back to rgb.

Testing on 420 produced from the png with no sws options.

Converting back to rgb with ffmpeg -

ffmpeg -s 890x768 -pix_fmt yuv420p -i 420.yuv -sws_flags 
+accurate_rnd+full_chroma_int -pix_fmt rgb24 420-ar-fc.rgb

is the best looking.

-sws_flags +accurate_rnd still has noticable "black" (really grey) 
pixels but is better than no sws options or
-sws_flags +full_chroma_int which produces exactly the same output 
(md5sum) as no sws options.

More information about the ffmpeg-user mailing list