2015-05-06 56 views
1

我對DirectX和c#來說是相當新的,我嘗試處理來自另一個視頻流的HDMI視頻流(60 fps) PC(使用Directx C#)。我正在使用視頻捕捉卡捕捉視頻。此外,我的一段代碼使我能夠完美地捕捉視頻。如何使用DirectX捕捉視頻的幀

但是,我有一個要求,我需要能夠同時處理視頻幀(可能在一個單獨的線程中)。

我一直在使用AForge庫捕捉幀嘗試,但只有具有集成的Web camera.When工作我嘗試喲與採集卡運行這個只顯示黑屏 任何參考指針或鏈接會非常感謝。

+0

我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

回答

0

最後,我自己找到了解決方案。可以使用Directshow的SampleGrabber方法提取視頻流的幀。

/// <summary> Interface frame event </summary> 
public delegate void HeFrame(System.Drawing.Bitmap BM); 
/// <summary> Frame event </summary> 
public event HeFrame FrameEvent2; 
private byte[] savedArray; 
private int bufferedSize; 

int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, 
    int BufferLen) 
{ 
    this.bufferedSize = BufferLen; 

    int stride = this.SnapShotWidth * 3; 

    Marshal.Copy(pBuffer, this.savedArray, 0, BufferLen); 

    GCHandle handle = GCHandle.Alloc(this.savedArray, GCHandleType.Pinned); 
    int scan0 = (int) handle.AddrOfPinnedObject(); 
    scan0 += (this.SnapShotHeight - 1) * stride; 
    Bitmap b = new Bitmap(this.SnapShotWidth, this.SnapShotHeight, -stride, 
     System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr) scan0); 
    handle.Free(); 
    SetBitmap=b; 
    return 0; 
} 
/// <summary> capture event, triggered by buffer callback. </summary> 
private void OnCaptureDone() 
{ 
    Trace.WriteLine("!!DLG: OnCaptureDone"); 
} 
/// <summary> Allocate memory space and set SetCallBack </summary> 
public void GrapImg() 
{ 
    Trace.Write ("IMG"); 
    if(this.savedArray == null) 
    { 
     int size = this.snapShotImageSize; 
     if((size < 1000) || (size > 16000000)) 
      return; 
     this.savedArray = new byte[ size + 64000 ]; 
    } 
    sampGrabber.SetCallback(this, 1); 
} 
/// <summary> Transfer bitmap upon firing event </summary> 
public System.Drawing.Bitmap SetBitmap 
{ 
    set 
    { 
     this.FrameEvent2(value); 
    } 
} 

Here是鏈接到Article.Might幫助一些之一,因爲它花了我很多時間去這一點。