private void loadVideo(String videoPath) { videoFilepath = videoPath; videoFileName.Text = getDisplayVideoName(); if (graph != null) { graph = null; } if (mediaControl != null) { // Stop media playback this.mediaControl.Stop(); mediaControl = null; } if (videoWindow != null) { videoWindow.put_Owner(IntPtr.Zero); videoWindow = null; } if (mediaSeeking != null) { mediaSeeking = null; } if (basicAudio != null) { basicAudio = null; } GC.Collect(); /* if (mediaPosition != null) { mediaPosition = null; }*/ graph = (IGraphBuilder)new FilterGraph(); mediaControl = (IMediaControl)graph; //mediaPosition = (IMediaPosition)graph; videoWindow = (IVideoWindow)graph; mediaSeeking = (IMediaSeeking)graph; basicAudio = (IBasicAudio)graph; AviSplitter spliter = new AviSplitter(); graph.AddFilter((IBaseFilter)spliter, null); graph.RenderFile(videoPath, null); graph.SetDefaultSyncSource(); /* * AMSeekingSeekingCapabilities cap = AMSeekingSeekingCapabilities.CanGetCurrentPos; if (mediaSeeking.CheckCapabilities(ref cap) > 0) { this.consoleErreur.AppendText("Impossible de recuperer la position de la frame"); } * */ videoWindow.put_Owner(videoPanel.Handle); videoWindow.put_MessageDrain(videoPanel.Handle); videoWindow.put_WindowStyle(WindowStyle.Child); videoWindow.put_WindowStyleEx(WindowStyleEx.ControlParent); videoWindow.put_Left(0); videoWindow.put_Top(0); videoWindow.put_Width(videoPanel.Width); videoWindow.put_Height(videoPanel.Height); //positionTrackbar.Enabled = true; speedTrackBar.Enabled = true; mediaSeeking.SetTimeFormat(TimeFormat.Frame); double rate; mediaSeeking.GetRate(out rate); rateText.Text = rate.ToString(); speedTrackBar.Value = (int)(speedTrackBar.Maximum * rate / 2); trackBar1.Value = trackBar1.Maximum / 2; this.basicAudio.put_Volume(-5000 + 5000 * trackBar1.Value / trackBar1.Maximum); //mediaPosition.put_Rate(0.5); running = false; frameChanged = false; }
/// <summary> build the capture graph for grabber. </summary> private void SetupGraph(string FileName) { int hr; // Get the graphbuilder object this.graphBuilder = new FilterGraph() as IGraphBuilder; this.mediaControl = this.graphBuilder as IMediaControl; this.mediaSeeking = this.graphBuilder as IMediaSeeking; this.mediaEvent = this.graphBuilder as IMediaEvent; try { // Get the SampleGrabber interface this.sampleGrabber = new SampleGrabber() as ISampleGrabber; this.sampleGrabberFilter = sampleGrabber as IBaseFilter; ConfigureSampleGrabber(sampleGrabber); // Add the frame grabber to the graph hr = graphBuilder.AddFilter(sampleGrabberFilter, "Ds.NET Sample Grabber"); DsError.ThrowExceptionForHR(hr); IBaseFilter aviSplitter = new AviSplitter() as IBaseFilter; // Add the aviSplitter to the graph hr = graphBuilder.AddFilter(aviSplitter, "Splitter"); DsError.ThrowExceptionForHR(hr); // Have the graph builder construct its appropriate graph automatically hr = this.graphBuilder.RenderFile(FileName, null); DsError.ThrowExceptionForHR(hr); #if DEBUG m_rot = new DsROTEntry(graphBuilder); #endif // Remove the video renderer filter IBaseFilter defaultVideoRenderer = null; graphBuilder.FindFilterByName("Video Renderer", out defaultVideoRenderer); graphBuilder.RemoveFilter(defaultVideoRenderer); // Disconnect anything that is connected // to the output of the sample grabber IPin iPinSampleGrabberOut = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Output, 0); IPin iPinVideoIn; hr = iPinSampleGrabberOut.ConnectedTo(out iPinVideoIn); if (hr == 0) { // Disconnect the sample grabber output from the attached filters hr = iPinVideoIn.Disconnect(); DsError.ThrowExceptionForHR(hr); hr = iPinSampleGrabberOut.Disconnect(); DsError.ThrowExceptionForHR(hr); } else { // Try other way round because automatic renderer could not build // graph including the sample grabber IPin iPinAVISplitterOut = DsFindPin.ByDirection(aviSplitter, PinDirection.Output, 0); IPin iPinAVISplitterIn; hr = iPinAVISplitterOut.ConnectedTo(out iPinAVISplitterIn); DsError.ThrowExceptionForHR(hr); hr = iPinAVISplitterOut.Disconnect(); DsError.ThrowExceptionForHR(hr); hr = iPinAVISplitterIn.Disconnect(); DsError.ThrowExceptionForHR(hr); // Connect the avi splitter output to sample grabber IPin iPinSampleGrabberIn = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Input, 0); hr = graphBuilder.Connect(iPinAVISplitterOut, iPinSampleGrabberIn); DsError.ThrowExceptionForHR(hr); } // Add the null renderer to the graph nullrenderer = new NullRenderer() as IBaseFilter; hr = graphBuilder.AddFilter(nullrenderer, "Null renderer"); DsError.ThrowExceptionForHR(hr); // Get the input pin of the null renderer IPin iPinNullRendererIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0); // Connect the sample grabber to the null renderer hr = graphBuilder.Connect(iPinSampleGrabberOut, iPinNullRendererIn); DsError.ThrowExceptionForHR(hr); // Read and cache the image sizes SaveSizeInfo(sampleGrabber); this.GetFrameStepInterface(); } finally { } }