Convert RGB cv::Mat to NvMediaImage YUV420 SEMI_PLANAR BL type

Please provide the following info (check/uncheck the boxes after creating this topic):
Software Version
DRIVE OS Linux 5.2.6
DRIVE OS Linux 5.2.6 and DriveWorks 4.0
[√] DRIVE OS Linux 5.2.0
DRIVE OS Linux 5.2.0 and DriveWorks 3.5
NVIDIA DRIVE™ Software 10.0 (Linux)
NVIDIA DRIVE™ Software 9.0 (Linux)
other DRIVE OS version
other

Target Operating System
[√] Linux
QNX
other

Hardware Platform
NVIDIA DRIVE™ AGX Xavier DevKit (E3550)
[√] NVIDIA DRIVE™ AGX Pegasus DevKit (E3550)
other

SDK Manager Version
1.9.1.10844
other

Host Machine Version
[√] native Ubuntu 18.04
other

Hi expert,
I have a rgb image in cv::Mat type, how can i convert to NvMediaImage in YUV420 SEMI_PLANAR BL type to encode? Is there any sample codes?

Dear @liuq1,
There are no direct sample from cv::mat to NvMedia yuv420.
You need to convert RGB to RGBA format. After that you can use VIC engine to convert RGBA to YUV format. Please check NvMedia2DBlitEx API usage in nvmimg_2d sample(DRIVE OS Linux)