1
我有一個應用程序,它使用DirectShow.Net播放視頻並記錄視頻。當我嘗試記錄剛剛用於DirectShow播放的文件名時,由於該文件仍處於使用狀態,因此它會失敗。有時它會工作,但需要5到60秒才能解鎖文件。在嘗試錄製之前,播放圖肯定已經被破壞。下面是創建和銷燬圖形的代碼。如果我停止並在播放後啓動我的應用程序,我可以記錄到相同的文件名,並且沒有文件鎖定問題。DirectShow .Net AddSourceFilter發佈文件
任何人都可以建議我如何才能正確地釋放源過濾器,使文件不被鎖定?
創建圖表
try
{
graphBuilder = (IGraphBuilder)new FilterGraph();
#if DEBUG
// "Connect to remote graph" in GraphEdit
rotEntry = new DsROTEntry(graphBuilder);
#endif
hr = graphBuilder.AddSourceFilter(filename, filename, out baseFilter);
DsError.ThrowExceptionForHR(hr);
vmr9 = (IBaseFilter)new VideoMixingRenderer9();
ConfigureVMR9InWindowlessMode();
hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
DsError.ThrowExceptionForHR(hr);
FilterGraphTools.ConnectFilters(graphBuilder, baseFilter, "Output", vmr9, "VMR Input0", true);
}
銷燬圖表
if (vmr9 != null)
{
Marshal.ReleaseComObject(vmr9);
vmr9 = null;
windowlessCtrl = null;
}
if (graphBuilder != null)
{
// Remove and release all filters
FilterGraphTools.RemoveAllFilters(graphBuilder);
Marshal.ReleaseComObject(graphBuilder);
graphBuilder = null;
baseFilter = null;
}
#if DEBUG
if (rotEntry != null)
{
rotEntry.Dispose();
rotEntry = null;
}
#endif