Search code examples
c#directshowdirectshow.net

How to release the Video File of WM ASF Writer


I use this code to create, and add an asf Writer to my graph

IFileSinkFilter pTmpSink = null;
IBaseFilter asfWriter = null;
int hr = capGraph.SetOutputFileName( MediaSubType.Asf, szOutputFileName,
 out asfWriter, out pTmpSink);

i want to stop saving the video capturing, release the video file, and then rerun the graph so that preview continue.

m_mediaCtrl.Stop();
Marshal.ReleaseComObject(asfWriter);
m_mediaCtrl.Run();

the problem is that when i Release asfWriter, the file didn't receive the video capturing, and it's size is always 5.08KB. if i didn't release the asfWriter the file receives the video stream (also not running the graph again)

i appreciate any help, thanks.


Solution

  • the solution is to disconnect the asfWriter from the graph and then remove it. in my case it's connected the the pin 0 of a SmartTee. hope this helps someone else.

    m_mediaCtrl.Stop();
    if(asfWriter != null)
    {
          IPin pin = DsFindPin.ByDirection(iSmartTee, PinDirection.Output, 0);
          hr = m_FilterGraph.Disconnect(pin);
          hr = m_FilterGraph.RemoveFilter(asfWriter); 
    }
    m_mediaCtrl.Run();