Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

UYUV to NV12

Kamal_Devanga
Beginner
931 Views

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
931 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

0 Kudos
Kamal_Devanga
Beginner
931 Views

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

0 Kudos
Jiandong_Z_Intel
Employee
931 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.

 

0 Kudos
Reply