protected AbstractRenderer(ITimeline timeline) { if (timeline == null) { throw new ArgumentNullException(TimelineParameterName); } _timeline = timeline; int hr = 0; // create the render engine _renderEngine = (IRenderEngine) new RenderEngine(); _cleanup.Add(_renderEngine); // tell the render engine about the timeline it should use hr = _renderEngine.SetTimelineObject(_timeline.DesTimeline); DESError.ThrowExceptionForHR(hr); // connect up the front end hr = _renderEngine.ConnectFrontEnd(); DESError.ThrowExceptionForHR(hr); // Get the filtergraph - used all over the place hr = _renderEngine.GetFilterGraph(out _graph); _cleanup.Add(Graph); DESError.ThrowExceptionForHR(hr); // find the first (and usually last) audio and video group, we use these // when rendering to track progress _firstAudioGroup = _timeline.FindFirstGroupOfType(GroupType.Audio); _firstVideoGroup = _timeline.FindFirstGroupOfType(GroupType.Video); }
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); }
public static IBaseFilter RenderFileDestination(DisposalCleanup dc, IGraphBuilder graph, string outputFile) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graph == null) { throw new ArgumentNullException("graph"); } if (string.IsNullOrEmpty(outputFile)) { throw new ArgumentNullException("outputFile"); } int hr = 0; var fileFilter = (IBaseFilter) new FileWriter(); hr = ((IFileSinkFilter)fileFilter).SetFileName(outputFile, null); DsError.ThrowExceptionForHR(hr); hr = graph.AddFilter(fileFilter, Resources.DefaultFileDestinationName); DsError.ThrowExceptionForHR(hr); dc.Add(fileFilter); return(fileFilter); }
public static IBaseFilter RenderAsfWriterWithProfile(DisposalCleanup dc, IGraphBuilder graph, string profileData, string outputFile) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graph == null) { throw new ArgumentNullException("graph"); } if (string.IsNullOrEmpty(profileData)) { throw new ArgumentNullException("profileData"); } if (string.IsNullOrEmpty(outputFile)) { throw new ArgumentNullException("outputFile"); } int hr = 0; var asfWriterFilter = (IBaseFilter) new WMAsfWriter(); dc.Add(asfWriterFilter); hr = graph.AddFilter(asfWriterFilter, Resources.DefaultAsfWriterName); 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 var configWriter = (IConfigAsfWriter2)asfWriterFilter; configWriter.ConfigureFilterUsingProfile(wmProfile); hr = ((IFileSinkFilter)asfWriterFilter).SetFileName(outputFile, null); DsError.ThrowExceptionForHR(hr); return(asfWriterFilter); }
public static IBaseFilter RenderWavDest(DisposalCleanup dc, IGraphBuilder graph) { IBaseFilter wavDest = FilterGraphTools.AddFilterFromClsid(graph, WavDestFilterId, "Wav DEST"); dc.Add(wavDest); return(wavDest); }
public static IBaseFilter RenderNull(DisposalCleanup dc, IGraphBuilder graph) { IBaseFilter filter = (IBaseFilter) new NullRenderer(); dc.Add(filter); graph.AddFilter(filter, "Null Renderer"); return(filter); }
/// <summary>Saves a graph to a GRF file.</summary> /// <param name="graph">The graph to be saved.</param> /// <param name="path">Path to the target GRF file.</param> private static void SaveGraphToFile(IGraphBuilder graph, string path) { using (DisposalCleanup dc = new DisposalCleanup()) { // Get the graph's persist stream interface IPersistStream ps = (IPersistStream)graph; // Create the file to which the graph should be stored IStorage graphStorage = StgCreateDocfile(path, (int)(STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE), 0); dc.Add(graphStorage); // Create the movie graph stream IStream stream = graphStorage.CreateStream("ActiveMovieGraph", (int)(STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE), 0, 0); dc.Add(stream); // Save out the graph and commit it ps.Save(stream, true); graphStorage.Commit(0); } }
/// <summary>Connects together to graph filters.</summary> /// <param name="graph">The graph on which the filters exist.</param> /// <param name="source">The source filter.</param> /// <param name="outPinName">The name of the output pin on the source filter.</param> /// <param name="destination">The destination filter.</param> /// <param name="inPinName">The name of the input pin on the destination filter.</param> protected void Connect(IGraphBuilder graph, IBaseFilter source, string outPinName, IBaseFilter destination, string inPinName) { IPin outPin = source.FindPin(outPinName); DisposalCleanup.Add(outPin); IPin inPin = destination.FindPin(inPinName); DisposalCleanup.Add(inPin); graph.Connect(outPin, inPin); }
public static IBaseFilter RenderFileDestination(DisposalCleanup dc, IGraphBuilder graph, string outputFile) { int hr = 0; IBaseFilter fileFilter = (IBaseFilter) new FileWriter(); hr = ((IFileSinkFilter)fileFilter).SetFileName(outputFile, null); DsError.ThrowExceptionForHR(hr); hr = graph.AddFilter(fileFilter, "Output File"); DsError.ThrowExceptionForHR(hr); dc.Add(fileFilter); return(fileFilter); }
/// <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); }
/// <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 source filter for the dvr-ms file IBaseFilter DvrmsSourceFilter = graph.AddSourceFilter(InputFilePath, null); DisposalCleanup.Add(DvrmsSourceFilter); // Add the file writer to the graph IBaseFilter wavFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.FileWriter); DisposalCleanup.Add(wavFilter); graph.AddFilter(wavFilter, null); IFileSinkFilter sinkFilter = (IFileSinkFilter)wavFilter; sinkFilter.SetFileName(OutputFilePath, null); // Add the Wav Dest filter to the graph IBaseFilter wavDest = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WavDest); DisposalCleanup.Add(wavDest); graph.AddFilter(wavDest, null); // Add the decrypter node to the graph IBaseFilter decrypter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.DecryptTag); DisposalCleanup.Add(decrypter); graph.AddFilter(decrypter, null); // Connect the dvr-ms source to the decrypter, the decrypter to the wav dest, // and the wav dest to the file writer Connect(graph, DvrmsSourceFilter, "DVR Out - 1", decrypter, "In(Enc/Tag)"); Connect(graph, decrypter, "Out", wavDest, "In"); Connect(graph, wavDest, "Out", wavFilter, "in"); // Run the graph to convert the audio to wav RunGraph(graph); return(null); }
public static IBaseFilter RenderWavDestination(DisposalCleanup dc, IGraphBuilder graph) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graph == null) { throw new ArgumentNullException("graph"); } IBaseFilter wavDest = FilterGraphTools.AddFilterFromClsid(graph, WavDestinationFilterId, Resources.DefaultWavDestinationName); dc.Add(wavDest); return(wavDest); }
public static IBaseFilter RenderNull(DisposalCleanup dc, IGraphBuilder graph) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graph == null) { throw new ArgumentNullException("graph"); } var filter = (IBaseFilter) new NullRenderer(); dc.Add(filter); graph.AddFilter(filter, Resources.DefaultNullRendererName); return(filter); }
public static IBaseFilter CreateAudioCompressor(DisposalCleanup dc, IGraphBuilder graph, IPin outPin, AudioFormat settings) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graph == null) { throw new ArgumentNullException("graph"); } if (outPin == null) { throw new ArgumentNullException("outPin"); } if (settings == null) { throw new ArgumentNullException("settings"); } int hr = 0; using (AudioCompressor compressor = AudioCompressorFactory.Create(settings)) { IBaseFilter compressorFilter = compressor.Filter; dc.Add(compressorFilter); hr = graph.AddFilter(compressorFilter, settings.AudioCompressor); DsError.ThrowExceptionForHR(hr); FilterGraphTools.ConnectFilters(graph, outPin, compressorFilter, true); // set the media type on the output pin of the compressor if (compressor.MediaType != null) { FilterGraphTools.SetFilterFormat(compressor.MediaType, compressorFilter); } return(compressorFilter); } }
public static IBaseFilter RenderAviDestination(DisposalCleanup dc, ICaptureGraphBuilder2 graphBuilder, string outputFile) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graphBuilder == null) { throw new ArgumentNullException("graphBuilder"); } if (string.IsNullOrEmpty(outputFile)) { throw new ArgumentNullException("outputFile"); } int hr = 0; // Create the file writer IBaseFilter multiplexer; IFileSinkFilter filter = null; try { hr = graphBuilder.SetOutputFileName(MediaSubType.Avi, outputFile, out multiplexer, out filter); dc.Add(multiplexer); DESError.ThrowExceptionForHR(hr); } finally { if (filter != null) { Marshal.ReleaseComObject(filter); } } return(multiplexer); }
public static IBaseFilter RenderAviDest(DisposalCleanup dc, ICaptureGraphBuilder2 icgb, string outputFile) { int hr = 0; // Create the file writer IBaseFilter pMux; IFileSinkFilter pFilter = null; try { hr = icgb.SetOutputFileName(MediaSubType.Avi, outputFile, out pMux, out pFilter); dc.Add(pMux); DESError.ThrowExceptionForHR(hr); } finally { if (pFilter != null) { Marshal.ReleaseComObject(pFilter); } } return(pMux); }