troubleshooting Question

speed up yuv422 to yuv420 software conversion

Avatar of Shiv_Sg
Shiv_Sg asked on
C++MultiMedia ApplicationsMultimedia Programming
2 Comments1 Solution2170 ViewsLast Modified:
Hi,

I have used the following code to convert yuv422 to yuv420 images.

void ConvertUyvyToYuv420P(uint8_t* destFrame,
                                            uint8_t* srcFrame,
                                            int width,
                                            int height)
      {
            
            uint8_t* pyFrame = destFrame;
            uint8_t* puFrame = pyFrame + width*height;
            uint8_t* pvFrame = puFrame + width*height/4;
            
            int uvOffset = width * 4 * sizeof(uint8_t);
            
            int i,j;
            
            for(i=0; i<height-2; i++)
            {
                  for(j=0;j<width;j+=2)
                  {
                        uint16_t calc;
                            if ((i&1) == 0)
                            {
                                  calc = *srcFrame;
                                  calc += *(srcFrame + uvOffset);
                                    calc /= 2;
                                  *puFrame++ = (uint8_t) calc;
                                 }
                             srcFrame++;
                           *pyFrame++ = *srcFrame++;
                           if ((i&1) == 0)
                           {
                              calc = *srcFrame;
                              calc += *(srcFrame + uvOffset);
                              calc /= 2;
                              *pvFrame++ = (uint8_t) calc;
                               }
                           srcFrame++;
                           *pyFrame++ = *srcFrame++;
                      }
               }
       }

When I used this on 1080p input at 30 frames per second I am able to convert only at 15 frames per second, is there any way to improve the above snippets speed or is there a better algorithm for conversion.

Any help would be great!!
Thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros