Rediger

Del via


Previewing a Project

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

[This API is not supported and may be altered or unavailable in the future.]

To preview a project, first call CoCreateInstance to create an instance of the Basic Render Engine. The class identifier is CLSID_RenderEngine. Then call the IRenderEngine::SetTimelineObject method to specify the timeline that you are rendering.

The first time that you preview the timeline, perform the following calls in the order listed:

  1. Call IRenderEngine::SetRenderRange to specify which portion of the timeline to preview. (Optional)
  2. Call IRenderEngine::ConnectFrontEnd to build the front end of the graph.
  3. Call IRenderEngine::RenderOutputPins. This method connects each output pin to a video renderer or audio renderer, completing the graph.

The following code example shows these steps:

IRenderEngine *pRender = NULL; 
hr = CoCreateInstance(CLSID_RenderEngine, NULL, 
    CLSCTX_INPROC_SERVER, IID_IRenderEngine, (void**)&pRender);

hr = pRender->SetTimelineObject(pTL);
hr = pRender->ConnectFrontEnd();
hr = pRender->RenderOutputPins();

Now run the filter graph. First, call the IRenderEngine::GetFilterGraph method to retrieve a pointer to the Filter Graph Manager's IGraphBuilder interface. Then query the Filter Graph Manager for the IMediaControl interface and call IMediaControl::Run, as shown in the following code:

IGraphBuilder   *pGraph = NULL;
IMediaControl   *pControl = NULL;
hr = pRender->GetFilterGraph(&pGraph);
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pControl->Run();

Use the Filter Graph Manager's IMediaEventEx interface to wait for the preview to complete. You can also seek the graph using the Filter Graph Manager's IMediaSeeking interface, just as you would with a file playback graph.

To preview the project again, seek the graph back to time zero and call Run again. If you change the contents of the timeline, do the following:

  1. Call SetRenderRange. (Optional)
  2. Call ConnectFrontEnd.
  3. If the ConnectFrontEnd method returns S_WARN_OUTPUTRESET, call RenderOutputPins. (If ConnectFrontEnd returns S_OK, you can skip this step.)
  4. Seek the graph back to time zero.
  5. Run the graph.

The following example shows these steps:

hr = pRender->ConnectFrontEnd();
if (hr == S_WARN_OUTPUTRESET)
{
    hr = pRender->RenderOutputPins();
}
LONGLONG llStart = 0; 
hr = pSeek->SetPositions(&llStart, AM_SEEKING_AbsolutePositioning, 0, 0); 
hr = pControl->Run();

For a complete example that loads and previews a project file, see Loading and Previewing a Project.

Managing Video Editing Projects

Rendering a Project