public static IBaseFilter RenderAsfWriterWithProfile(DisposalCleanup dc, IGraphBuilder graph, string profileData, string outputFile) { int hr = 0; IBaseFilter asfWriterFilter = (IBaseFilter) new WMAsfWriter(); dc.Add(asfWriterFilter); hr = graph.AddFilter(asfWriterFilter, "ASF Writer"); DsError.ThrowExceptionForHR(hr); // Create an appropriate IWMProfile from the data IWMProfileManager profileManager = ProfileManager.CreateInstance(); dc.Add(profileManager); IntPtr wmProfile = profileManager.LoadProfileByData(profileData); dc.Add(wmProfile); // Set the profile on the writer IConfigAsfWriter2 configWriter = (IConfigAsfWriter2)asfWriterFilter; configWriter.ConfigureFilterUsingProfile(wmProfile); hr = ((IFileSinkFilter)asfWriterFilter).SetFileName(outputFile, null); DsError.ThrowExceptionForHR(hr); return(asfWriterFilter); }
private void Configure() { int hr; m_FilterGraph = (IFilterGraph2) new FilterGraph(); m_asfw = (IConfigAsfWriter2) new WMAsfWriter(); hr = m_FilterGraph.AddFilter((IBaseFilter)m_asfw, "asdf"); DsError.ThrowExceptionForHR(hr); }
/// <summary>Do the conversion from DVR-MS to WAV.</summary> /// <returns>Null; ignored.</returns> protected override object DoWork() { // Get the filter graph object filterGraph = ClassId.CoCreateInstance(ClassId.FilterGraph); DisposalCleanup.Add(filterGraph); IGraphBuilder graph = (IGraphBuilder)filterGraph; // Add the ASF writer and set the output name IBaseFilter asfWriterFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WMAsfWriter); DisposalCleanup.Add(asfWriterFilter); graph.AddFilter(asfWriterFilter, null); IFileSinkFilter sinkFilter = (IFileSinkFilter)asfWriterFilter; sinkFilter.SetFileName(OutputFilePath, null); // Set the profile to be used for conversion if (_profilePath != null && _profilePath.Trim().Length > 0) { // Load the profile XML contents string profileData; using (StreamReader reader = new StreamReader(File.OpenRead(_profilePath))) { profileData = reader.ReadToEnd(); } // Create an appropriate IWMProfile from the data IWMProfileManager profileManager = ProfileManager.CreateInstance(); DisposalCleanup.Add(profileManager); IntPtr wmProfile = profileManager.LoadProfileByData(profileData); DisposalCleanup.Add(wmProfile); // Set the profile on the writer IConfigAsfWriter2 configWriter = (IConfigAsfWriter2)asfWriterFilter; configWriter.ConfigureFilterUsingProfile(wmProfile); } // Add the source filter; should connect automatically through the appropriate transform filters graph.RenderFile(InputFilePath, null); // Run the graph to completion RunGraph(graph, asfWriterFilter); return(null); }