[FFmpeg-user] RGB-YUV color shift

George L.P. Fitz george at glpf.net
Fri Oct 19 18:45:52 CEST 2012


On Oct 18, 2012, at 4:09 AM, Tim Nicholson wrote:

> On 18/10/12 00:03, George L.P. Fitz wrote:
>> Hello,
>> 
>> I am seeing a slight color shift when using ffmpeg to encode to yuv based codecs like prores and v210 from an rgb source.  The resulting file has slightly more saturation and gamma than the original- it doesn't look way different, but there is enough of a difference to be noticed.  I'm assuming this has to do with the rgb->yuv colorspace conversion, since encoding from a yuv source to a yuv codec shows no perceivable color difference.  Has anyone run across this and if so, found a way to keep the color shift negligible?
>> 
> 
> Although ffmpeg supports a number of colourspace definitions. Third
> party applications that use the libs make use of these choices but not
> currently ffmpeg*, it only ever uses its SWS_CS_DEFAULT which is set to
> BT601/BT470BG/SMPTE170m etc etc. IF you are working with HD pictures you
> really want BT709/SMPTE240.
> 
> So either you have to convert RGB->yuv the use the
> "colormatrix" filter, which may lead to some concatenation/rounding
> errors, or change the ffmpeg default to your required colourspace and
> recompile.

Tim, I tried changing the ffmpeg default since for this particular project I'm working on, all the source clips will always be in BT709:

In the source tree, I modified ffmpeg/libswscale/swscale.h

BEFORE:
#define SWS_CS_ITU709         1
#define SWS_CS_FCC            4
#define SWS_CS_ITU601         5
#define SWS_CS_ITU624         5
#define SWS_CS_SMPTE170M      5
#define SWS_CS_SMPTE240M      7
#define SWS_CS_DEFAULT        5

AFTER:
#define SWS_CS_ITU709         1
#define SWS_CS_FCC            4
#define SWS_CS_ITU601         5
#define SWS_CS_ITU624         5
#define SWS_CS_SMPTE170M      5
#define SWS_CS_SMPTE240M      7
#define SWS_CS_DEFAULT        1

Then I recompiled and tested.  However I'm still seeing the same color shift.  As far as you know, should that change I made have worked?

Otherwise, I took your advice on the colormatrix filter.  I used -vf colormatrix=bt601:bt709 and that gives a much better result.  So that seems to be a workable solution, at least for me.  

Thanks very much for the help....

> 
>> Here's a sample command:
>> 
>> ffmpeg -f rawvideo -pix_fmt rgb24 -s 1920x1080 -r 23.976 -i c3yoz4vuuy.video.raw -vcodec prores -profile 3 test.mov
>> 
>> Thanks for any help you can provide
>> 
>> -George
>> [..]
> 
> * There is an advanced AVCodec option of "-colorspace" which ought to
> allow setting of the required values (1 for 709 & 5 for 601) but the
> last time I played with it it made no difference to the output....
> 
> -- 
> Tim
> 






More information about the ffmpeg-user mailing list