public bool PlayVideo(string filePath)
        {
            if (m_list_player.IsPlaying)
            {
                m_list_player.Stop();
            }
            if (m_player.IsPlaying)
            {
                m_player.Stop();
            }

            m_media     = m_factory.CreateMedia <IMediaFromFile>(filePath);
            m_memRender = m_player.CustomRenderer;
            m_memRender.SetCallback(delegate(Bitmap frame)
            {
                Video = (Bitmap)frame.Clone();
            });

            m_memRender.SetFormat(new BitmapFormat(1024, 576, ChromaType.RV32));

            try
            {
                m_media.Events.DurationChanged -= new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    -= new EventHandler <MediaStateChange>(Events_StateChanged);
                m_media.Events.ParsedChanged   -= new EventHandler <MediaParseChange>(Events_ParsedChanged);

                m_media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);
                m_media.Events.ParsedChanged   += new EventHandler <MediaParseChange>(Events_ParsedChanged);
            }
            catch (Exception exce)
            {
                m_media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);
                m_media.Events.ParsedChanged   += new EventHandler <MediaParseChange>(Events_ParsedChanged);
            }

            /*  m_renderPlayer = m_factory.CreatePlayer<IAudioPlayer>();
             * m_renderMedia = m_factory.CreateMedia<IMemoryInputMedia>(MediaStrings.IMEM);
             * m_audioRender = m_player.CustomAudioRenderer;
             *
             * var fc = new Func<SoundFormat, SoundFormat>(SoundFormatCallback);
             * m_player.CustomAudioRenderer.SetFormatCallback(fc);
             * var ac = new AudioCallbacks { SoundCallback = SoundCallback };
             * m_player.CustomAudioRenderer.SetCallbacks(ac);
             * m_player.CustomAudioRenderer.SetExceptionHandler(Handler);
             * GC.KeepAlive(m_player);*/

            m_player.Channel = AudioChannelType.Stereo;
            m_player.Open(m_media);
            m_media.Parse(true);
            m_player.Play();
            m_video    = true;
            MediaEnded = false;

            return(m_video);
        }
Beispiel #2
0
        public bool Start(string videoSrcUrl)
        {
            if (_bIsInitial)
            {
                return(true);
            }

            _bIsInitial = true;
            try
            {
                if (_vlcmedia != null)
                {
                    _vlcmedia.Events.StateChanged    -= Events_StateChanged;
                    _vlcmedia.Events.DurationChanged -= Events_DurationChanged;
                    _vlcmedia.Dispose();
                }
                _vlcmedia = Vlcfactory.CreateMedia <IMedia>(videoSrcUrl);
                _vlcmedia.Events.StateChanged    += Events_StateChanged;
                _vlcmedia.Events.DurationChanged += Events_DurationChanged;
                // 自定义显示
                _memRender = _vlcplayer.CustomRenderer;
                _memRender.SetFormat(new BitmapFormat(704, 576, ChromaType.RV24));
                _memRender.SetCallback(delegate(Bitmap frame)
                {
                    if ((frame != null) && (ReceiveFrameEvent != null))
                    {
                        if (_videoPlayState)
                        {
                            long currentDateTime = _currentTime;

                            Image imgd             = (Bitmap)frame.Clone();
                            FaceDetectInfo facedet = new FaceDetectInfo(imgd, currentDateTime);

                            //ReceiveFrameEvent(facedet);
                            Task.Factory.StartNew(() => ReceiveFrameEvent(facedet));
                        }
                        frame.Dispose();
                        frame = null;
                    }
                });

                _vlcplayer.Open(_vlcmedia);
                _vlcplayer.Play();
                _videoPlayState = true;

                return(true);
            }
            catch (Exception ex)
            {
                Log4NetHelper.Instance.Error("启动视频播放Capture方法出现错误:" + ex.Message);
                return(false);
            }
        }
        public void GetDuration(string filePath)
        {
            IMedia       media  = m_factory.CreateMedia <IMediaFromFile>(filePath);
            IVideoPlayer player = m_factory.CreatePlayer <IVideoPlayer>();

            m_memRender = player.CustomRenderer;
            m_memRender.SetFormat(new BitmapFormat(1, 1, ChromaType.RV24));
            media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_GetTimeDuration);
            media.Parse(true);
            player.Play();
            player.Stop();

            Thread.Sleep(100);
            player.Dispose();
            m_memRender.Dispose();
            media.Dispose();
        }
