How to acquire a NV12 data after decoding in H264?

How to acquire a NV12 data after decoding in H264?

nrson's picture

Hi, All

I have a few quesetions during testing a sample decode in MSDK 2012.

1. when I output NV12 format after decoding in H264, the output result is good as like figure(No error.png).

but I rewrite the source as following:

    BYTE* pDec = new BYTE [pmfxOutSurface->Info.CropW * pmfxOutSurface->Info.CropH * 3 / 2];     

    memcpy( pDec, pmfxOutSurface->Data.Y, pmfxOutSurface->Info.CropW * pmfxOutSurface->Info.CropH); 

    memcpy( pDec + pmfxOutSurface->Info.CropW * pmfxOutSurface->Info.CropH, pmfxOutSurface->Data.UV, pmfxOutSurface->Info.CropW * pmfxOutSurface->Info.CropH / 2);

the parts of output image are a few errors as like figure(imgae errors after decoding).

I thought that the arrays of UV are wrong. I rewrited the source as like your WriteNextFrame() in source. the rewrited source is next following:

int h = pmfxOutSurface->Info.CropH / 2;

int w = pmfxOutSurface->Info.CropW;

for (int i = 0; i < h; i++) {  

    for (int j = 0; j < w; j += 2)  {    

     memcpy(pDec + (pmfxOutSurface->Info.CropW * pmfxOutSurface->Info.CropH) + pmfxOutSurface->Data.Pitch * i + j, pmfxOutSurface->Data.UV + (pmfxOutSurface->Info.CropY * pmfxOutSurface->Data.Pitch / 2 + pmfxOutSurface->Info.CropX) + i * pmfxOutSurface->Data.Pitch + j, 1);                                   

     }

 }

for (int i = 0; i < h; i++) {  

     for (int j = 1; j < w; j += 2)  {  

         memcpy(pDec + (pmfxOutSurface->Info.CropW * pmfxOutSurface->Info.CropH) + pmfxOutSurface->Data.Pitch * i + j, pmfxOutSurface->Data.UV + (pmfxOutSurface->Info.CropY * pmfxOutSurface->Data.Pitch / 2 + pmfxOutSurface->Info.CropX)+ i * pmfxOutSurface->Data.Pitch + j, 1);  

    }

 }

But the errors are same to first test.

2. I want to resize the image using ippiResizeYUV420_8u_P2R after decoding. but this is a few errors as like figure(resize error).

My resize source is as following:

int ResizeToWidth = 320;

int ResizeToHeight = 240;

BYTE* pDestY = new BYTE[ ResizeToWidth * ResizeToHeight ];

BYTE* pDestUV = new BYTE[ ResizeToWidth * ResizeToHeight / 2 ];

Ipp64f xRatio = static_cast<Ipp64f> (pmfxOutSurface->Info.CropW)  / static_cast<Ipp64f> (ResizeToWidth);

Ipp64f yRatio = static_cast<Ipp64f> (pmfxOutSurface->Info.CropH) / static_cast<Ipp64f> (ResizeToHeight);

IppiSize srcRoiSize = { pmfxOutSurface->Info.CropW, pmfxOutSurface->Info.CropH};

IppiSize dstRoiSize = { ResizeToWidth, ResizeToHeight };

int nBufSIze = 0;

ippiResizeYUV420GetBufSize( srcRoiSize, dstRoiSize, IPPI_INTER_SUPER, &nBufSIze);

Ipp8u *pBuffer = new Ipp8u[ nBufSIze ];

IppStatus rErr = ippiResizeYUV420_8u_P2R( (Ipp8u*) pmfxOutSurface->Data.Y, int(pmfxOutSurface->Info.CropW),  (Ipp8u*) pmfxOutSurface->Data.VU, int(pmfxOutSurface->Info.CropW / 2), srcRoiSize,  (Ipp8u*) pDestY, ResizeToWidth,  (Ipp8u*) pDestUV, (ResizeToWidth / 2), dstRoiSize,   IPPI_INTER_SUPER, (Ipp8u*) pBuffer);

 How do I solve the problems?

Thank in advances.

nrson

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.