[FFmpeg-user] YUV 422P Conversion Clipping detection
tkoole
tom at tomkoole.com
Mon Aug 29 22:41:47 CEST 2011
I'm trying to detect clipping when converting from YUV422p to RGB24. I've
looked through some of the variables included when calling sws_scale() but
didn't find any flags that stood out so I'm trying to convert manually using
the descriptions on wikipedia. http://en.wikipedia.org/wiki/YCbCr
I've tried several different methods of converting but I don't seem to be
getting the proper rgb values. sws_scale converts the image properly however
when I convert it I get values between 16-20;
'img' is just a small struct wrapping the frame
'frame' is the AVFrame containing the image
int vc = 0, uc = 0;
for(DWORD i = 0; i < img.width - 1; i += 2) {
float y1 = img.frame->data[0][i];
float y2 = img.frame->data[0][i+1];
float u = img.frame->data[1][vc++];
float v = img.frame->data[2][uc++];
//int Cr = u;
//int Cb = v;
//float r = y1 + 1.402f * (Cr - 128);
//float g = y1 - 0.344f * (Cb - 128) - 0.714 * (Cr - 128);
//float b = y1 + 1.772f * (Cb - 128);
//int r = y1 + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5);
//int g = y1 - ((Cb >> 2) + (Cb >> 4) + (Cb >> 5)) - ((Cr >> 1) + (Cr >>
3) + (Cr >> 4) + (Cr >> 5));
//int b = y1 + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6);
float r = 255.f / 219.f * (y1 - 0.f) + 255.f / 112.f * 0.701f * (u -
128.f);
float g = 255.f / 219.f * (y1 - 0.f) - 255.f / 112.f * 0.886f * 0.114f /
0.587f * (v - 128.f) - 255.f / 112.f * 0.701f * 0.299f / 0.587f * (u -
128.f);
float b = 255.f / 219.f * (y1 - 0.f) + 255.f / 112.f * 0.886f * (v -
128.f);
rMax = (r > rMax) ? r : rMax;
gMax = (g > gMax) ? g : gMax;
bMax = (b > bMax) ? b : bMax;
rMin = (r < rMin) ? r : rMin;
gMin = (g < gMin) ? g : gMin;
bMin = (b < bMin) ? b : bMin;
// ..... repeat for y2
}
Thanks for your time.
--
View this message in context: http://ffmpeg-users.933282.n4.nabble.com/YUV-422P-Conversion-Clipping-detection-tp3777344p3777344.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.
More information about the ffmpeg-user
mailing list