[Libav-user] JPEG YUV->RGB

Dmitriy K melorn at bk.ru
Thu May 12 09:02:05 CEST 2011

Hi all!

I use libav to decode MJPEG frames from IP-camera and to show some pixels from them on a SDL-surface.
SDL takes only RGB pixels so I have to convert YUV from MJPEG frame to RGB.
I have AVFrame after avcodec_decode_video() and as I see, there data[0] stands for Y component, data[1] - V component and data[2] - U component.
Also, U and V components arrays are twice shorter, so that 1 U or V component stands for 2 Y components.
Then I use formulas found in wikipedia to convert YUV to RGB:

R=Y + 1.370705*(U - 128);
G=Y - 0.698001*(V - 128) - 0.337633*(U - 128);
B=Y + 1.732446*(V - 128);

But in final picture I got colors mismatch in highly white and highly black regions.
For example in pixels that should be black, I have blue or red pixels, and in white regions - only green.

So I have two questions:
1) Am I right in my vision of YUV components position in AVFrame->data arrays ?
2) Is there any way to solve problems with colors mismatch?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110512/5a102fd7/attachment.html>

More information about the Libav-user mailing list