Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Kamal_Devanga
Beginner
127 Views

UYUV to NV12

I've been experimenting with the following code to convert UYUV to NV12:

void UYVYToUVURow(const std::uint8_t * src_uyvy, int src_stride_uyvy, uint8_t* dst_uv, int width) 
{
	for (int x = 0; x < width; x += 2, src_uyvy += 4, dst_uv += 2) 
	{
		dst_uv[0] = (src_uyvy[0] + src_uyvy[src_stride_uyvy + 0] + 1) >> 1;
		dst_uv[1] = (src_uyvy[2] + src_uyvy[src_stride_uyvy + 2] + 1) >> 1;
	}
}

void UYVYToYRow(const uint8_t* src_uyvy, uint8_t* dst_y, int width) 
{
	for (int x = 0; x < width - 1; x += 2, src_uyvy += 4) 
	{
		dst_y = src_uyvy[1];
		dst_y[x + 1] = src_uyvy[3];
	}
}

int UYVYToNV12(const std::uint8_t * src_uyvy, 
		std::uint8_t * dst_y, 
		std::uint8_t * dst_uv, 
		int src_stride_uyvy, 
		int dst_stride_y, 
		int dst_stride_uv, 
		int width, 
		int height) 
{
	for (int y = 0; y < height - 1; y += 2) 
	{
		UYVYToUVURow(src_uyvy, src_stride_uyvy, dst_uv, width);
		UYVYToYRow(src_uyvy, dst_y, width);
		UYVYToYRow(src_uyvy + src_stride_uyvy, dst_y + dst_stride_y, width);

		src_uyvy += src_stride_uyvy * 2;
		dst_y    += dst_stride_y * 2;
		dst_uv   += dst_stride_uv;
	}

	return 0;
}

(found it on the internets).  It works but I don't like the performance on HD sized images (1280 x 720 for example).  I ran VTune on the UYVYToNV12 function and the average fetch latency was 7 cycles. So the algorithm is probably close to optimal already (it doesn't do much really does it) and there were few if any cache misses.  Everything I tried like reordering code, splitting into two Y loops and so on only made it slower.  

Is this the kind of thing I could do using VPP?

0 Kudos
3 Replies
Jiandong_Z_Intel
Employee
127 Views

Hi There,

Currently UYUV to NV12 does not support by MSDK.

Color space conversion are support by MSDK can refer to "Table 2: Color Conversion Support in VPP* " in Page 7 in https://software.intel.com/sites/default/files/managed/47/49/mediasdk-man.pdf

 

Best Regards,

Zachary

Kamal_Devanga
Beginner
127 Views

Thanks.  I see it does YUY2 conversion.  Does this happen in hardware or does the driver to it in software, I wonder?

Jiandong_Z_Intel
Employee
127 Views

Yes, YUY2 is support, and YUY2 and UYUV are similar, but UYUV is not support.  maybe you interesting Intel IPP (https://software.intel.com/en-us/intel-ipp), maybe you can find some functions help to do this.

 

Reply