Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Bob3
Beginner
54 Views

Bad output writing to memory from decoder (h264 with NV12 output)

I'm using the simple_2_decode sample, instead of writing to file I wanted to write to memory. Somewhere along the way I'm getting some bad output. Here are the two functions where I take the output surface and write to an external buffer.

If anymore information is required to help debug, please let me know.

I'm doing H264 (ES) -> NV12 -> YUV420 in memory

 

mfxStatus WriteSectionMemory(mfxU8* plane, mfxU16 factor, mfxU16 chunksize,
	mfxFrameInfo* pInfo, mfxFrameData* pData, mfxU32 i,
	mfxU32 j, unsigned char* out)
{


	mfxU8* plane2 = plane + (pInfo->CropY * pData->Pitch / factor + pInfo->CropX) + i * pData->Pitch + j;
	
	int test = (int)memcpy(out, plane2, chunksize);
	
	if (chunksize != test)
		return MFX_ERR_UNDEFINED_BEHAVIOR;
	return MFX_ERR_NONE;
}

int WriteRawFrame(mfxFrameSurface1* pSurface, unsigned char *output)
{
	mfxFrameInfo* pInfo = &pSurface->Info;
	mfxFrameData* pData = &pSurface->Data;
	mfxU32 i, j, h, w;
	mfxI32 pitch, nByteWrite;
	mfxU8* ptr;
	unsigned char *poutput = output;
	mfxStatus sts = MFX_ERR_NONE;
	int frameBytes = 0;

	for (i = 0; i < pInfo->CropH; i++)
	{
		sts = WriteSectionMemory(pData->Y, 1, pInfo->CropW, pInfo, pData, i, 0, poutput);
		poutput += pInfo->CropW;
		frameBytes += pInfo->CropW;
	}

	h = pInfo->CropH/2;
	w = pInfo->CropW;
	for (i = 0; i < h; i++) {

		for (j = 0; j < w; j += 2)
		{
			sts = WriteSectionMemory(pData->UV, 2, 1, pInfo, pData, i, j, poutput);
			poutput += 1;
			frameBytes++;
		}

	}

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

		for (j = 1; j < w; j += 2)
		{
			sts = WriteSectionMemory(pData->UV, 2, 1, pInfo, pData, i, j, poutput);
			poutput += 1;
			frameBytes++;

		}
	}
	return frameBytes;
}

 

 

Below is what the output looks like when using the normal file writing functions, and the bad output is from these memory output functions. Any ideas on what could be causing the warping/discoloration?

Good Output

 

0 Kudos
1 Reply
Ramashankar
New Contributor III
54 Views

Hi Bob,

By seeing the second output image, it looks like somehow 1 or 2 pixel is being processed less in width, but your code for copying data from surface to memory looks correct (though it can be made more simpler than this).

What are your frame width and height here? Are you manipulating the output buffer again due to any reason before rendering? Can you share the code block where you are doing file write which is rendered fine?

Reply