首页 vc++关于视频捕捉

vc++关于视频捕捉

举报
开通vip

vc++关于视频捕捉1关于视频捕捉(about video capture in dshow) 1视频捕捉graph的构建 一个能够捕捉音频或者视频的graph图都称之为捕捉graph图。捕捉graph图比一般的文件回放graph图要复杂许多,dshow提供了一个capture graph builder com组件使得捕捉graph图的生成更加简单。capture graph builder提供了一个icapturegraphbuilder2接口,这个接口提供了一些方法用来构建和控制捕捉graph。 首先创建一个capture g...

vc++关于视频捕捉
1关于视频捕捉(about video capture in dshow) 1视频捕捉graph的构建 一个能够捕捉音频或者视频的graph图都称之为捕捉graph图。捕捉graph图比一般的文件回放graph图要复杂许多,dshow提供了一个capture graph builder com组件使得捕捉graph图的生成更加简单。capture graph builder提供了一个icapturegraphbuilder2接口,这个接口提供了一些方法用来构建和控制捕捉graph。 首先创建一个capture graph builder对象和一个graph manger对象,然后用filter graph manager 作参数,调用icapturegraphbuilder2::setfiltergraph来初始化capture graph builder。看下面的代码把 hresult initcapturegraphbuilder( igraphbuilder **ppgraph, // receives the pointer. icapturegraphbuilder2 **ppbuild // receives the pointer. ) { if (!ppgraph || !ppbuild) { return e_pointer; } igraphbuilder *pgraph = null; icapturegraphbuilder2 *pbuild = null; // create the capture graph builder. hresult hr = cocreateinstance(clsid_capturegraphbuilder2, null, clsctx_inproc_server, iid_icapturegraphbuilder2, (void**)&pgraph); if (succeeded(hr)) { // create the filter graph manager. hr = cocreateinstance(clsid_filtergraph, 0, clsctx_inproc_server, iid_igraphbuilder, (void**)&pgraph); if (succeeded(hr)) { // initialize the capture graph builder. pbuild->setfiltergraph(pgraph); // return both interface pointers to the caller. *ppbuild = pbuild; *ppgraph = pgraph; // the caller must release both interfaces. return s_ok; } else { pbuild->release(); } } return hr; // failed } 2视频捕捉的设备 现在许多新的视频捕捉设备都采用的是wdm驱动方法,在wdm机制中,微软提供了一个独立于硬件设备的驱动,称为类驱动程序。驱动程序的供应商提供的驱动程序称为minidrivers。minidrivers提供了直接和硬件打交道的函数,在这些函数中调用了类驱动。 在directshow的filter图表中,任何一个wdm捕捉设备都是做为一个wdm video capture 过滤器(filter)出现。wdm video capture过滤器根据驱动程序的特征构建自己的filter 下面是陆其明的一篇有关于dshow和硬件的文章,可以拿来参考一下 //陆文章开始 大家知道,为了提高系统的稳定性,windows操作系统对硬件操作进行了隔离;应用程序一般不能直接访问硬件。directshow filter工作在用户模式(user mode,操作系统特权级别为ring 3),而硬件工作在内核模式(kernel mode,操作系统特权级别为ring 0),那么它们之间怎么协同工作呢? directshow解决的方法是,为这些硬件设计包装filter;这种filter能够工作在用户模式下,外观、控制方法跟普通filter一样,而包装filter内部完成与硬件驱动程序的交互。这样的设计,使得编写directshow应用程序的开发人员,从为支持硬件而需做出的特殊处理中解脱出来。directshow已经集成的包装filter,包括audio capture filter(qcap.dll)、vfw capture filter(qcap.dll,filter的class id为clsid_vfwcapture)、tv tuner filter(kstvtune.ax,filter的class id为clsid_ctvtunerfilter)、analog video crossbar filter(ksxbar.ax)、tv audio filter(filter的class id为clsid_tvaudiofilter)等;另外,directshow为采用wdm驱动程序的硬件设计了ksproxy filter(ksproxy.ax,)。我们来看一下结构图: 下面,我们分别来看一下几种常见的硬件。 vfw视频采集卡。这类硬件在市场上已经处于一种淘汰的趋势;新生产的视频采集卡一般采用wdm驱动模型。但是,directshow为了保持向后兼容,还是专门提供了一个包装filter支持这种硬件。和其他硬件的包装filter一样,这种包装filter的创建不是像普通filter一样使用cocreateinstance,而要通过系统枚举,然后bindtoobject。 音频采集卡(声卡)。声卡的采集功能也是通过包装filter来实现的;而且现在的声卡大部分都有混音的功能。这个filter一般有几个input pin,每个pin都代表一个输入,如line in、microphone、cd、midi等。值得注意的是,这些pin代表的是声卡上的物理输入端子,在filter graph中是永远不会连接到其他filter上的。声卡的输出功能,可以有两个filter供选择:directsound renderer filter和audio renderer (waveout) filter。注意,这两个filter不是上述意义上的包装filter,它们能够同硬件交互,是因为它们使用了api函数:前者使用了directsound api,后者使用了waveout api。这两个filter的区别,还在于后者输出音频的同时不支持混音。(顺便说明一下,video renderer filter能够访问显卡,也是因为使用了gdi、directdraw或direct3d api。)如果你的机器上有声卡的话,你可以通过graphedit,在audio capture sources目录下看到这个声卡的包装filter。 wdm驱动的硬件(包括视频捕捉卡、硬件解压卡等)。这类硬件都使用ksproxy.ax这个包装filter。ksproxy.ax实现了很多功能,所以有“瑞士军刀”的美誉;它还被称作为“变色龙filter”,因为该filter上定义了统一的接口,而接口的实现因具体的硬件驱动程序而异。在filter graph中,ksproxy filter显示的名字为硬件的friendly name(一般在驱动程序的.inf文件中定义)。我们可以通过graphedit,在wdm streaming开头的目录中找到本机系统中安装的wdm硬件。因为ksproxy.ax能够代表各种wdm的音视频设备,所以这个包装filter的工作 流程 快递问题件怎么处理流程河南自建厂房流程下载关于规范招聘需求审批流程制作流程表下载邮件下载流程设计 有点复杂。这个filter不会预先知道要代表哪种类型的设备,它必须首先访问驱动程序的属性集,然后动态配置filter上应该实现的接口。当ksproxy filter上的接口方法被应用程序或其他filter调用时,它会将调用方法以及参数传递给驱动程序,由驱动程序最终完成指定功能。除此以外,wdm硬件还支持内核流(kernel streaming),即内核模式下的数据传输,而无需经过到用户模式的转换。因为内核模式与用户模式之间的相互转换,需要花费很大的计算量。如果使用内核流,不仅可以避免大量的计算,还避免了内核数据与主机内存之间的拷贝过程。在这种情况下,用户模式的filter graph中,即使pin之间是连接的,也不会有实际的数据流动。典型的情况,如带有video port pin的视频捕捉卡,preview时显示的图像就是在内核模式下直接传送到显卡的显存的。所以,你也休想在vp pin后面截获数据流。 讲到这里,我想大家应该对directshow对硬件的支持问题有了一个总体的认识。对于应用程序开发人员来说,这方面的内容不用研究得太透,而只需作为背景知识了解一下就好了。其实,大量繁琐的工作directshow已经帮我们做好了。 //陆其明文章结束 direcshow中视频捕捉的filter pin的种类 捕捉filter一般都有两个或多个输出pin,他们输出的媒体类型都一样,比如预览pin和捕捉pin,因此根据媒体类型就不能很好的区别这些pin。此时就要根据pin的功能来区别每个pin了,每个pin都有一个guid,称为pin的种类。 如果想仔细的了解pin的种类,请看后面的相关内容working with pin categories。对于大多数的应用来说,icapturegraphbuilder2提供了一些函数可以自动确定pin的种类。 预览pin和捕捉pin 视频捕捉filter都提供了预览和捕捉的输出pin,预览pin用来将视频流在屏幕上显示,捕捉pin用来将视频流写入文件。 预览pin和输出pin有下面的区别: 1 为了保证捕捉pin对视频桢流量,预览pin必要的时候可以停止。 2 经过捕捉pin的视频桢都有时间戳,但是预览pin的视频流没有时间戳。 预览pin的视频流之所以没有时间戳的原因在于filter图表管理器在视频流里加一个很小的latency,如果捕捉时间被认为就是render时间的话,视频renderfilter就认为视频流有一个小小的延迟,如果此时render filter试图连续播放的时候,就会丢桢。去掉时间戳就保证了视频桢来了就可以播放,不用等待,也不丢桢。 预览pin的种类guid为pin_category_preview 捕捉pin的种类guid为pin_category_capture video port pin video port是一个介于视频设备(tv)和视频卡之间的硬件设备。同过video port,视频数据可以直接发送到图像卡上,通过硬件的覆盖,视频可以直接在屏幕显示出来。video port就是连接两个设备的。 使用video port的最大好处是,不用cpu的任何工作,视频流直接写入内存中。当然它也有下面的缺点drawbacks: 略 如果捕捉设备使用了video port,捕捉filter就用一个video port pin代替预览pin。 video port pin的种类guid为pin_category_videoport 一个捕捉filter至少有一个capture pin,另外,它可能有一个预览pin 和一个video port pin ,或者两者都没有,也许filter有很多的capture pin,和预览pin,每一个pin都代表一种媒体类型,因此一个filter可以有一个视频capture pin,视频预览pin,音频捕捉pin,音频预览pin。 upstream wdm filters 在捕捉filter之上,wdm设备可能需要额外的filters,下面就是这些filter tv tuner filter tv audio filter. analog video crossbar filter 尽管这些都是一些独立的filter,但是他们可能代表的是同一个硬件设备,每个filter都控制设备的不同函数,这些filter通过pin连接起来,但是在pin中没有数据流动。因此,这些pin 的连接和媒体类型无关。他们使用一个guid值来定义一个给定设备的minidriver,例如:tv tuner filter 和video capture filter都支持同一种medium。 在实际应用中,如果你使用icapturegraphbuilder2来创建你的capture graphs,这些filters就会自动被添加到你的graph中。更多的详细资料,可以参考wdm class driver filters 2选择一个视频捕捉设备(select capture device) 如何选择一个视频捕捉设备,可以采用系统设备枚举,详细资料参见using the system device enumerator 。enumerator可以根据filter的种类返回一个设备的monikers。moniker是一个com对象,可以参见imoniker的sdk。 对于捕捉设备,下面两种类是相关的。 clsid_audioinputdevicecategory 音频设备 clsid_videoinputdevicecategory 视频设备 下面的代码演示了如何枚举一个视频捕捉设备 icreatedevenum *pdevenum = null; ienummoniker *penum = null; // create the system device enumerator. hresult hr = cocreateinstance(clsid_systemdeviceenum, null, clsctx_inproc_server, iid_icreatedevenum, reinterpret_cast(&pdevenum)); if (succeeded(hr)) { //创建一个枚举器,枚举视频设备 hr = pdevenum->createclassenumerator( clsid_videoinputdevicecategory, &penum, 0); } ienummoniker接口penum返回一个imoniker接口的列表,代表一系列的moniker,你可以显示所有的设备,然后让用户选择一个。 采用imoniker::bindtostorage方法,返回一个ipropertybag接口指针。然后调用ipropertybag::read读取moniker的属性。下面看看都包含什么属性 1 friendlyname 是设备的名字 2 description 属性仅仅适用于dv和d-vhs/mpeg摄象机,如果这个属性可用,这个属性更详细的描述了设备的资料 3devicepath 这个属性是不可读的,但是每个设备都有一个独一无二的。你可以用这个属性来区别同一个设备的不同实例 下面的代码演示了如何显示遍历设备的名称 ,接上面的代码 hwnd hlist; // handle to the list box. imoniker *pmoniker = null; while (penum->next(1, &pmoniker, null) == s_ok) { ipropertybag *ppropbag; hr = pmoniker->bindtostorage(0, 0, iid_ipropertybag, (void**)(&ppropbag)); if (failed(hr)) { pmoniker->release(); continue; // skip this one, maybe the next one will work. } // find the description or friendly name. variant varname; variantinit(&varname); hr = ppropbag->read(l"description", &varname, 0); if (failed(hr)) { hr = ppropbag->read(l"friendlyname", &varname, 0); } if (succeeded(hr)) { // add it to the application's list box. uses_conversion; (long)sendmessage(hlist, lb_addstring, 0, (lparam)ole2t(varname.bstrval)); variantclear(&varname); } ppropbag->release(); pmoniker->release(); } 如果用户选中了一个设备调用imoniker::bindtoobject为设备生成filter,然后将filter加入到graph中。 ibasefilter *pcap = null; hr = pmoniker->bindtoobject(0, 0, iid_ibasefilter, (void**)&pcap); if (succeeded(hr)) { hr = m_pgraph->addfilter(pcap, l"capture filter"); } 3预览视频(previewing video) 为了创建可以预览视频的graph,可以调用下面的代码 icapturegraphbuilder2 *pbuild; // capture graph builder // initialize pbuild (not shown). ibasefilter *pcap; // video capture filter. /* initialize pcap and add it to the filter graph (not shown). */ hr = pbuild->renderstream(&pin_category_preview, &mediatype_video, pcap, null, null); 4如何捕捉视频流并保存到文件(capture video to file) 1 将视频流保存到avi文件 下面的图表显示了graph图 图2 avi mux filter接收从capture pin过来的视频流,然后将其打包成avi流。音频流也可以连接到avi mux filter上,这样mux filter就将视频流和视频流合成avi流。file writer将avi流写入到文件中。 可以像下面这样构建graph图 ibasefilter *pmux; hr = pbuild->setoutputfilename( &mediasubtype_avi, // specifies avi for the target file. l"c:\\example.avi", // file name. &pmux, // receives a pointer to the mux. null); // (optional) receives a pointer to the file sink. 第一个参数表明文件的类型,这里表明是avi,第二个参数是制定文件的名称。对于avi文件,setoutputfilename函数会创建一个avi mux filter 和一个 file writer filter ,并且将两个filter添加到graph图中,在这个函数中,通过file writer filter 请求ifilesinkfilter接口,然后调用ifilesinkfilter::setfilename方法,设置文件的名称。然后将两个filter连接起来。第三个参数返回一个指向 avi mux的指针,同时,它也通过第四个参数返回一个ifilesinkfilter参数,如果你不需要这个参数,你可以将这个参数设置成null。 然后,你应该调用下面的函数将capture filter 和avi mux连接起来。 hr = pbuild->renderstream( &pin_category_capture, // pin category. &mediatype_video, // media type. pcap, // capture filter. null, // intermediate filter (optional). pmux); // mux or file sink filter. // release the mux filter. pmux->release(); 第5个参数就是使用的上面函数返回的pmux指针。 当捕捉音频的时候,媒体类型要设置为mediatype_audio,如果你从两个不同的设备捕捉视频和音频,你最好将音频设置成主流,这样可以防止两个数据流间drift,因为avi mux filter为同步音频,会调整视频的播放速度的。为了设置master 流,调用iconfigavimux::setmasterstream方法,可以采用如下的代码: iconfigavimux *pconfigmux = null; hr = pmux->queryinterface(iid_iconfigavimux, (void**)&pconfigmux); if (succeeded(hr)) { pconfigmux->setmasterstream(1); pconfigmux->release(); } setmasterstream的参数指的是数据流的数目,这个是由调用renderstream的次序决定的。例如,如果你调用renderstream首先用于视频流,然后是音频,那么视频流就是0,音频流就是1。 添加编码filter ibasefilter *pencoder; /* create the encoder filter (not shown). */ // add it to the filter graph. pgraph->addfilter(pencoder, l"encoder); /* call setoutputfilename as shown previously. */ // render the stream. hr = pbuild->renderstream(&pin_category_capture, &mediatype_video, pcap, pencoder, pmux); pencoder->release(); 2将视频流保存成wmv格式的文件 为了将视频流保存成并编码成windows media video (wmv)格式的文件,将capture pin连到wm asf writer filter。 图3 构建graph图最简单的方法就是将在icapturegraphbuilder2::setoutputfilename方法中指定mediasubtype_asf的filter。如下 ibasefilter* pasfwriter = 0; hr = pbuild->setoutputfilename( &mediasubtype_asf, // create a windows media file. l"c:\\vidcap.wmv", // file name. &pasfwriter, // receives a pointer to the filter. null); // receives an ifilesinkfilter interface pointer (optional). 参数mediasubtype_asf 告诉graph builder,要使用wm asf writer作为文件接收器,于是,pbuild 就创建这个filter,将其添加到graph图中,然后调用ifilesinkfilter::setfilename来设置输出文件的名字。第三个参数用来返回一个asf writer指针,第四个参数用来返回文件的指针。 在将任何pin连接到wm asf writer之前,一定要对wm asf writer进行一下设置,你可以同过wm asf writer的iconfigasfwriter接口指针来进行设置。 iconfigasfwriter *pconfig = 0; hr = pasfwriter->queryinterface(iid_iconfigasfwriter, (void**)&pconfig); if (succeeded(hr)) { // configure the asf writer filter. pconfig->release(); } 然后调用icapturegraphbuilder2::renderstream将capture filter 和 asf writer连接起来。 hr = pbuild->renderstream( &pin_category_capture, // capture pin. &mediatype_video, // video. use mediatype_audio for audio. pcap, // pointer to the capture filter. 0, pasfwriter); // pointer to the sink filter (asf writer). 3保存成自定义的文件格式 如果你想将文件保存成自己的格式,你必须有自己的 file writer。看下面的代码 ibasefilter *pmux = 0; ifilesinkfilter *psink = 0; hr = pbuild->setoutputfilename( &clsid_mycustommuxfilter, //自己开发的filter l"c:\\vidcap.avi", &pmux, &psink); 4如何将视频流保存进多个文件 当你将视频流保存进一个文件后,如果你想开始保存第二个文件,这时,你应该首先将graph停止,然后通过ifilesinkfilter::setfilename改变 file writer 的文件名称。注意,ifilesinkfilter指针你可以在setoutputfilename时通过第四个参数返回的。 看看保存多个文件的代码吧 ibasefilter *pmux; ifilesinkfilter *psink hr = pbuild->setoutputfilename(&mediasubtype_avi, l"c:\\yourfilename.avi", &pmux, &psink); if (succeeded(hr)) { hr = pbuild->renderstream(&pin_category_capture, &mediatype_video, pcap, null, pmux); if (succeeded(hr)) { pcontrol->run(); /* wait awhile, then stop the graph. */ pcontrol->stop(); // change the file name and run the graph again. psink->setfilename(l"yourfilename02.avi", 0); pcontrol->run(); } pmux->release(); psink->release(); } 5组合视频的捕捉和预览 如果想组建一个既可以预览视频,又可以将视频保存成文件的graph,只需要两次调用icapturegraphbuilder2::renderstream即可。代码如下: // render the preview stream to the video renderer. hr = pbuild->renderstream(&pin_category_preview, &mediatype_video, pcap, null, null); // render the capture stream to the mux. hr = pbuild->renderstream(&pin_category_capture, &mediatype_video, pcap, null, pmux); 在上面的代码中,graph builder 其实隐藏了下面的细节。 1 如果capture filter既有preview pin 也有captrue pin,那么renderstream仅仅将两个pin和render filter接起来。如下图 图4 2如果caprture filter只有一个capture pin,那么capture graph builder就采用一个smart tee filter将视频流分流,graph图如下 图5 5如何控制capture graph(controlling capture graph) filter图表管理器可以通过imediacontrol接口控制整个graph的运行,停止和暂停。但是当一个graph有捕捉和预览两个数据流的时候,如果我们想单独的控制其中的一个数据流话,我们可以通过icapturegraphbuilder2::controlstream 。 下面讲一下如何来单独控制捕捉和预览数据流。 1 控制捕捉视频流 下面的代码,让捕捉数据流在graph开始运行1秒后开始,允运行4秒后结束。 // control the video capture stream. reference_time rtstart = 1000 0000, rtstop = 5000 0000; const word wstartcookie = 1, wstopcookie = 2; // arbitrary values. hr = pbuild->controlstream( &pin_category_capture, // pin category. &mediatype_video, // media type. pcap, // capture filter. &rtstart, &rtstop, // start and stop times. wstartcookie, wstopcookie // values for the start and stop events. ); pcontrol->run(); 第一个参数表明需要控制的数据流,一般采用的是pin种类guid, 第二个参数表明了媒体类型。 第三个参数指明了捕捉的filter。如果想要控制graph图中的所有捕捉filter,第二个和第三个参数都要设置成null。 第四和第五个参数表明了流开始和结束的时间,这是一个相对于graph开始的时间。 只有你调用imediacontrol::run以后,这个函数才有作用。如果graph正在运行,这个设置立即生效。 最后的两个参数用来设置当数据流停止,开始能够得到的事件通知。对于任何一个运用此方法的数据流,graph当流开始的时候,会发送ec_stream_control_started通知,在流结束的时候,要发送ec_stream_control_stopped通知。wstartcookie和wstopcookie是作为第二个参数的。 看看事件通知处理过程吧 while (hr = pevent->getevent(&evcode, ¶m1, ¶m2, 0), succeeded(hr)) { switch (evcode) { case ec_stream_control_started: // param2 == wstartcookie break; case ec_stream_control_stopped: // param2 == wstopcookie break; } pevent->freeeventparams(evcode, param1, param2); } controlstream还定义了一些特定的值来表示开始和停止的时间。 maxlonglong 从不开始,只有在graph停止的时候才停止 null, 立即开始和停止 例如,下面的代码立即停止捕捉流。 pbuild->controlstream(&pin_category_capture, &mediatype_video, pcap, 0, 0, // start and stop times. wstartcookie, wstopcookie); 2控制预览视频流 只要给controlstream第一个参数设置成pin_category_preview就可以控制预览pin,整个函数的使用和控制捕捉流一样,但是唯一区别是在这里你没法设置开始和结束时间了,因为预览的视频流没有时间戳,因此你必须使用null或者maxlonglong。例子 use null to start the preview stream: pbuild->controlstream(&pin_category_preview, &mediatype_video, pcap, null, // start now. 0, // (don't care.) wstartcookie, wstopcookie); use maxlonglong to stop the preview stream: pbuild->controlstream(&pin_category_preview, &mediatype_video, pcap, 0, // (don't care.) maxlonglong, // stop now. wstartcookie, wstopcookie); 3关于数据流的控制 pin的缺省的行为是传递sample,例如,如果你对pin_category_capture使用了controlstream,但是对于pin_category_preview没有使用该函数,因此,当你run graph的时候,preview 流会立即运行起来,而capture 流则要等到你设置的时间运行。 6如何配置一个视频捕捉设备 1显示vfw驱动的视频设备对话框 如果视频捕捉设备采用的仍然是vfw方式的驱动程序,则必须支持下面三个对话框,用来设置视频设备。 1 video source 用来选择视频输入设备并且调整设备的设置,比如亮度和对比度。 2video format 用来设置桢的大小和位 3video display 用来设置视频的显示参数 为了显示上面的三个对话框,你可以do the following 1 停止graph。 2向捕捉filter请求iamvfwcapturedialogs接口,如果成功,表明设备支持vfw驱动。 3调用iamvfwcapturedialogs::hasdialog来检查驱动程序是否支持你请求的对话框,如果支持,返回s_ok,否则返回s_false。注意不要用succeded宏。 4如果驱动支持该对话框,调用iamvfwcapturedialogs::showdialog显示该对话框。 5 重新运行graph 代码如下 pcontrol->stop(); // stop the graph. // query the capture filter for the iamvfwcapturedialogs interface. iamvfwcapturedialogs *pvfw = 0; hr = pcap->queryinterface(iid_iamvfwcapturedialogs, (void**)&pvfw); if (succeeded(hr)) { // check if the device supports this dialog box. if (s_ok == pvfw->hasdialog(vfwcapturedialog_source)) { // show the dialog box. hr = pvfw->showdialog(vfwcapturedialog_source, hwndparent); } } pcontrol->run(); 2 调整视频的质量 wdm驱动的设备支持一些属性可以用来调整视频的质量,比如亮度,对比度,饱和度,等要向调整视频的质量,do the following 1 从捕捉filter上请求iamvideoprocamp接口 2 对于你想调整的任何一个属性,调用iamvideoprocamp::getrange可以返回这个属性赋值的范围,缺省值,最小的增量值。iamvideoprocamp::get返回当前正在使用的值。videoprocampproperty枚举每个属性定义的标志。 3调用iamvideoprocamp::set来设置这个属性值。设置属性的时候,不用停止graph。 看看下面的代码是如何调整视频的质量的 hwnd htrackbar; // handle to the trackbar control. // initialize htrackbar (not shown). // query the capture filter for the iamvideoprocamp interface. iamvideoprocamp *pprocamp = 0; hr = pcap->queryinterface(iid_iamvideoprocamp, (void**)&pprocamp); if (failed(hr)) { // the device does not support iamvideoprocamp, so disable the control. enablewindow(htrackbar, false); } else { long min, max, step, default, flags, val; // get the range and default value. hr = m_pprocamp->getrange(videoprocamp_brightness, &min, &max, &step, &default, &flags); if (succeeded(hr)) { // get the current value. hr = m_pprocamp->get(videoprocamp_brightness, &val, &flags); } if (succeeded(hr)) { // set the trackbar range and position. sendmessage(htrackbar, tbm_setrange, true, makelong(min, max)); sendmessage(htrackbar, tbm_setpos, true, val); enablewindow(htrackbar, true); } else { // this property is not supported, so disable the control. enablewindow(htrackbar, false); } } 3调整视频输出格式 我们知道视频流可以有多种输出格式,一个设备可以支持16-bit rgb, 32-bit rgb, and yuyv,在每一种格式下,设备还可以调整视频桢的大小。 在wdm驱动设备上,iamstreamconfig 接口用来 报告 软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载 设备输出视频的格式的,vfw设备,可以采用对话框的方式来设置,参见前面的内容。 捕捉filter的捕捉pin和预览pin都支持iamstreamconfig 接口,可以通过icapturegraphbuilder2::findinterface获得iamstreamconfig接口。 iamstreamconfig *pconfig = null; hr = pbuild->findinterface( &pin_category_preview, // preview pin. 0, // any media type. pcap, // pointer to the capture filter. iid_iamstreamconfig, (void**)&pconfig); 设备还支持一系列的媒体类型,对于每一个媒体类型,设备都要支持一系列的属性,比如,桢的大小,图像如何缩放,桢率的范围等。 通过iamstreamconfig::getnumberofcapabilities获得设备所支持的媒体类型的数量。这个方法返回两个值,一个是媒体类型的数量,二是属性所需结构的大小。 这个结构的大小很重要,因为这个方法是用于视频和音频的,视频采用的是video_stream_config_caps结构,音频用audio_stream_config_caps结构。 通过函数iamstreamconfig::getstreamcaps来枚举媒体类型,要给这个函数传递一个序号作为参数,这个函数返回媒体类型和相应的属性结构体。看代码把 int icount = 0, isize = 0; hr = pconfig->getnumberofcapabilities(&icount, &isize); // check the size to make sure we pass in the correct structure. if (isize == sizeof(video_stream_config_caps) { // use the video capabilities structure. for (int iformat = 0; iformat < icount; iformat++) { video_stream_config_caps scc; am_media_type *pmtconfig; hr = pconfig->getstreamcaps(iformat, &pmtconfig, (byte*)&scc); if (succeeded(hr)) { /* examine the format, and possibly use it. */ // delete the media type when you are done. hr = pconfig->setformat(pmtconfig);//重新设置视频格式 deletemediatype(pmtconfig); } } 你可以调用iamstreamconfig::setformat设置新的媒体类型 hr = pconfig->setformat(pmtconfig); 如果pin没有连接,当连接的时候就试图用新的格式,如果pin已经在连接了,它就会用的新的媒体格式重新连接。在任何一种情况下,下游的filter都有可能拒绝新的媒体格式。 在setformat前你可以修改video_stream_config_caps结构来重新设置媒体类型。 例如: 如果getstreamcaps返回的是24-bit rgb format,桢的大小是320 x 240 像素,你可以通过检查媒体类型的major type,subtpye,和format等值 if ((pmtconfig.majortype == mediatype_video) && (pmtconfig.subtype == mediasubtype_rgb24) && (pmtconfig.formattype == format_videoinfo) && (pmtconfig.cbformat >= sizeof (videoinfoheader)) && (pmtconfig.pbformat != null)) { videoinfoheader *pvih = (videoinfoheader*)pmtconfig.pbformat; // pvih contains the detailed format information. long lwidth = pvih->bmiheader.biwidth; long lheight = pvih->bmiheader.biheight; } video_stream_config_caps结构里包含了该媒体类型的视频长度和宽度的最大值和最小值,还有递增的幅度值,就是每次调整视频size的幅度,例如,设备可能返回如下的值 ? minoutputsize: 160 x 120 ? maxoutputsize: 320 x 240 ? outputgranularityx: 8 pixels (horizontal step size) ? outputgranularityy: 8 pixels (vertical step size) 这样你可以在(160, 168, 176, ... 304, 312, 320
本文档为【vc++关于视频捕捉】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_508432
暂无简介~
格式:doc
大小:139KB
软件:Word
页数:36
分类:互联网
上传时间:2012-04-28
浏览量:29