DirectShow .Net 实现视频
DirectShow .Net 实现视频
、获取视频采集设备IBaseFilter接口对象的方法 //获取所有视频设备名称
public ArrayList GetVideoInputDevice()
{ return GetDeviceCollection(FilterCategory.VideoInputDevice);}
private ArrayList GetDeviceCollection(Guid DeviceType)
{
ArrayList returnString = new ArrayList();
foreach (DsDevice ds in DsDevice.GetDevicesOfCat(DeviceType))
{
returnString.Add(ds.Name);
}
return returnString;
} //通过获取到的视频设备名称设置采集设备的IBaseFilter对象
public bool SetVideoInputDevice(string VideoInputDeviceName)
{ //创建视频输入设备接口
theVideoDevice = CreateFilter(FilterCategory.VideoInputDevice, VideoInputDeviceName);
}
//通过过滤器类型和过滤器名称获取IBaseFilter接口
private IBaseFilter CreateFilter(Guid category, string friendlyname)
{
object source = null;
Guid iid = typeof(IBaseFilter).GUID;
foreach (DsDevice device in DsDevice.GetDevicesOfCat(category))
{
if (device.Name.CompareTo(friendlyname) == )
{
device.Mon.BindToObject(null, null, ref iid, out source);
break;
}
} return (IBaseFilter)source;
} 、初始化基本的接口对象 private void InitInterfaces()
{
int hr = ; // 获取IGraphBuilder接口对象
this.m_graphBuilder = (IGraphBuilder)new FilterGraph();
//获取ICaptureGraphBuilder2接口对象
this.m_captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
//获取m_graphBuilder 接口对象的IMediaControl对象
this.m_mediaControl = (IMediaControl)this.m_graphBuilder;
//获取m_graphBuilder 接口对象的IVideoWindow对象
this.m_videoWindow = (IVideoWindow)this.m_graphBuilder;
//获取m_graphBuilder 接口对象的IMediaEventEx对象
this.m_mediaEventEx = (IMediaEventEx)this.m_graphBuilder;
//设置ICaptureGraphBuilder2的IGraphBuilder接口对象为当前对象
hr = this.m_captureGraphBuilder.SetFiltergraph(this.m_graphBuilder);
DsError.ThrowExceptionForHR(hr);
//注册事件到应用程序的窗体上
hr = this.m_mediaEventEx.SetNotifyWindow(this.hwnPropertyPageOwner, WM_GRAPHNOTIFY, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
} 、开始视频预览
public void VideoPreview()
try
{ int hr = ;
hr = this.m_graphBuilder.AddFilter(theVideoDevice, "Video Capture");
DsError.ThrowExceptionForHR(hr); // 通过theVideoDevice(IBaseFilter)视频接口对象的Preview Pin预览
hr = this.m_captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theVideoDevice, null, null);
DsError.ThrowExceptionForHR(hr); //插入SampleGrabber
m_pinStill = DsFindPin.ByCategory(theVideoDevice, PinCategory.Still, ); if (m_pinStill == null)
{
m_pinStill = DsFindPin.ByCategory(theVideoDevice, PinCategory.Capture, );
} // 获取theVideoDevice的IAMVideoControl对象,对于具有Still Pin的对象可以获到,采集设备不具备Still Pin,那么该对象将为Null
m_VidControl = theVideoDevice as IAMVideoControl; // 设置采集视频参数
if (this.videoHeight + this.videoWidth + this.videoStride > )
{
SetConfigParms(m_pinStill, this.videoWidth, this.videoHeight, );
} //开始拍照功能所需的接口对象
// 获得SampleGrabber对象接口
sampGrabber = new SampleGrabber() as ISampleGrabber; // 配置sample grabber
baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber); // 将sample grabber添加到图形过滤器中
hr = m_graphBuilder.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr); //通过渲染将采集设备的相关输出Pin与sample grabber对象的输入Pin连接起来
//如果采集设备提供Still Pin,则通过Still Pin连接,否则直接使用Capture Pin连接
if (m_VidControl!=null)
{
hr = this.m_captureGraphBuilder.RenderStream(PinCategory.Still, MediaType.Video, theVideoDevice, null, baseGrabFlt);
DsError.ThrowExceptionForHR(hr); }
else
{
hr = this.m_captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, theVideoDevice, null, baseGrabFlt);
DsError.ThrowExceptionForHR(hr);
}
//设置抓取图片相关参数
SaveSizeInfo(sampGrabber);
//拍照功能所需的接口对象添加结束 // 开始将视频窗口绑定到主窗体上
hr = this.m_videoWindow.put_Owner(this.hwnVideoWindowOwner);
DsError.ThrowExceptionForHR(hr); hr = this.m_videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr); if (this.m_videoWindow != null)
{
this.m_videoWindow.SetWindowPosition(, , this.videoWidth, this.videoHeight);
} hr = this.m_videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr); // 开始预览采集设备采集到的视频
hr = this.m_mediaControl.Run(); DsError.ThrowExceptionForHR(hr);
m_IsPreview = true;
}
catch
{
m_IsPreview = false;
throw new Exception("VideoPreview函数出现异常,视频预览失败!"); }
}
DirectShow .Net 实现视频的更多相关文章
- DirectShow 获取音视频输入设备列表
开发环境:Win10 + VS2015 本文介绍一个 "获取音频视频输入设备列表" 的示例代码. 效果图 代码下载 代码下载(VC2015):Github - DShow_simp ...
- DirectShow建立一个视频捕捉程序
DirectShow 提供了用应用程序从适当的硬件中捕捉和预览音/视频的能力.数据源包括:VCR,camera,TV tuner,microphone,或其他的数据源.一个应用程序可以立刻显示捕捉的数 ...
- 摘录DirectShow数据,视频采集
DirectShow在,数据流(Data Flow)它们是依次流过每Filter的.管理其数据具有其自己的方法,并且并没有向用户提供一个统一的接口,供用户操作数据流.这里以提取视频採集在的每帧为位图数 ...
- 基于DirectShow的MPEG-4视频传输系统的研究与实现
1 引言 近年来,随着国民经济的发展,社会各个部门对于视频监视系统的需求越来越多.但目前的很多监视系统都跟具体的硬件相关,必须要具体的采集卡的支持才能实现.所以有必要开发一种具有通用性的视频监 ...
- Directshow 判断音视频设备是否被占用<转>
直接上代码吧: 代码是参考网上大神分享的,在原基础上做了些修改(只检测视频设备): int DeviceIsBusy(char *videoName) { //输入设备的音视频名称 HRESULT h ...
- Directshow 采集音视频数据H264+AAC+rtmp效果还不错
从usb摄像头或者采集卡中采集效果还是不错的.
- 转:最简单的基于 DirectShow 的视频播放器
50行代码实现的一个最简单的基于 DirectShow 的视频播放器 本文介绍一个最简单的基于 DirectShow 的视频播放器.该播放器对于初学者来说是十分有用的,它包含了使用 DirectSho ...
- 最简单的基于DirectShow的示例:视频播放器
===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...
- 采集音频和摄像头视频并实时H264编码及AAC编码[转]
0. 前言 我在前两篇文章中写了DirectShow捕获音视频然后生成avi,再进行264编码的方法.那种方法有一些局限性,不适合实时性质的应用,如:视频会议.视频聊天.视频监控等.本文所使用的技术, ...
随机推荐
- GEF: 图形拖拽处理
重写EditPart#getDragTracker 即可替换拖拽事件.
- Backbone源码解析(三):Collection模块
Collection模块式是对分散在项目中model的收集,他可以存储所有的model,构成一个集合,并且通过自身的方法统一操作model.Collection模块包装着若干对象,对象本身不具有一些方 ...
- Linux 网络编程(epoll)
服务器端代码 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/soc ...
- s3c2440笔记1(启动)
s3c2440启动方式 1. 从nand flash 启动 1.1 上电后将nand flash中的前4KB数据复制到“Stepping Stone”: 1.2 CPU 执行“Stepping Sto ...
- 自己实现一个Native方法的调用
JNI 开始本篇的内容之前,首先要讲一下JNI.Java很好,使用的人很多.应用极广,但是Java不是完美的.Java的不足体现在运行速度要比传统的C++慢上许多之外,还有Java无法直接访问到操作系 ...
- WPF,Silverlight与XAML读书笔记第四十八 - Silverlight网络与通讯
说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 这一部分我们重点讨论下Silverlight ...
- dijit样式定制之TextBox(一)
参考资料:http://dojotoolkit.org/reference-guide/1.9/dijit/themes.html http://archive.dojotoolkit.org/nig ...
- Alpha阶段冲刺项目总结(补充)
Alpha阶段冲刺阶段总结(补充) 此篇博客为"作业七:Alpha版本冲刺阶段" 与 "作业八:Alpha阶段项目总结" 的总结版. 一.项目预期计划vs实际进 ...
- 如何在IIS7/7.5上配置IISADMPWD
问题 很多IIS用户还记得在早期的IIS版本上有一个web应用, IISADMPWD. 该应用是与IIS5 和IIS6一起发布的. 主要用于为域用户提供修改密码的功能, 同时也可以修改本机用户的密码. ...
- 每天一个linux命令(26):用SecureCRT来上传和下载文件
用SSH管理linux服务器时经常需要远程与本地之间交互文件.而直接用SecureCRT自带的上传下载功能无疑是最方便的,SecureCRT下的文件传输协议有ASCII.Xmodem.Zmodem. ...