8
我正嘗試使用BlackMagic SDK編寫預覽應用程序,但正在變得不連貫的播放。我正在使用MFC框架,併爲我的視頻預覽窗口繼承CWnd。將視頻幀作爲位圖繪製到MFC窗口
當每幀視頻到達時,我會做一個顏色轉換爲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;
}
可以做些什麼來創建更流暢的視頻?
更新:
我結束了Direct2D的,而不是去GDI和已經得到了更好的性能。下面的代碼是我現在使用的渲染什麼:
// initialization
HRESULT hr = D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
&pD2DFactory
);
// Obtain the size of the drawing area.
RECT rc;
GetClientRect(&rc);
// Create a Direct2D render target
hr = pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
this->GetSafeHwnd(),
D2D1::SizeU(
1280, 720
/*rc.right - rc.left,
rc.bottom - rc.top*/)
),
&pRT);
D2D1_BITMAP_PROPERTIES properties;
properties.pixelFormat = D2D1::PixelFormat(
DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE);
properties.dpiX = properties.dpiY = 96;
hr = pRT->CreateBitmap(D2D1::SizeU(1280, 720), properties, &pBitmap);
ASSERT(SUCCEEDED(hr));
// per frame code
// buffer is rgb frame
HRESULT hr;
pRT->BeginDraw();
pBitmap->CopyFromMemory(NULL, buffer, width*4);
pRT->DrawBitmap(pBitmap);
pRT->EndDraw();
一次做一個幀會導致視頻波動,因爲它太慢了,即使使用今天的處理器。您需要使用視頻管道。 –
視頻需要儘可能接近實時顯示。有關視頻管道的任何建議? – wshirey
對不起,如果我有一個建議,我會留下一個答案。 –