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

Andy Furniss adf.lists at gmail.com
Wed Aug 21 00:04:49 CEST 2013

mokacao wrote:
> I generated a test that contains a variety of colors pictures,
> red/green have black dot.
> Here is part of the core code:

It's the same using ffmpeg directly, but there's probably nothing wrong
with the rgb -> yuv420p and using the flags below for this conversion
does not affect the outcome.

A more interesting test would be to find something else that can make
yuv420p from rgb.

> original png file
> <http://ffmpeg-users.933282.n4.nabble.com/file/n4660789/P0001.png>
> yuv420p zoom in 4x, use the software yuv
> viewer(http://sourceforge.net/projects/yuviewer/), and screenshot

So yuviewer does the same yuv -> rgb scale as ffmpeg in default mode.

> <http://ffmpeg-users.933282.n4.nabble.com/file/n4660789/P0001_yuv_zoom_in_4x.png>
 > original png file to yuv420p use above code
> P0001.yuv
> <http://ffmpeg-users.933282.n4.nabble.com/file/n4660789/P0001.yuv>

Playing your .yuv looks fine with ffplay and mplayer + three different
ways of using my gpu to scale/csc.

It's likely that anyone playing your yuv with a normal player that will
choose h/w to scale/csc won't see the issue.

Due to the height being >=720 some code may assume it's 709 rather than
601 colourspace, but that's nothing to do with this issue.

ffmpeg -s 1024x768 -pix_fmt yuv420p -i P0001.yuv P0001-noopt.png

Will show the artifacts you see

ffmpeg -s 1024x768 -pix_fmt yuv420p -i P0001.yuv -sws_flags
+accurate_rnd+full_chroma_int P0001-arfc.png

Doesn't produce them, so it looks like the yuv its self is sound, but
the accuracy of yuviewer/ffmpeg default is the issue when converting
back to rgb.

More information about the ffmpeg-user mailing list