VideoHelp Forum
+ Reply to Thread
Results 1 to 9 of 9
Thread
  1. I have been beating my head for two days and feel really dumb. I have a Microsoft LifeCam Cinema and capturing video from it. I can see the video fine and all that is working. The problem comes in when I want to take a snap shot and save it as a bmp file. I need to convert the data from YUY2 (Compression value of 0x32595559) to RGB so I can save as a BMP file. I am using C++, I only need to do one frame, so speed is not as critical. Every method I have tried creates a picture that is flipped and looks like pink snow. I read the information at fourcc.org. I read the HD paper at “http://www.martinreddy.net/gfx/faqs/colorconv.faq”. There has to be something I am missing, but I cannot figure out what. Thank you in advance.

    I have tried all of the following.

    r = Clamp(y + (1.370705 * (v-128)),0,255);
    g = Clamp(y - (0.698001 * (v-128)) - (0.337633 * (u-128)),0,255);
    b = Clamp(y + (1.732446 * (u-128)),0,255);

    r = Clamp(1.164 * (y - 16) + 1.596 * (v - 128),0,255) ;
    g = Clamp(1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u - 128),0,255) ;
    b = Clamp(1.164 * (y - 16) + 2.018 * (u - 128),0,255) ;

    r = Clamp(y + ( 1.403 * v ),0,255) ;
    g = Clamp(y - ( 0.344 * u ) - ( 0.714 * v ),0,255) ;
    b = Clamp(y + ( 1.770 * u ),0,255) ;

    r = Clamp(((298 * (y - 16) + 409 * (v - 128 )) >> 8),0,255) ;
    g = Clamp(((298 * (y - 16) - 100 * (u - 128) - 208 * (v - 128 ) + 128) >> 8),0,255) ;
    b = Clamp(((298 * (y - 16) + 516 * (u - 128) + 128) >> 8),0,255) ;

    r = Clamp(y + 1.402 * (v - 128),0,255) ;
    g = Clamp(y - 0.34414 * ( u - 128) - 0.71414 * ( v - 128 ), 0, 255) ;
    b = Clamp(y + 1.772 * ( u - 128 ), 0, 255) ;

    r = Clamp((1.3584 * y) + (1.8215 * (v - 137)), 0, 255) ;
    g = Clamp((1.3584 * y) - (0.194 * (2.2179 * (u - 156))) - (0.509 * (1.8215 * (v - 137))), 0, 255) ;
    b = Clamp((1.3584 * y) + (0.194 * (2.2179 * (u - 156))), 0, 255) ;

    r = Clamp(y + ( 1.403 * v ), 0, 255) ;
    g = Clamp(y - ( 0.344 * u ) - ( 0.714 * v ), 0, 255) ;
    b = Clamp(y + ( 1.773 * u ), 0, 255) ;
    Quote Quote  
  2. what format is your video ? if you don't know use mediainfo

    you can take a screenshot though avisynth + avsp , or virtualdub for example

    you can specify the RGB conversion matrix in avisynth e.g. rec601 , rec709 etc....

    avidemux should be able to open most common types of videos and take screenshots
    Last edited by poisondeathray; 18th Aug 2010 at 17:10.
    Quote Quote  
  3. This is a streaming video from a web camera. It is live not file based, so a tool does not work. The application that I am working on has a video chat component. The user asks for a snapshot of the video session. I grab a frame and save it. That is why I need an algorythum and not a utility. I might have miss-understood your comment and I appreciate the quick response. When I get the video format from the API the biHeader says the compression (or format) is YUY2. I hope that helps.
    Quote Quote  
  4. sorry , I misunderstood that it was live feed

    I can't help with the equations, but the programmers behind avisynth will definitely know the answer. You can find some of them at doom9 forums.

    But along the utility train of thought, why not use a screenshot/capturing utility e.g. fraps, snagit etc.... If you only need to push a button and take a screenshot? if it displays properly, the decoder you are using has already converted it to RGB for display on the monitor. Or are you trying to make a program yourself ? You might be able to use graphedit or graphstudio for this
    Quote Quote  
  5. In actuallity this is a nurse talking to a patient during a video visit. The nurse sees the patient, the patient sees the nurse. The nurse needs to take a snapshot of the patient. So the nurses application sends the request to the patients system to take the snapshot, the patients system grabs the frame and saves the bmp, then it sends the bmp back to the nurse's applicaion for saving. I hope this helps clear up my problem.
    Quote Quote  
  6. Maybe this is a dumb question, but if this is a web chat scenario (both nurse and patient are remote from each other, and both have webcams, and can both "see" each other) , why does the request have to go to the patient system ? The decoded image is already in RGB format on the nurses computer. Typical webcam software decodes the transmitted YUY2 video (it's usually going to be some compressed format, not uncompressed YUY2) and decodes it to RGB for display. If you select the pin after the decoder, (e.g. in graphedit) it should already be in RGB format. If you select it before, it will be whatever format was used to send the video data (Probably YV12, not YUY2) . Screen capture or webcam capture software captures the screenshot after the the data has been decoded by the decoder (ie. it's already RGB) , not before . If it's been transmitted with proprietary codec, then you need to decode it first.
    Quote Quote  
  7. The chat session runs in 320x176 (running over POTS). The patients camera switches to 640x480 to grab the snapshot, then switches back. We capture the snap shot at a higher resolution then we can ever run the chat session in. So, capturing it on the nurse's side does not work. Very good question that made me think of why we did it the way we did.
    Quote Quote  
  8. Originally Posted by jrivord View Post
    Every method I have tried creates a picture that is flipped and looks like pink snow.
    It sounds to me like you are sampling YUY2 incorrectly. Or maybe you have a signed vs unsigned problem. First verify you are selecting the Y, U, and V components correctly -- ie build RGB from only Y (R=G=B=Y) to create a grayscale image. Make sure that looks right. Then do the same form U and V (they should be half width). Here are Y, U, and V from an image separated into planar form and stacked horizontally:

    Click image for larger version

Name:	yuv.png
Views:	2456
Size:	78.7 KB
ID:	3151

    Once you have that worked out work on the YUV to RGB conversion. I would use the equations from here:

    http://msdn.microsoft.com/en-us/library/Aa904813#yuvformats_2

    That appears to be the standard rec.601 conversion which most standard definition (and lower) video should use. That's equivalent to your 4th method.
    Last edited by jagabo; 18th Aug 2010 at 19:41.
    Quote Quote  
  9. When you step away from a problem and start to question your fundimenta perceptions, it helps. Turns out that I made another change and was never calling the transform. Color me stupid. No wonder it was not making any difference. Thank you all for your help. Now it is working and I just have to flip the image.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!