public void RenderToWavDest( string outputFile, IBaseFilter audioCompressor, AMMediaType mediaType, IDESCombineCB audioCallback) { if (audioCompressor != null) { _dc.Add(audioCompressor); } int hr; if (_firstAudioGroup == null) { throw new SplicerException("No audio stream to render"); } if (outputFile == null) { throw new SplicerException("Output file name cannot be null"); } // Contains useful routines for creating the graph ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); _dc.Add(icgb); try { hr = icgb.SetFiltergraph(_graph); DESError.ThrowExceptionForHR(hr); IBaseFilter wavDestFilter = StandardFilters.RenderWavDest(_dc, _graph); IBaseFilter fileSink = StandardFilters.RenderFileDestination(_dc, _graph, outputFile); try { RenderGroups(icgb, audioCompressor, null, wavDestFilter, audioCallback, null); FilterGraphTools.ConnectFilters(_graph, wavDestFilter, fileSink, true); // if supplied, apply the media type to the filter if (mediaType != null) { FilterGraphTools.SetFilterFormat(mediaType, audioCompressor); } } finally { Marshal.ReleaseComObject(wavDestFilter); Marshal.ReleaseComObject(fileSink); } } finally { Marshal.ReleaseComObject(icgb); } }
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); } }
private void RenderToWavDest( string outputFile, IBaseFilter audioCompressor, AMMediaType mediaType, ICallbackParticipant[] audioParticipants) { if (audioCompressor != null) { Cleanup.Add(audioCompressor); } int hr; if (FirstAudioGroup == null) { throw new SplicerException(Resources.ErrorNoAudioStreamToRender); } if (outputFile == null) { throw new SplicerException(Resources.ErrorInvalidOutputFileName); } // Contains useful routines for creating the graph var graphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); Cleanup.Add(graphBuilder); try { hr = graphBuilder.SetFiltergraph(Graph); DESError.ThrowExceptionForHR(hr); IBaseFilter wavDestFilter = StandardFilters.RenderWavDestination(Cleanup, Graph); IBaseFilter fileSink = StandardFilters.RenderFileDestination(Cleanup, Graph, outputFile); try { RenderGroups(graphBuilder, audioCompressor, null, wavDestFilter, audioParticipants, null); FilterGraphTools.ConnectFilters(Graph, wavDestFilter, fileSink, true); // if supplied, apply the media type to the filter if (mediaType != null) { FilterGraphTools.SetFilterFormat(mediaType, audioCompressor); } DisableClock(); } finally { if (wavDestFilter != null) { Marshal.ReleaseComObject(wavDestFilter); } if (fileSink != null) { Marshal.ReleaseComObject(fileSink); } } } finally { Marshal.ReleaseComObject(graphBuilder); } }