我正在尝试使用BlackMagic SDK编写预览应用程序,但播放速度不稳定.我正在使用MFC框架,并将CWnd子类化为我的视频预览窗口.
当每帧视频到达时,我会进行RGB颜色转换,然后调用一个函数来显示RGB位图.
void VideoPreview::Display(int width, int height, byte* buffer)
{
__int64 begin = GetTickCount();
HRESULT hr;
CRect rcRect, statusBarRect;
GetClientRect (rcRect);
BITMAPINFO bmInfo;
ZeroMemory(&bmInfo, sizeof(BITMAPINFO));
bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biBitCount = 32;
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biWidth = width;
bmInfo.bmiHeader.biHeight = -height;
dc->SetStretchBltMode(COLORONCOLOR);
int iResult = StretchDIBits(*dc,
rcRect.left, rcRect.top, rcRect.right, rcRect.bottom,
0, 0, width, height,
buffer, &bmInfo, 0, SRCCOPY);
DWORD dwError;
if (iResult == 0 || iResult == GDI_ERROR)
{
dwError = GetLastError();
}
else
fpsCount++;
procTimeCount += GetTickCount() - begin; …Run Code Online (Sandbox Code Playgroud)