directX视频播放------手动连接

简介: <p><br></p><p><img src="http://img.blog.csdn.net/20141028095016390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFvMDUxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center"



IGraphBuilder *pigb  = NULL;
IMediaControl *pimc  = NULL;
IMediaEventEx *pimex = NULL;
IVideoWindow  *pivw  = NULL;
IMediaSeeking  *pims  = NULL;
ICaptureGraphBuilder2 * g_pCaptureBuilder = NULL;

IBaseFilter *pF = 0; 
void CTestFilterDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	CoInitialize(NULL);
    HRESULT	hr = CoCreateInstance(CLSID_FilterGraph,
		NULL,
		CLSCTX_INPROC_SERVER,
		IID_IGraphBuilder,
		(void **)&pigb);
    hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
                           IID_ICaptureGraphBuilder2, (void **) &g_pCaptureBuilder);
	   pigb->QueryInterface(IID_IMediaControl, (void **)&pimc);
	   pigb->QueryInterface(IID_IMediaEventEx, (void **)&pimex);
       pigb->QueryInterface(IID_IMediaSeeking, (void **)&pims);
	   pigb->QueryInterface(IID_IVideoWindow, (void **)&pivw);
	  hr = g_pCaptureBuilder->SetFiltergraph(pigb);
 // avi-source ////////////////////////////////////////////////////////////
	  const GUID CLSID_AviSource={0xCEA8DEFF,0x0AF7,0x4DB9,{0x9A,0x38,0xFB,0x3C,0x3A,0xEF,0xC0,0xDE}};
	  hr = CoCreateInstance(CLSID_AviSource, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pF)); 
	  hr = pigb->AddFilter(pF,L"SOURCE FILTER");
	  IFileSourceFilter *pSF = NULL;
	  hr = pF->QueryInterface(IID_IFileSourceFilter, (void**)&pSF);
	  if (SUCCEEDED(hr))
	  {
		  pSF->Load(L"F:\\FFOutput\\ff640480.avi", NULL);
		  pSF->Release();
	  }
	  IPin *pOut_Source = 0;
	   IPin      *pPin;
	  if(SUCCEEDED(hr))
	  {
		  IEnumPins *pEnum;
	//	  IPin      *pPin;
		  hr = pF->EnumPins(&pEnum);
		  if (SUCCEEDED(hr))
		  {
			  /*
			  while(pEnum->Next(1, &pPin, 0) == S_OK)
			  {
				  PIN_DIRECTION pinDirThis;
				  pPin->QueryDirection(&pinDirThis);
				  if (PINDIR_OUTPUT == pinDirThis)
				  {
					  break;
				  }
			  }*/
			  hr = g_pCaptureBuilder->FindPin(pF,PINDIR_OUTPUT,NULL,NULL,FALSE,0,&pPin);
			  pEnum->Release();
		  }
			
	  }
     pOut_Source= pPin;
      if (hr)
      {
		  MessageBox("ERR RENDERAVI!");
      }
// ffshow-decoder  /////////////////////////////////////////////////
	  IBaseFilter *paviDecoder;//---871E-AB91661A4EF7
	  const GUID CLSID_Decoder={0x04FE9017,0xF873,0x410E,{0x87,0x1e,0xaB,0x91,0x66,0x1a,0x4e,0xf7}};
	  hr = CoCreateInstance(CLSID_Decoder,NULL,CLSCTX_ALL,IID_IBaseFilter,(void **)&paviDecoder);
      hr = pigb->AddFilter(paviDecoder,L"ffdshow Video Decoder ");

	  IPin *pIn_aviDecoder = 0;
	  IPin *pOut_aviDecoder = 0;
	  hr = g_pCaptureBuilder->FindPin(paviDecoder,PINDIR_INPUT,NULL,NULL,FALSE,0,&pIn_aviDecoder);
	  hr = g_pCaptureBuilder->FindPin(paviDecoder,PINDIR_OUTPUT,NULL,NULL,FALSE,0,&pOut_aviDecoder);
// Render filter ////////////////////////////////////////
	  IBaseFilter *pRenderFilter;
      hr = CoCreateInstance(CLSID_VideoRenderer,NULL,CLSCTX_ALL,IID_IBaseFilter,(void **)&pRenderFilter);
	  hr = pigb->AddFilter(pRenderFilter,L"ffdshow Video Render ");
	  IPin *pIn_Render = 0;
	  hr = g_pCaptureBuilder->FindPin(pRenderFilter,PINDIR_INPUT,NULL,NULL,FALSE,0,&pIn_Render);
