I try to encode camera ARGB raw video with NVENC SDK 8.0. my project build in visual sudio 2013 linked with cuda tool kit 8.0. my issue is that I’m having trouble to converting ARGB to YUV which needed for encoding. I’m trying to use NPP library as you can see in the following code but it does not work (the output compress video is empty green image), can someone please help me to understand what wrong with the code or It would even be better to get any suggestion to do this converting job with NVIDIA SDK or CUDA (actually I need to convert ARGB to NV12)
NVENCSTATUS CNvEncoderLowLatency::ConvertRGBToNV12NPP(unsigned char *pRGB, unsigned char *yuv[3],int width, int height)
{
NppStatus ret = NPP_SUCCESS;
Npp32u m_RGBPitch;
Npp8u* m_RGBDriver = NULL;
cudaMallocPitch((void**)&m_RGBDriver, (size_t*)&m_RGBPitch, width*4 , height);
int m_stepDestP1,m_stepDestP2,m_stepDestP3;
Npp8u* m_stYuvP1 = nppiMalloc_8u_C1(uInputWidth, uInputHeight, &m_stepDestP1);
Npp8u* m_stYuvP2 = nppiMalloc_8u_C1(uInputWidth/2 , uInputHeight/2 , &m_stepDestP2);
Npp8u* m_stYuvP3 = nppiMalloc_8u_C1(uInputWidth/2 , uInputHeight/2 , &m_stepDestP3);
cudaMemcpy(m_RGBDriver, pRGB, width*height*4, cudaMemcpyHostToDevice);
int d_steps[3] = { m_stepDestP1, m_stepDestP2, m_stepDestP3 };
Npp8u* d_ptrs[3] = { m_stYuvP1, m_stYuvP2, m_stYuvP3 };
NppiSize ROI = { width*4, height };
if ((ret = nppiRGBToYCrCb420_8u_AC4P3R(m_RGBDriver, m_RGBPitch, d_ptrs, d_steps, ROI)) != NPP_SUCCESS)
return NV_ENC_ERR_GENERIC;
cudaMemcpy(yuv[0], d_ptrs[0], width*height , cudaMemcpyDeviceToHost);
cudaMemcpy(yuv[1], d_ptrs[1], width*height /4, cudaMemcpyDeviceToHost);
cudaMemcpy(yuv[2], d_ptrs[2], width*height /4, cudaMemcpyDeviceToHost);
return NV_ENC_SUCCESS;
}