580
社区成员
发帖
与我相关
我的任务
分享
bool VideoEncoder::EncodeFrame(NVVE_EncodeFrameParams &sFrameParams, CUdeviceptr dptr_VideoFrame, CUvideoctxlock ctxLock)
{
// If this is the first frame, we can start timing
if (m_nFrameCount == 0)
{
Start();
}
HRESULT hr = S_OK;
if (m_pEncoderParams->iUseDeviceMem)
{
// Copies video frame from system memory, and passes it as a System pointer to the API
switch (m_pEncoderParams->iSurfaceFormat)
{
case UYVY: // UYVY (4:2:2)
case YUY2: // YUY2 (4:2:2)
CopyUYVYorYUY2Frame(sFrameParams, dptr_VideoFrame, ctxLock);
break;
case YV12: // YV12 (4:2:0), Y V U
case IYUV: // IYUV (4:2:0), Y U V
CopyYV12orIYUVFrame(sFrameParams, dptr_VideoFrame, ctxLock);
break;
case NV12: // NV12 (4:2:0)
CopyNV12Frame(sFrameParams, dptr_VideoFrame, ctxLock);
break;
default:
break;
}
sFrameParams.picBuf = NULL; // Must be set to NULL in order to support device memory input
hr = NVEncodeFrame(m_pEncoder, &sFrameParams, 0, (void *)dptr_VideoFrame); //send the video (device memory) to the
}
else
{
// Copies video frame from system memory, and passes it as a System pointer to the API
hr = NVEncodeFrame(m_pEncoder, &sFrameParams, 0, m_pSNRData);
}
if (FAILED(hr))
{
printf("VideoEncoder::EncodeFrame() error when encoding frame (%d)\n", m_nFrameCount);
return false;
}
if (sFrameParams.bLast)
{
m_bLastFrame = true;
m_nLastFrameNumber = m_nFrameCount;
}
else
{
frameSummation(m_nFrameCount);
m_nFrameCount++;
}
return true;
}