Log in

View Full Version : Convert JPEG to YUV


roozhou
25th November 2009, 14:26
The problem comes from converting JPEG sequence to video using mencoder. Mencoder decodes JPEG images with mjpeg codecs and the color is incorrect. I know that decoding JPEG to RGB and converting back to YUV works, but this will introduce error.

Could someone provide coefficients of converting JPEG YUV to Rec601/Rec709 YUV. It should looks like:

Y2 = AxY1 + BxU1 + CxV1 + D
U2 = ...
V2 = ...

Sagekilla
27th November 2009, 01:44
What you're looking for is a YCbCr -> YUV conversion. A quick look on Wikipedia will provide the necessary coefficients for RGB -> YCbCr, and RGB -> YUV (Rec601, Rec709). You'll need to do a little math to solve for YCbr = YUV.

roozhou
27th November 2009, 10:07
Thanks, I got it here (http://en.wikipedia.org/wiki/YCbCr).
Well I am just too lazy to do the math myself ... I will post the results when I finish this.

Wilbert
4th December 2009, 23:33
I thought that JPEG YUV = PC601 YCbCr (ie full range). Is that not the case?

roozhou
11th December 2009, 11:34
I thought that JPEG YUV = PC601 YCbCr (ie full range). Is that not the case?

Yes, so converting JPEG to BT.601 is quite easy:

Y2 = Y1 * 219 / 255 + 16
C2 = C1 * 224 / 255 + 16

JPEG -> BT.709 is a bit complicated. I haven't yet worked it out.