如何使用 Direct Show.net Library 制作屏幕捕获视频?
如何使用 Direct Show.net Library 制作屏幕捕获视频? 我阅读了msdn Direct show文档并找到了在以下代码中更改视频源设备的方法。 此代码将网络摄像头作为视频设备。
public IBaseFilter FindCaptureDevice()
{
int hr = 0;
IEnumMoniker classEnum = null;
IMoniker[] moniker = new IMoniker[1];
object source = null;
// Create the system device enumerator
ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum();
// Create an enumerator for the video capture devices
hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum,0);
DsError.ThrowExceptionForHR(hr);
// The device enumerator is no more needed
Marshal.ReleaseComObject(devEnum);
// If there are no enumerators for the requested type, then
// CreateClassEnumerator will succeed, but classEnum will be NULL.
if (classEnum == null)
{
throw new ApplicationException("No video capture device was detected.\r\n\r\n" +
"This sample requires a video capture device, such as a USB WebCam,\r\n" +
"to be installed and working properly. The sample will now close.");
}
if (classEnum.Next (moniker.Length, moniker, IntPtr.Zero) == 0)
{
Guid iid = typeof(IBaseFilter).GUID;
moniker[0].BindToObject(null, null, ref iid, out source);
}
else
{
throw new ApplicationException("Unable to access video capture device!");
}
Marshal.ReleaseComObject(moniker[0]);
Marshal.ReleaseComObject(classEnum);
return (IBaseFilter) source;
}
How to make screen capture video using Direct Show.net Library?
I read msdn Direct show document and find the way to change video source device within the following code.
This code got webcamera as video device.
public IBaseFilter FindCaptureDevice()
{
int hr = 0;
IEnumMoniker classEnum = null;
IMoniker[] moniker = new IMoniker[1];
object source = null;
// Create the system device enumerator
ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum();
// Create an enumerator for the video capture devices
hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum,0);
DsError.ThrowExceptionForHR(hr);
// The device enumerator is no more needed
Marshal.ReleaseComObject(devEnum);
// If there are no enumerators for the requested type, then
// CreateClassEnumerator will succeed, but classEnum will be NULL.
if (classEnum == null)
{
throw new ApplicationException("No video capture device was detected.\r\n\r\n" +
"This sample requires a video capture device, such as a USB WebCam,\r\n" +
"to be installed and working properly. The sample will now close.");
}
if (classEnum.Next (moniker.Length, moniker, IntPtr.Zero) == 0)
{
Guid iid = typeof(IBaseFilter).GUID;
moniker[0].BindToObject(null, null, ref iid, out source);
}
else
{
throw new ApplicationException("Unable to access video capture device!");
}
Marshal.ReleaseComObject(moniker[0]);
Marshal.ReleaseComObject(classEnum);
return (IBaseFilter) source;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个过滤器来捕获屏幕并将视频发送到流中。在 DirectShow SDK 中有一个名为 PushSource 的示例过滤器,里面有一个 PushSourceDesktop。编译它并作为源过滤器插入到图表中。
You need a filter which captures screen and sends the video down the stream. In DirectShow SDK there is a sample filter called PushSource and inside there is PushSourceDesktop. Compile it and insert into your graph as a source filter.
好的,
OK,