• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 22KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 104
    下载次数
  • 2005-08-09 08:43
    上传日期
基于DirectShow编辑而成的视频流播放处理类,收集了许多常用的视频播放控制功能
szpvideo.rar
  • SzpVideo.h
    25.3KB
  • SzpVideo.cpp
    63.9KB
  • www.pudn.com.txt
    218B
内容介绍
// SzpVideo.cpp: implementation of the CSzpVideo class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" // for direct show #include <streams.h> #include <mtype.h> #include "SzpVideo.h" #include "../imagereadandwrite/visimage.h" #include "../imagereadandwrite/featureextraction.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // CSzpVideo: The class handle the DirectShow graph building ////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // Constructor : Init member variable and search for available devices /////////////////////////////////////////////////////////////////////// CSzpVideo::CSzpVideo() { CoInitialize(NULL); // Init COM m_pCaptureGraphBuilder2 = NULL; m_pGraphBuilder = NULL; m_pFilterGraph = NULL; m_pMediaControl = NULL; m_pVideoWindow = NULL; m_pMediaSeeking = NULL; m_pSrcFilter = NULL; m_pRenderFilter = NULL; //m_pBasicVideo = NULL; //shizp 2004.6.4 //m_pVideoFrameStep = NULL; //shizp 2004.6.4 m_TimeFormat = TIME_FORMAT_MEDIA_TIME; m_hRenderWnd = NULL; m_pCaptureSetting = NULL; m_fIsScaling = false; // no scaling m_fRegisterFilterGraph = true; // register for GraphEdt to view m_dwGraphRegister = 0; // the register no. of the graph m_wcMediaName[0] = '\0'; m_wcOutputFile[0] = '\0'; // enumerate all available video capture devices m_nNumOfCapDev = 0; HRESULT hr; CComPtr<ICreateDevEnum> pCreateDevEnum; CComPtr<IEnumMoniker> pEnumMoniker = NULL; hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void**)&pCreateDevEnum); if (FAILED(hr)) return; // no capture device enumerator hr = pCreateDevEnum-> CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumMoniker, 0); if (FAILED(hr) || !pEnumMoniker) return; // no capture device // Search all available devices and save in m_pCapMonikers[] ULONG cFetched; // Note that if the Next() call succeeds but there are no monikers, // it will return S_FALSE (which is not a failure). Therefore, we // check that the return code is S_OK instead of using SUCCEEDED() while (S_OK == pEnumMoniker->Next(1, m_pCapMonikers+m_nNumOfCapDev, &cFetched)) m_nNumOfCapDev ++; } /////////////////////////////////////////////////////////////////////// // Deconstructor : Release all resources /////////////////////////////////////////////////////////////////////// CSzpVideo::~CSzpVideo() { // Release the stored available capture device for (int i = 0; i < m_nNumOfCapDev; i++) SafeRelease(m_pCapMonikers[i]); ReleaseFilterGraph(); // destroy the filter graph CoUninitialize(); // release COM } /////////////////////////////////////////////////////////////////////// // SetRenderWindow: Set the window to display the video // Auguments: // hWnd: the display window handler // pImgRect: display the video in the rectangle in window // if NULL, display video in up-left conner (0, 0) at // original video size // return value: error code of set video window /////////////////////////////////////////////////////////////////////// // Filter graph notification to the specified window #define WM_GRAPHNOTIFY (WM_USER+20) HRESULT CSzpVideo::SetRenderWindow(HWND hWnd, RECT * pImgRect) { m_hRenderWnd = hWnd; // set the render window if (pImgRect == NULL) // displaye video in original size at up-left corner. m_fIsScaling = false, m_oVideoRect.left = m_oVideoRect.top = 0; else // Set the rect to display the video and mark the flag m_oVideoRect = *pImgRect, m_fIsScaling = true; //set video window shizp 2004.3.3 HRESULT hr = NULL; if (m_hRenderWnd&&m_pVideoWindow) { //shizp edit for maybe an audio only, if is audio only, hr = (m_pVideoWindow->put_MessageDrain((OAHWND)m_hRenderWnd)); if(SUCCEEDED(hr)){ JIF(m_pVideoWindow->put_Owner((OAHWND)m_hRenderWnd)); JIF(m_pVideoWindow->put_WindowStyle(WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS));// // Set the display position JIF(setVideoWindowSize()); m_pVideoWindow->put_Visible(OATRUE); //hr = m_pVideoWindow->SetWindowForeground(-1); } } // update the video window size return S_OK;// setVideoWindowSize(); } /////////////////////////////////////////////////////////////////////// // SetRenderWindow: Set the window to display the video // Auguments: // hWnd: the display window handler // x, y: display in original size and up-left coner at (x, y) // return value: error code of set video window /////////////////////////////////////////////////////////////////////// HRESULT CSzpVideo::SetRenderWindow(HWND hWnd, int x, int y) { m_hRenderWnd = hWnd; // set the render window m_fIsScaling = false; // no scaling m_oVideoRect.left = x, m_oVideoRect.top = y; //set video window shizp 2004.7.2 if (m_hRenderWnd&&m_pVideoWindow) { //shizp edit for maybe an audio only, if is audio only, HRESULT hr = (m_pVideoWindow->put_MessageDrain((OAHWND)m_hRenderWnd)); if(SUCCEEDED(hr)){ JIF(m_pVideoWindow->put_Owner((OAHWND)m_hRenderWnd)); JIF(m_pVideoWindow->put_WindowStyle(WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN));// // Set the display position JIF(setVideoWindowSize()); m_pVideoWindow->put_Visible(OATRUE); //hr = m_pVideoWindow->SetWindowForeground(-1); } } // update the video window size return S_OK;// setVideoWindowSize(); } /////////////////////////////////////////////////////////////////////// // ReleaseFilterGraph : Release the whole graph /////////////////////////////////////////////////////////////////////// void CSzpVideo::ReleaseFilterGraph() { // Destroy the whole filter graph stopGraph(); SafeRelease( m_pMediaControl ); SafeRelease( m_pMediaSeeking ); SafeRelease( m_pSrcFilter ); SafeRelease( m_pRenderFilter ); SafeRelease( m_pVideoWindow ); SafeRelease( m_pFilterGraph ); SafeRelease( m_pGraphBuilder ); SafeRelease( m_pCaptureGraphBuilder2 ); } /////////////////////////////////////////////////////////////////////// // RenderFile: Playback the given media file // Auguments: // vname: the name of the media file // Return value: Error code of building playback graph /////////////////////////////////////////////////////////////////////// HRESULT CSzpVideo::RenderFile(const TCHAR * vname) { // set the VideoSource to indicate we are play video file m_nVideoSource = VideoFilePlayback; // change the given file name to wide character in m_wcMediaName USES_CONVERSION; TCHAR tempVName[MAX_PATH]; _tcscpy(tempVName, vname); wcscpy(m_wcMediaName, T2W(tempVName)); HRESULT hr; // Create the essensial element of a video graph JIF(createFilterGraph()); // Create seeking control to navigate through the video file // May fail for live camera. (but no need to return even we fail) hr = m_pGraphBuilder->QueryInterface(IID_IMediaSeeking, (void**)&m_pMediaSeeking); if (SUCCEEDED(hr)) { /* hr = m_pMediaSeeking->SetTimeFormat(&TIME_FORMAT_FRAME); if (SUCCEEDED(hr)) m_TimeFormat = TIME_FORMAT_FRAME; */ } else
评论
  • jerryche 2005-09-15 16:15:03
    CPP