///// 特效filter ///////////////////////////////////////////////
	  IBaseFilter *peffect;//---871E-AB91661A4EF7
	  const GUID CLSID_EFFECT={0x8b498501, 0x1218, 0x11cf,{ 0xad, 0xc4, 0x0, 0xa0, 0xd1, 0x0, 0x4, 0x1b}};
	  hr = CoCreateInstance(CLSID_EFFECT,NULL,CLSCTX_ALL,IID_IBaseFilter,(void **)&peffect);
      hr = pigb->AddFilter(peffect,L"Image effect ");

	  IPin *pIn_peffect = 0;
	  IPin *pOut_peffect = 0;
	  hr = g_pCaptureBuilder->FindPin(peffect,PINDIR_INPUT,NULL,NULL,FALSE,0,&pIn_peffect);
	  hr = g_pCaptureBuilder->FindPin(peffect,PINDIR_OUTPUT,NULL,NULL,FALSE,0,&pOut_peffect);
	  peffect->Release();
 /// Connect 连接 pin/////////////////////////
	  hr = pigb->Connect(pOut_Source, pIn_aviDecoder);
	  if(FAILED(hr))
	  {
	      MessageBox("err17");
	  }
	  hr = pigb->Connect(pOut_aviDecoder, pIn_peffect);
	  if(FAILED(hr))
	  {
		  MessageBox("err18");
	  }
	  hr = pigb->Connect(pOut_peffect, pIn_Render);
	 if(FAILED(hr))
	 {
		MessageBox("err19");
	 }
///////显示//////////////////////
	   HWND m_hwndScreen = m_Screen2.GetSafeHwnd();
	   
	   RECT rc;

	   hr = pivw->put_Owner((OAHWND)m_hwndScreen);
	   hr = pivw->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
	   m_Screen2.GetClientRect(&rc);
	   hr = pivw->SetWindowPosition(0, 0, (rc.right), (rc.bottom));
	   hr = pivw->put_Visible(OATRUE);//*/
	   hr = pimc->Run();  
}


相关文章
|
编解码 Windows
UE-windows包蓝图分辨率设置
windows包蓝图分辨率设置
|
2月前
|
内存技术
用VC 6.0写flash播放器——5、全屏播放
用VC 6.0写flash播放器——5、全屏播放
|
数据采集 开发工具 图形学
Windows平台实现Unity下窗体|摄像头|屏幕采集推送
随着Unity3D的应用范围越来越广,越来越多的行业开始基于Unity3D开发产品,如传统行业中虚拟仿真教育、航空工业、室内设计、城市规划、工业仿真等领域。
105 0
|
数据采集 物联网 Linux
Unity3D下实现Linux平台RTMP推流(以采集Unity窗体和声音为例)
随着物联网等行业的崛起,越来越多的传统行业如虚拟仿真、航天工业、工业仿真、城市规划等,对Linux下的生态构建,有了更大的期望,Linux平台下,可选的直播推拉流解决方案相对Windows和移动端,非常少,基于Unity的Linux推送方案,更是几无参考。本文以Unity3d环境下Linux平台推送Unity窗体和Unity采集的音频,然后编码推送到RTMP服务器为例,大概说下实现过程。
191 0
|
编译器 开发工具 C语言
QT应用编程:基于VLC开发音视频播放器(句柄方式)
QT应用编程:基于VLC开发音视频播放器(句柄方式)
448 0
QT应用编程:基于VLC开发音视频播放器(句柄方式)
|
编译器 开发工具 C语言
QT应用编程:基于VLC开发音视频播放器(回调方式)
QT应用编程:基于VLC开发音视频播放器(回调方式)
594 0
QT应用编程:基于VLC开发音视频播放器(回调方式)
|
编解码 C语言
|
编解码 安全 数据安全/隐私保护
阿里云移动端播放器高级功能---安全播放
基本介绍 如何保障视频内容的安全,不被盗链、非法下载和传播,阿里云视频点播已经有一套完善的机制保障视频的安全播放: 那么在播放器中支持哪一些安全播放的机制呢? 这里有料:视频安全解决方案。 Referer访问控制 基于 HTTP 协议支持的 Referer机制,通过 Referer跟踪来源,对来源进行识别和判断,用户可配置访问的 Referer 黑、白名单(二者互斥)来限制视频资源被访问的情况。
3969 0