Video encoders like Intel® Media SDK require NV12 video input format.
NV12 format is YUV 4:2:0 format ordered in memory with a Y plane first, followed by packed chroma samples in interleaved UV plane.
Example:
YYYYYY
YYYYYY
UVUVUV
RGB color format, refers to Pixel-Order RGB (byte per pixel, lower byte is Red):
RGBRGBRGBRGBRGB
RGBRGBRGBRGBRGB
I did some Web research, and found out that regarding NV12, YUV is defined as YCbCr color space. There are currently at least 2 possible YCbCr formats apply NV12:
My question is: Is there as IPP function that converts RGB color space to NV12?
I found out that IPP function exists:
ippiRGBToYCbCr420_8u_C3P2R
It was hard to find, because the function name or description does not mention NV12.
The function uses BT.601 standard.
Here is a code sample for converting RGB to NV12 in BT.601 standard:
Converting RGB to NV12 with BT.709 standard:
As for 2019, BT.709 (HDTV) standard is probably more relevant than BT.601 (SDTV).
IPP lacks a function for direct conversion from RGB to NV12 in BT.709 standard.
There is a function that converts BGR to NV12.
The solution includes two stages:
Code sample uses
ippiSwapChannels_8u_C3R
for RGB to BGR conversion.Code sample uses
ippiBGRToYCbCr420_709CSC_8u_C3P2R
for BGR to NV12 conversion.The sample function requires some extra memory space for storing the intermediate BGR image.
A pointer to the sketch memory is passed to the function (the memory should be allocated outside the function).
Here is a code sample for converting RGB to NV12 in BT.709 standard: