2012-11-29 57 views
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(); 
+1

一次做一个帧会导致视频波动,因为它太慢了,即使使用今天的处理器。您需要使用视频管道。 –

+0

视频需要尽可能接近实时显示。有关视频管道的任何建议? – wshirey

+0

对不起,如果我有一个建议,我会留下一个答案。 –

回答

0

的Blackmagic自带DirectShow视频源过滤器。使用GraphEditPlus以BlackMagic滤镜作为视频源生成渲染代码。 Renderer过滤器可以链接到您选择的HWND。这应该会提供最佳的性能。

我相信你的当前实现会诱发更多RAMCPU的使用,即使你使用Direct2D来blit缓冲区。

相关问题