コード例 #1
0
        public static void startSecond()
        {
            initDSArrays();



            filter1 = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9();
            DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)filter1;
            filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            filterConfig.SetNumberOfStreams(2);


            DirectShowLib.IVMRSurfaceAllocatorNotify9 vmrSurfAllocNotify = (DirectShowLib.IVMRSurfaceAllocatorNotify9)filter1;

            try
            {
                int hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(userId1, allocator);
                DsError.ThrowExceptionForHR(hr);

                hr = allocator.AdviseNotify(vmrSurfAllocNotify);
                DsError.ThrowExceptionForHR(hr);
            }
            catch { }



            graph1 = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph();
            graph1.AddFilter(filter1, "Video Mixing Renderer 9");

            graph1.RenderFile(@"C:\Download\workmates.wmv", null);
            mediaControl1 = (DirectShowLib.IMediaControl)graph1;
            mediaControl1.Run();
        }
コード例 #2
0
        /// <summary>
        /// Load a video to setup DirectShow. This also initally creates an instance of the DirectX3D Device
        /// </summary>
        public static void StartGraph()
        {
            int hr = 0;

            //CloseGraph();

            string path = @"opensebj.wmv";

            try
            {
                graph  = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph();
                filter = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9();

                DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)filter;

                hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
                DsError.ThrowExceptionForHR(hr);

                hr = filterConfig.SetNumberOfStreams(2);
                DsError.ThrowExceptionForHR(hr);

                SetAllocatorPresenter();

                hr = graph.AddFilter(filter, "Video Mixing Renderer 9");
                DsError.ThrowExceptionForHR(hr);

                hr = graph.RenderFile(path, null);
                DsError.ThrowExceptionForHR(hr);

                mediaControl = (DirectShowLib.IMediaControl)graph;
            }
            catch
            {
            }
        }
コード例 #3
0
        private void InitializeDvd(string path)
        {
            /* The DVDControl2 interface lets us control DVD features */
            _mDvdControl = _dvdNav as IDvdControl2;

            if (_mDvdControl == null)
            {
                throw new Exception("Could not QueryInterface the IDvdControl2 interface");
            }

            /* QueryInterface the DVDInfo2 */
            _mDvdInfo = _dvdNav as IDvdInfo2;

            var videoTsPath = Path.Combine(path, "video_ts");

            if (Directory.Exists(videoTsPath))
            {
                path = videoTsPath;
            }

            /* If a Dvd directory has been set then use it, if not, let DShow find the Dvd */
            var hr = _mDvdControl.SetDVDDirectory(path);

            DsError.ThrowExceptionForHR(hr);

            /* This gives us the DVD time in Hours-Minutes-Seconds-Frame time format, and other options */
            hr = _mDvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);
            DsError.ThrowExceptionForHR(hr);

            /* If the graph stops, resume at the same point */
            _mDvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);

            hr = m_graph.AddFilter(_dvdNav, "DVD Navigator");
            DsError.ThrowExceptionForHR(hr);

            //int uTitle = 1;
            //dma = new DvdMenuAttributes();
            //dta = new DvdTitleAttributes();
            //m_dvdInfo.GetTitleAttributes(uTitle, out dma, dta);

            //int iX = dta.VideoAttributes.aspectX;
            //int iY = dta.VideoAttributes.aspectY;
            //DvdIsLetterBoxed = dta.VideoAttributes.isSourceLetterboxed;
            //int sX = dta.VideoAttributes.sourceResolutionX;
            //int sY = dta.VideoAttributes.sourceResolutionY;
        }
