Generating a Table of Contents Automatically
This topic demonstrates how to use Table of Contents Generator (TOC Generator) component to automatically generate a table of contents for a video file.
TOC Generator is a DirectX Media Object (DMO). To use the TOC Generator DMO, build a DirectX filter graph that has a video file as its source. Insert the TOC Generator DMO into the filter graph, and run the graph. You can then obtain the automatically generated table of contents from the TOC Generator DMO.
The following procedure gives the steps in more detail.
Call CoCreateInstance to create a Filter Graph object (CLSID_FilterGraph) and obtain an IGraphBuilder interface.
Call CoCreateInstance to create a DMO Wrapper Filter object (CLSID_DMOWrapperFilter) and obtain an IDMOWrapperFilter interface.
Pass CLSID_CTocGeneratorDmo to the Init method of your DMO wrapper filter. This creates a TOC Generator DMO and wraps it in your DMO wrapper filter.
Call the AddFilter method of your IGraphBuilder interface to add the wrapped TOC Generator DMO to the filter graph.
Note
IGraphBuilder inherits from IFilterGraph.
Call the AddSourceFilter method of your IGraphBuilder interface to create a souce filter and add it to the graph.
Enumerate pins on the DMO wrapper filter and the source filter. This involves obtaining IEnumPins interfaces and IPin interfaces.
Connect the source filter and the wrapper filter by calling the Connect method of your IGraphBuilder interface.
Complete the graph by calling the Render method of your IGraphBuilder interface.
Run the graph (IMediaControl::Run), and wait for it to complete (IMediaEvent::WaitForCompletion).
Obtain an IPropertyStore interface on your DMO filter wrapper, and get the value of the MFPKEY_TOCGENERATOR_TOCREADY property. Repeat if necessary until the table of contents is ready.
Use your IPropertyStore interface to get the value of the MFPKEY_TOCGENERATOR_TOCOBJECT property. This property is an IToc interface that represents the automatically generated table of contents.
The following code demonstrates the procedure for generating a table of contents automatically. The code uses three helper functions (BuildGraph, RunGraphAndWait, and GetToc) that are shown on other pages of this documentation.
#include <dshow.h>
#include <dmodshow.h>
#include <wmcodecdsp.h>
#include <dmoreg.h>
#include <propsys.h>
#include <propidl.h>
#include <initguid.h>
HRESULT GetToc(IDMOWrapperFilter* pWrap, IToc** ppToc);
HRESULT RunGraphAndWait(IGraphBuilder* pGraph);
HRESULT BuildGraph(IGraphBuilder* pGraph, IDMOWrapperFilter* pWrap);
WCHAR g_sourceFile[] = L"c:\\experiment\\Seattle.wmv";
void main()
{
HRESULT hr = E_FAIL;
hr = CoInitialize(NULL);
if(SUCCEEDED(hr))
{
IGraphBuilder* pBuilder = NULL;
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (VOID**)&pBuilder);
if(SUCCEEDED(hr))
{
IDMOWrapperFilter* pWrap = NULL;
hr = CoCreateInstance(CLSID_DMOWrapperFilter, NULL, CLSCTX_INPROC,
IID_IDMOWrapperFilter, (VOID**)&pWrap);
if(SUCCEEDED(hr))
{
hr = pWrap->Init(CLSID_CTocGeneratorDmo, DMOCATEGORY_VIDEO_EFFECT);
if(SUCCEEDED(hr))
{
hr = BuildGraph(pBuilder, pWrap);
if(SUCCEEDED(hr))
{
hr = RunGraphAndWait(pBuilder);
if(SUCCEEDED(hr))
{
IToc* pToc = NULL;
hr = GetToc(pWrap, &pToc);
if(SUCCEEDED(hr))
{
// Inspect the table of contents by calling IToc methods.
pToc->Release();
pToc = NULL;
}
}
}
}
pWrap->Release();
pWrap = NULL;
}
pBuilder->Release();
pBuilder = NULL;
}
CoUninitialize();
}
}
Related topics