Beispiel #4
0
        public void Start(int index, string name, string url)
        {
            Index = index;
            Name  = name;

            IMediaPlayerFactory factory = new MediaPlayerFactory();
            IMedia media = factory.CreateMedia <IMedia>(url);

            m_player = factory.CreatePlayer <IVideoPlayer>();
            m_player.WindowHandle = this.Handle;

            memRender = m_player.CustomRenderer;
            memRender.SetFormat(new BitmapFormat(Width, Height, ChromaType.RV16));

            m_player.AspectRatio = Aspect_Ratio;
            m_player.Open(media);
            m_player.Play();
            timer1.Enabled = true;
        }
Beispiel #5
0
        protected override void DoBackgroundWork()
        {
            try
            {
                frameEncodeInterval = 1000 / this.cameraSpec.vlc_transcode_fps;
                w = this.cameraSpec.h264_video_width;
                h = this.cameraSpec.h264_video_height;
                if (w <= 0 || h <= 0)
                {
                    w = h = 0;
                }

                IVideoPlayer player = null;

                while (!Exit)
                {
                    try
                    {
                        frameNumber             = 0;
                        lastFrameEncoded        = 0;
                        nextFrameEncodeTime     = 0;
                        lastTimestampUpdateTime = -1;
                        frameTimer.Start();
                        IMediaPlayerFactory factory = new MediaPlayerFactory();
                        player = factory.CreatePlayer <IVideoPlayer>();
                        player.Events.TimeChanged += new EventHandler <Declarations.Events.MediaPlayerTimeChanged>(Events_TimeChanged);
                        int      b    = cameraSpec.vlc_transcode_buffer_time;
                        string[] args = new string[] { ":rtsp-caching=" + b, ":realrtsp-caching=" + b, ":network-caching=" + b, ":udp-caching=" + b, ":volume=0", cameraSpec.wanscamCompatibilityMode ? ":demux=h264" : "", cameraSpec.wanscamCompatibilityMode ? ":h264-fps=" + cameraSpec.wanscamFps : "" };
                        string   url  = cameraSpec.imageryUrl;
                        if (cameraSpec.wanscamCompatibilityMode)
                        {
                            url = "http://127.0.0.1:" + MJpegWrapper.cfg.webport + "/" + cameraSpec.id + ".wanscamstream";
                        }
                        IMedia media = factory.CreateMedia <IMedia>(url, args);
                        memRender = player.CustomRenderer2;
                        //memRender.SetExceptionHandler(ExHandler);
                        memRender.SetCallback(delegate(Bitmap frame)
                        {
                            // We won't consume the bitmap here.  For efficiency's sake under light load, we will only encode the bitmap as jpeg when it is requested by a client.
                            frameNumber++;
                            if (!player.Mute)
                            {
                                player.ToggleMute();
                            }
                            if (frameTimer.ElapsedMilliseconds >= nextFrameEncodeTime)
                            {
                                EventWaitHandle oldWaitHandle = newFrameWaitHandle;
                                newFrameWaitHandle            = new EventWaitHandle(false, EventResetMode.ManualReset);
                                oldWaitHandle.Set();
                            }
                            //long time = frameCounter.ElapsedMilliseconds;
                            //if (time >= nextFrameEncodeTime)
                            //{
                            //    lastFrame = ImageConverter.GetJpegBytes(frame);
                            //    nextFrameEncodeTime = time + frameEncodeInterval;
                            //}
                            //latestBitmap = new Bitmap(frame);  // frame.Clone() actually doesn't copy the data and exceptions get thrown
                        });
                        memRender.SetFormat(new BitmapFormat(w, h, ChromaType.RV24));
                        //memRender.SetFormatSetupCallback(formatSetupCallback);
                        player.Open(media);
                        player.Play();
                        if (w == 0)
                        {
                            // Need to auto-detect video size.
                            while (!Exit)
                            {
                                Thread.Sleep(50);
                                Size s = player.GetVideoSize(0);
                                if (s.Width > 0 && s.Height > 0)
                                {
                                    lock (MJpegWrapper.cfg)
                                    {
                                        w = this.cameraSpec.h264_video_width = (ushort)s.Width;
                                        h = this.cameraSpec.h264_video_height = (ushort)s.Height;
                                        MJpegWrapper.cfg.Save(Globals.ConfigFilePath);
                                    }
                                    throw new Exception("Restart");
                                }
                            }
                        }
                        else
                        {
                            while (!Exit)
                            {
                                Thread.Sleep(50);
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    {
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message != "Restart")
                        {
                            Logger.Debug(ex);
                            int waitedTimes = 0;
                            while (!Exit && waitedTimes++ < 100)
                            {
                                Thread.Sleep(50);
                            }
                        }
                    }
                    finally
                    {
                        frameTimer.Stop();
                        frameTimer.Reset();
                        if (player != null)
                        {
                            player.Stop();
                        }
                        newFrameWaitHandle.Set();
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Logger.Debug(ex);
            }
            newFrameWaitHandle.Set();
        }
        public VlcPlayer()
        {
            string[] args = new string[]
            {
                "-I",
                "dumy",
                "--ignore-config",
                "--no-osd",
                "--disable-screensaver",
                "--plugin-path=./plugins",
                "--audio-filter=equalizer",
                "--equalizer-preamp=11.9",
                "--equalizer-bands=0 0 0 0 0 0 0 0 0 0"
            };

            m_factory            = new MediaPlayerFactory(args);
            m_player             = m_factory.CreatePlayer <IVideoPlayer>();
            m_media_list         = m_factory.CreateMediaList <IMediaList>();
            m_media_list_preview = m_factory.CreateMediaList <IMediaList>();

            m_presets = Implementation.Equalizer.Presets.ToDictionary(key => key.Index);

            m_equalizer = new Implementation.Equalizer(m_presets[0]);

            m_equalizer.Preamp = Equalizer.ArrBandValue[10].PreAmp / 10;

            for (int i = 0; i < Equalizer.ArrBandValue.Count() - 2; i++)
            {
                m_equalizer.Bands[i].Amplitude = Equalizer.ArrBandValue[i].Gain / 10;

                Console.WriteLine("Amplitude " + m_equalizer.Bands[i].Amplitude + " : " + m_equalizer.Preamp);
            }

            m_player.SetEqualizer(m_equalizer);
            m_equalizer.Dispose();

            //Background Video ==========
            m_list_player = m_factory.CreateMediaListPlayer <IMediaListPlayer>(m_media_list);

            m_memRender = m_list_player.InnerPlayer.CustomRenderer;
            m_memRender.SetCallback(delegate(Bitmap frame)
            {
                Video = (Bitmap)frame.Clone();
            });

            // 4:3 aspect ratio resolutions: 640×480, 800×600, 960×720, 1024×768, 1280×960, 1400×1050, 1440×1080 , 1600×1200, 1856×1392, 1920×1440, and 2048×1536
            //16:9 aspect ratio resolutions: 1024×576, 1152×648, 1280×720, 1366×768, 1600×900, 1920×1080, 2560×1440 and 3840×2160

            m_memRender.SetFormat(new BitmapFormat(1024, 576, ChromaType.RV32));
            m_list_player.PlaybackMode     = PlaybackMode.Loop;
            m_list_player.InnerPlayer.Mute = true;
            //Background Video

            //Preview Background video ==========
            m_list_preview_player = m_factory.CreateMediaListPlayer <IMediaListPlayer>(m_media_list_preview);
            m_list_preview_player.PlaybackMode     = PlaybackMode.Loop;
            m_list_preview_player.InnerPlayer.Mute = true;
            //Preview Background video

            m_player.Events.PlayerPositionChanged += new EventHandler <MediaPlayerPositionChanged>(Events_PlayerPositionChanged);
            m_player.Events.TimeChanged           += new EventHandler <MediaPlayerTimeChanged>(Events_TimeChanged);
            m_player.Events.MediaEnded            += new EventHandler(Events_MediaEnded);
            m_player.Events.PlayerStopped         += new EventHandler(Events_PlayerStopped);

            videoDir = Main_Form.iniFileHelper.Read("Video", "Video Path");

            if (videoDir == string.Empty || !Directory.Exists(videoDir))
            {
                videoDir = BGVideoPath + @"VIDEO_NATURE\";
            }

            GetVideoBG(videoDir);

            SetAudioOutputDevice();
        }