コード例 #4
0
ファイル: GUI.cs プロジェクト: mguthrie777/demo-newstuff
        //
        // Starts playback for the selected stream at the specified time
        //
        int OpenStream(string videopath, double videotime)
        {
            double td;  // store stream duration;
            int hr = 0;

            // animate bt logo
            //   logo_webbrowser.Refresh();

            // cover overlay options with video or not
            // if overlay is active
            ////////if (OverlayButton.Checked) // Overlay button config - Melek
            ////////{
            ////////    VideoPanel.Width = VideoPlayerPanel.Width - OverlayPanel.Width;
            ////////    OverlayBar.Location = new System.Drawing.Point(-1, -1); ;
            ////////    OverlayBar.Text = ">";
            ////////}
            ////////else
            ////////// if overlay is not active
            ////////{
            ////////    VideoPanel.Width = VideoPlayerPanel.Width - OverlayBar.Width;
            ////////    OverlayBar.Location = new System.Drawing.Point(OverlayPanel.Width - OverlayBar.Width - 1, -1); ;
            ////////    OverlayBar.Text = "<";
            ////////}

            filename = videopath;
            try//Melek
            {
                if (filename == string.Empty)
                    return -1;

                // this.graphBuilder = (IGraphBuilder)new FilterGraph();
                this.graphBuilder = (IFilterGraph2)new FilterGraph();

                // We manually add the VMR (video mixer/renderer) filter so that we can set it into "mixing" mode.
                // That is needed so that the VMR will deinterlace before playing back
                VideoMixingRenderer vmr = new VideoMixingRenderer(); //Tom's deinterlace changes
                graphBuilder.AddFilter((IBaseFilter)vmr, "vmr");//Tom's deinterlace changes
                IVMRFilterConfig vmrConfig = vmr as IVMRFilterConfig;//Tom's deinterlace changes
                int nRet = vmrConfig.SetNumberOfStreams(1);//Tom's deinterlace changes

                // BuildVideoGraph(videopath); //No more overlay - Melek
                hr = this.graphBuilder.RenderFile(filename, null);//MELek - instead of calling BuildVideoGraph function call RenderFile function directly
                DsError.ThrowExceptionForHR(hr);//Melek

                // QueryInterface for DirectShow interfaces
                this.mediaControl = (IMediaControl)this.graphBuilder;
                this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
                this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
                this.mediaPosition = (IMediaPosition)this.graphBuilder;

                // Query for video interfaces, which may not be relevant for audio files
                this.videoWindow = this.graphBuilder as IVideoWindow;
                this.basicVideo = this.graphBuilder as IBasicVideo;

                // Query for audio interfaces, which may not be relevant for video-only files
                this.basicAudio = this.graphBuilder as IBasicAudio;

                // Is this an audio-only file (no video component)?
                CheckVisibility();

                // Have the graph signal event via window callbacks for performance
                hr = this.mediaEventEx.SetNotifyWindow(this.Handle, WMGraphNotify, IntPtr.Zero);

                DsError.ThrowExceptionForHR(hr);

                //if (!this.isAudioOnly)
                //{
                // Setup the video window
                hr = this.videoWindow.put_Owner(this.VideoPanel.Handle);

                DsError.ThrowExceptionForHR(hr);

                hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
                DsError.ThrowExceptionForHR(hr);

                hr = InitVideoWindow(1, 1);
                DsError.ThrowExceptionForHR(hr);

                GetFrameStepInterface();
                //}
                //else
                //{
                // Initialize the default player size
                //    hr = InitPlayerWindow();
                //    DsError.ThrowExceptionForHR(hr);

                //EnablePlaybackMenu(true, MediaType.Audio);
                //}

                // Complete window initialization
                //CheckSizeMenu(menuFileSizeNormal);
                //this.isFullScreen = false;
                this.currentPlaybackRate = 1.0;

            #if DEBUG
                rot = new DsROTEntry(this.graphBuilder);
            #endif

                // check the mute button
                MuteStatus();

                // Run the graph to play the media file
                this.mediaPosition.put_CurrentPosition(videotime);
                hr = this.mediaControl.Run();

                DsError.ThrowExceptionForHR(hr);

                this.currentState = PlayState.Running;

                UpdateMainTitle();

                try
                {
            #if !DEMO
                    this.mediaPosition.get_Duration(out td);
            #else
                    td=vs.getDurationInSeconds();
            #endif

                    this.VideoProgressionBar.Minimum = 0;
                    this.VideoProgressionBar.Maximum = (int)(td * 100);

                    isTimer = true;
                    // disable if raw 264 files are open (.264 or .h264) as they dont allow seeking
                    if (videopath.EndsWith("264"))
                        this.mediaSeeking = null;
                    return 0;

                }
                catch (Exception ex)
                {
                    //Global.log("Problem opening " + vs.path.Name + ".ts\n" + ex);
                    Global.log("Problem opening " + vs.StreamFileName + "\n" + ex); //Melek - path.name => streamfilename
                    EnablePlayback(false); //MElek
                    return -1;
                }

            }
            catch (Exception ex) //Melek
            {
                //  MessageBox.Show(ex.Message);
                EnablePlayback(false);
                return -1;
            }
        }
コード例 #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;
        }