我是DirectX的新手,而且我有一个新的挑战,我试图处理视频帧(60 fps),作为来自另一台PC的HDMI视频流(使用Directx C#)。我正在使用视频捕获卡来捕获视频。此外,我的代码使我能够完美地捕捉视频。
但是,我需要能够在流媒体上同时处理视频帧(可能在一个单独的线程中)。
我尝试使用 AForge库来捕获帧,但这只适用于集成网络摄像头。当我尝试使用捕获卡运行时,它只显示黑屏 任何指针或链接供参考都将非常感激。
答案 0 :(得分: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是文章的链接。可能会帮助一些人,因为我花了很多时间来实现这个目标。