记录一下在转换过程中出现问题,由于宽和高设置设置不正确,造成转换的数据变成全零,全绿。
NVENCSTATUS CNvEncoder::ConvertRGBToNV12(IDirect3DSurface9 *pSrcRGB, IDirect3DSurface9 *pNV12Dst, uint32_t uWidth, uint32_t uHeight)
{
DXVA2_VideoProcessBltParams vpblt;
DXVA2_VideoSample vs;
D3DSURFACE_DESC desc;
pSrcRGB->GetDesc(&desc);
//此处将数据进行进行拉伸,如果数据不正确,数据会变成0
RECT srcRect = { 0, 0, desc.Width, desc.Height };
RECT dstRect = { 0, 0, uWidth, uHeight };
// Input
memset(&vs, 0, sizeof(vs));
vs.PlanarAlpha.ll = 0x10000;
vs.SrcSurface = pSrcRGB;
vs.SrcRect = srcRect;
vs.DstRect = dstRect;
vs.SampleFormat.SampleFormat = DXVA2_SampleProgressiveFrame;
vs.SampleFormat.VideoChromaSubsampling = DXVA2_VideoChromaSubsampling_MPEG2;
vs.SampleFormat.NominalRange = DXVA2_NominalRange_0_255;
vs.SampleFormat.VideoTransferMatrix = DXVA2_VideoTransferMatrix_BT601;
// Output
memset(&vpblt, 0, sizeof(vpblt));
vpblt.TargetRect = dstRect;
vpblt.DestFormat = vs.SampleFormat;
vpblt.DestFormat.SampleFormat = DXVA2_SampleProgressiveFrame;
vpblt.Alpha.ll = 0x10000;
vpblt.TargetFrame = vs.Start;
vpblt.ProcAmpValues.Brightness = m_Brightness.DefaultValue;
vpblt.ProcAmpValues.Contrast = m_Contrast.DefaultValue;
vpblt.ProcAmpValues.Hue = m_Hue.DefaultValue;
vpblt.ProcAmpValues.Saturation = m_Saturation.DefaultValue;
vpblt.BackgroundColor.Y = 0x1000;
vpblt.BackgroundColor.Cb = 0x8000;
vpblt.BackgroundColor.Cr = 0x8000;
vpblt.BackgroundColor.Alpha = 0xffff;
HRESULT hr = m_pDXVA2VideoProcessor->VideoProcessBlt(pNV12Dst, &vpblt, &vs, 1, NULL);
return NV_ENC_SUCCESS;
}