相关推荐
  • DirectShow 实务精选 + 源码
    视频叠加、媒体播放等。在介绍各种应用的同时,辅助以大量详尽的实例源代 码。这些实例,不仅具有很强的实用价值和指导意义,更让读者理论联系实践, 使学习DirectShow 技术变得轻松自如。 本书结构合理,内容丰富...
  • Directshow 视频播放
    Directshow 视频播放 VC++ 6.0 视频播放,暂停,停止,等等
  • VC++通过DirectShow播放视频
    VC++2015编译,使用DirectX90b中的DirectShow播放常见的AVI、WMA、MP4等格式的视频文件
  • 使用DirectShow播放视频
    使用DirectShow方法播放视频,简单的播放器,播放本地音视频
  • 基于DirectShow的MFC视频播放器
    自己写的MFC视频播放器,基于DirectShow技术,VS2013写的,需要配置DirectShow的环境才可运行,压缩包中有DirectShow的配置方法和配置文档,本播放器实现了播放,暂停,停止,帧播放,加速播放(最多20倍,可在源码...
  • 基于WPF和DirectShow视频播放程序
    程序的界面是WPF做的,本程序通过将WinForm的Panel嵌入到WPF界面中,实现了用DirectShow.net开发技术播放视频的功能。比较简单,基本就是一个框架,另外,运行的时候需要DirectShow.net的lib。其中WinForm控件嵌入...
  • DirectShow实现视频播放以及摄像头视频采集
    MFC+DirectShow实现视频播放器,同事还可以摄像头采集视频,并播放出来
  • windows mobile directshow 播放视频
    windows mobile上播放视频示例
  • DirectShow开发指南源码
    DirectShow开发指南源码,是很好的Windows 音视频编码的学习源代码!
  • 视频播放
    DirectShow开发的视频播放器,可播放多种格式视频。开发工具VC6.0,在运行程序之前要装好DirectShow