Capturing to Multiple Files

 
Microsoft DirectShow 9.0

Capturing to Multiple Files

After you have captured some video to a file, you can switch to a new file by stopping the graph and setting the file name on the File Writer filter. Call the IFileSinkFilter::SetFileName method on the File Writer. You can get a pointer to the IFileSinkFilter interface when you build the graph, through the pSink parameter of the SetOutputFileName method. The following code shows how to do this:

IBaseFilter *pMux;
IFileSinkFilter *pSink
hr = pBuild->SetOutputFileName(&MEDIASUBTYPE_Avi, L"C:\\YourFileName.avi", 
    &pMux, &pSink);
if (SUCCEEDED(hr))
{
    hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, 
        pCap, NULL, pMux);

    if (SUCCEEDED(hr))
    {
        pControl->Run();
        /* Wait awhile, then stop the graph. */
        pControl->Stop();
        // Change the file name and run the graph again.
        pSink->SetFileName(L"YourFileName02.avi", 0);
        pControl->Run();
    }
    pMux->Release();
    pSink->Release();
}