Transformation from YUY2 to UYVY


I can capture video with logitech QuickCam Pro9000 in YUY2 format. But My encoder only takes video in UYVY format. Is there any tool or any API to transform YUY2 to UYVY?? I need help on this. If any one can share any idea then also it helps me.


Anirban Roy Choudhury[Y]

1 Reply

  • These formats look to be almost the same, just the ordering of the bytes is reversed based on the descriptions from here for UYVY and here for YUY2. So it sounds like you are getting YUYVYUYVYUYV... and you need UYVYUYVYUYVY...

    For a dirty method that would at least align your colors correctly you could just offset the image array by one byte so that it starts with a U instead of a Y (which would be dropped), this should get you to having real color instead of the neon green/pink image I suspect you are getting now.

    The real way to do it would be to write a small loop that swaps every pair of bytes in the image, I do not believe there is a tool or API in our software package to handle this but it should be fairly easy to handle. Something like the pseudo code below:

    char_pointer_to_image_next=char_pointer_to_image-1;      //set second pointer to one byte ahead of the first pointer
    for(line=0;line<480;line++){       //count off lines
      for(pixel=0;pixel<720;pixel++){        //count off byte pairs
         tempval = *char_pointer_to_image;      //save the first byte
         *char_pointer_to_image= *char_pointer_to_image_next;      //write second byte to first
         *char_pointer_to_image_next = tempval;      //write saved first byte to second
         char_pointer_to_image_next-=2;      //move second pointer down the image two bytes
         char_pointer_to_image-=2;      //move first pointer down the image two bytes