示例#1
0
        private void CloseInterface()
        {
            //그래프와 콘트롤 해제
            if (pMediaControl != null)
            {
                pMediaControl.StopWhenReady();
            }
            if (pVideoWindow != null)
            {
                pVideoWindow.put_Visible(OABool.False);
                pVideoWindow.put_Owner(IntPtr.Zero);
            }

            Marshal.ReleaseComObject(pSampleGrabber);
            pSampleGrabber = null;
            Marshal.ReleaseComObject(pSampleGrabberFilter);
            pSampleGrabberFilter = null;
            Marshal.ReleaseComObject(pGraphBuilder);
            pGraphBuilder = null;
            Marshal.ReleaseComObject(pMediaControl);
            pMediaControl = null;
            Marshal.ReleaseComObject(pVideoWindow);
            pVideoWindow = null;
            Marshal.ReleaseComObject(pMediaPosition);
            pMediaPosition = null;
            //this.Close(); //close this program
        }
示例#2
0
    // Configure the video window
    private void ConfigureVideoWindow(DirectShowLib.IVideoWindow videoWindow, Control hWin)
    {
        int hr;

        // Set the output window
        hr = videoWindow.put_Owner(hWin.Handle);
        DsError.ThrowExceptionForHR(hr);

        // Set the window style
        hr = videoWindow.put_WindowStyle((WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings));
        DsError.ThrowExceptionForHR(hr);

        // Make the window visible
        hr = videoWindow.put_Visible(OABool.True);
        DsError.ThrowExceptionForHR(hr);

        // Make the window visible
        //hr = videoWindow.put_Visible( OABool.False );
        //DsError.ThrowExceptionForHR( hr );

        // Position the playing location
        Rectangle rc = hWin.ClientRectangle;

        hr = videoWindow.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
        DsError.ThrowExceptionForHR(hr);

        //Rectangle rc = hWin.ClientRectangle;
        //hr = videoWindow.SetWindowPosition( 0, 0, 0, 0 );
        //DsError.ThrowExceptionForHR( hr );
    }
示例#3
0
        private void SetVideoWindow()
        {
            SetVideoPositions();
            _hiddenWindow.SizeChanged += _hiddenWindow_SizeChanged;

            if (_cursorHidden)
            {
                _videoWindow.HideCursor(OABool.True);
            }
            _videoWindow.put_Owner(VideoWindowHandle);
            _videoWindow.put_WindowStyle(DirectShowLib.WindowStyle.Child | DirectShowLib.WindowStyle.Visible | DirectShowLib.WindowStyle.ClipSiblings);
            _videoWindow.SetWindowForeground(OABool.True);

            //_videoWindow.put_FullScreenMode(OABool.True);

            if (_madvr != null)
            {
                SetExclusiveMode(false);
            }
        }
示例#4
0
        private void Videotest1()
        {
            pGraphBuilder = (DirectShowLib.IGraphBuilder) new FilterGraph();
            pMediaControl = (DirectShowLib.IMediaControl)pGraphBuilder; //controler
            pMediaEvent   = (DirectShowLib.IMediaEvent)pGraphBuilder;   //envent

            pMediaControl.RenderFile(@"C:\Users\trevor\Desktop\Videos\cctv2.wmv");
            pVideoWindow = (DirectShowLib.IVideoWindow)pGraphBuilder; // renderFile을 실행 한 후 연결해줘야한다. 출력처를 알기위해서.
            //pVideoWindow.put_Caption("test"); // setTitle
            //pVideoWindow.put_FullScreenMode(OABool.True); //Video full Screen
            pVideoWindow.put_Owner(tabPage2.Handle); // tabPage2에 그리기.
            pVideoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings);
            Rectangle rect = tabPage2.ClientRectangle;

            pVideoWindow.SetWindowPosition(0, 0, rect.Right, rect.Bottom);
            pMediaControl.Run();                              // Video play

            pMediaEvent.WaitForCompletion(-1, out eventCode); //블로킹을 실시하는 메소드

            switch (eventCode)
            {
            case 0:
                textBox1.Text = "TimeOut";
                break;

            case EventCode.UserAbort:     //ex) alt+f4
                textBox1.Text = "User Abort";
                break;

            case EventCode.Complete:
                textBox1.Text = "complete";
                break;

            case EventCode.ErrorAbort:
                textBox1.Text = "Error Abort";

                break;
            }

            //pVideoWindow.put_FullScreenMode(OABool.False); // !full Screen

            //free
            Marshal.ReleaseComObject(pGraphBuilder);
            pGraphBuilder = null;
            Marshal.ReleaseComObject(pMediaControl);
            pMediaControl = null;
            Marshal.ReleaseComObject(pMediaEvent);
            pMediaEvent = null;
        }
示例#5
0
        private void SetupGraph(Control hWin, string filename)
        {
            pGraphBuilder   = (DirectShowLib.IGraphBuilder) new FilterGraph();
            pMediaControl   = (DirectShowLib.IMediaControl)pGraphBuilder;
            pVideoWindow    = (DirectShowLib.IVideoWindow)pGraphBuilder;
            pVideoFrameStep = (DirectShowLib.IVideoFrameStep)pGraphBuilder; // video frame...
            pMediaPosition  = (DirectShowLib.IMediaPosition)pGraphBuilder;
            //DirectShowLib.IBaseFilter pBaseFilter = (DirectShowLib.IBaseFilter)pGraphBuilder;

            //pMediaSeeking = (DirectShowLib.IMediaSeeking)pGraphBuilder;
            //pMediaSeeking.SetPositions(5000, AMSeekingSeekingFlags.AbsolutePositioning, 6000, AMSeekingSeekingFlags.AbsolutePositioning);

            //test
            DirectShowLib.ICaptureGraphBuilder2  pCaptureGraphBuilder2;
            DirectShowLib.IBaseFilter            pRenderer;
            DirectShowLib.IVMRFilterConfig9      pIVMRFilterConfig9;
            DirectShowLib.IVMRWindowlessControl9 pVMRWC9;

            pCaptureGraphBuilder2 = (DirectShowLib.ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            pCaptureGraphBuilder2.SetFiltergraph(pGraphBuilder);     // CaptureGraph를  GraphBuilder에 붙인다.

            //pGraphBuilder.AddFilter(pMediaControl "SDZ 375 Source");  // GraphBuilder에 영상장치필터를 추가한다.
            pRenderer          = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9(); // 믹서 필터를 생성 한다.
            pIVMRFilterConfig9 = (DirectShowLib.IVMRFilterConfig9)pRenderer;                           // 믹서 필터의 속성을 설정한다.
            pIVMRFilterConfig9.SetRenderingMode(VMR9Mode.Windowless);
            pIVMRFilterConfig9.SetNumberOfStreams(2);

            pVMRWC9 = (DirectShowLib.IVMRWindowlessControl9)pRenderer;              // 오버레이 평면의 속성을 설정한다.
            pVMRWC9.SetVideoClippingWindow(hWin.Handle);
            pVMRWC9.SetBorderColor(0);
            pVMRWC9.SetVideoPosition(null, hWin.ClientRectangle);
            pGraphBuilder.AddFilter(pRenderer, "Video Mixing Renderer");                               // GraphBuilder에 믹스 필터를 추가한다.
            pCaptureGraphBuilder2.RenderStream(null, MediaType.Video, pGraphBuilder, null, pRenderer); // 영상표시를 위한 필터를 설정한다.
            ///test

            //sampleGrabber
            AMMediaType am_media_type = new AMMediaType();

            pSampleGrabber           = (DirectShowLib.ISampleGrabber) new SampleGrabber();
            pSampleGrabberFilter     = (DirectShowLib.IBaseFilter)pSampleGrabber;
            am_media_type.majorType  = MediaType.Video;
            am_media_type.subType    = MediaSubType.RGB24;
            am_media_type.formatType = FormatType.VideoInfo;
            pSampleGrabber.SetMediaType(am_media_type);
            //Graph에 sampleGrabber filter를 추가
            pGraphBuilder.AddFilter(pSampleGrabberFilter, "Sample Grabber");

            pMediaControl.RenderFile(filename);

            pVideoWindow.put_Owner(hWin.Handle);
            pVideoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings);
            Rectangle rect = hWin.ClientRectangle;

            pVideoWindow.SetWindowPosition(0, 0, rect.Right, rect.Bottom);

            //sampleGrabber2
            pSampleGrabber.GetConnectedMediaType(am_media_type);
            DirectShowLib.VideoInfoHeader pVideoInfoHeader = (DirectShowLib.VideoInfoHeader)Marshal.PtrToStructure(am_media_type.formatPtr, typeof(VideoInfoHeader));
            String str = string.Format("size = {0} x {1}", pVideoInfoHeader.BmiHeader.Width, pVideoInfoHeader.BmiHeader.Height);

            Video_Width   = pVideoInfoHeader.BmiHeader.Width;
            Video_Height  = pVideoInfoHeader.BmiHeader.Height;
            str          += string.Format("sample size = {0}", am_media_type.sampleSize);
            textBox1.Text = str;
            DsUtils.FreeAMMediaType(am_media_type);
            //SetBufferSamples를 실행하지 않으면 버퍼로부터 데이터를 얻을 수 없다.
            //불필요하게 부하를 주고싶지 않은경우 false, 데이터를 얻고싶으면 true
            pSampleGrabber.SetBufferSamples(true);

            //play time
            pMediaPosition = (DirectShowLib.IMediaPosition)pGraphBuilder;
            double Length;

            pMediaPosition.get_Duration(out Length);
            String str2 = string.Format("play time: {0}", Length);

            textBox1.Text = str2;
            pMediaPosition.put_CurrentPosition(5.0); //set current Position



            //2017.05.08
            DirectShowLib.IVMRWindowlessControl9 windowlessCtrl = (DirectShowLib.IVMRWindowlessControl9)pRenderer;
            windowlessCtrl.SetVideoClippingWindow(hWin.Handle);
            IntPtr lpDib;

            windowlessCtrl.GetCurrentImage(out lpDib);
            BitmapInfoHeader head;

            head = (BitmapInfoHeader)Marshal.PtrToStructure(lpDib, typeof(BitmapInfoHeader));
            int         width       = head.Width;
            int         height      = head.Height;
            int         stride      = width * (head.BitCount / 8);
            PixelFormat pixelFormat = PixelFormat.Format24bppRgb;

            switch (head.BitCount)
            {
            case 24: pixelFormat = PixelFormat.Format24bppRgb; break;

            case 32: pixelFormat = PixelFormat.Format32bppRgb; break;

            case 48: pixelFormat = PixelFormat.Format48bppRgb; break;

            default: throw new Exception("Unknown BitCount");
            }

            Bitmap Cap = new Bitmap(width, height, stride, pixelFormat, lpDib);

            Cap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            pictureBox1.Image = Cap;
        }