Avatar of Shiv_Sg
Shiv_Sg
 asked on

speed up yuv422 to yuv420 software conversion

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
Multimedia ProgrammingC++MultiMedia Applications

Avatar of undefined
Last Comment
Shiv_Sg

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
algorith

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shiv_Sg

ASKER
Hi Thanks a lot for the quick response.. I currently have dual core CPU so would try to add more threads and see how much it improves..

I am also trying to modify the code based on ur space tradeoff suggestion in para 3, ll let u know how things improve up.

Thanks again.
Regards
Shiv
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy