Using VMR9

In this page, usage of VMR9 (Video Mixing Renderer 9) is shown.

VMR9

The main characteristic of VMR9 is that it can do video mixing. For example, you can add caption over the video. You can also overlay image files over video too.

VMR9 also has a deinterlace function. This is very useful when writing a video capturing code.

Sample code

In this page, the way to build a graph using VMR9 is shown. Detail of each VMR9 function is shown later, and not shown in this page.

The following sample code shows how to use VMR9.


#include <stdio.h>

#include <dshow.h>

// change here
#define	FILENAME L"c:\\DXSDK\\Samples\\Media\\butterfly.mpg"

int
main()
{
 IGraphBuilder *pGraphBuilder;
 IMediaControl *pMediaControl;
 ICaptureGraphBuilder2 *pCaptureGraphBuilder2;

 // Initialize COM
 CoInitialize(NULL);

 // Create FilterGraph
 CoCreateInstance(CLSID_FilterGraph,
	NULL,
	CLSCTX_INPROC,
	IID_IGraphBuilder,
	(LPVOID *)&pGraphBuilder);

 // Get MediaControl Interface
 pGraphBuilder->QueryInterface(IID_IMediaControl,
	(LPVOID *)&pMediaControl);

 // Prepare VMR9 filter
 IBaseFilter *pVmr9 = NULL;
 CoCreateInstance(CLSID_VideoMixingRenderer9, 0, 
    CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pVmr9);

 // Add VMR9 filter to Graph
 pGraphBuilder->AddFilter(pVmr9, L"VMR9");

 // Prepare media file using SourceFilter
 IBaseFilter *pSource;
 pGraphBuilder->AddSourceFilter(FILENAME, L"Source", &pSource);

 // Create GraphBuilder, CaptureGraphBuilder2
 CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, 
   IID_ICaptureGraphBuilder2, 
   (LPVOID *)&pCaptureGraphBuilder2);

 // Set FilterGraph for CaptureGraphBuilder2
 pCaptureGraphBuilder2->SetFiltergraph(pGraphBuilder);

 // Build Graph
 pCaptureGraphBuilder2->RenderStream(0, 0, pSource, 0, pVmr9);

 // Start playing
 pMediaControl->Run();

 // This is to block while playing
 MessageBox(NULL,
	"Block Execution",
	"Block",
	MB_OK);

 // Release resource
 pMediaControl->Release();
 pCaptureGraphBuilder2->Release();
 pGraphBuilder->Release();

 // Finalize COM
 CoUninitialize();

 return 0;
}


  

Copyright (C) GeekPage.JP. All rights reserved.