Beispiel #1
0
        public void PlayAvi(string path, bool saveScreen = false)
        {
            var i = 0;

            try
            {
                var s      = new VideoFileSource(path);
                var reader = new VideoFileReader();
                var uri    = new Uri(path);
                reader.Open(uri.AbsolutePath);
                int framesToSkip = reader.FrameRate * 3600;

                var seconds = reader.FrameCount / reader.FrameRate;

                for (i = 0; i < reader.FrameCount; i++)
                {
                    try
                    {
                        var screen = reader.ReadVideoFrame();
                        Console.WriteLine(i);
                        if (i % 25 == 0)
                        {
                            screen.Save(@"screen_" + i.ToString() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    } catch { }
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
            }
        }
 /// <summary>
 /// This event is called when the stream finishes and loopAudio is set to true.
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="reason"></param>
 public void PlayingFinished(object sender, ReasonToFinishPlaying reason)
 {
     _source                  = new VideoFileSource(_source.Source);
     _source.NewFrame        += NextFrame;
     _source.PlayingFinished += PlayingFinished;
     _source.Start();
 }
Beispiel #3
0
        private void CloseVideoSource()
        {
            if (!(kamera == null))
            {
                if (kamera.IsRunning)
                {
                    kamera.SignalToStop();
                    kamera = null;
                }
            }

            if (!(stream == null))
            {
                if (stream.IsRunning)
                {
                    stream.SignalToStop();
                    stream = null;
                }
            }

            if (!(videoSource == null))
            {
                if (videoSource.IsRunning)
                {
                    videoSource.SignalToStop();
                    videoSource = null;
                }
            }
        }
        static void Main(string[] args)
        {
            var options = new PicToAsciiOptions()
            {
                FixedDimension    = PicToAsciiOptions.Fix.Vertical,
                FixedSize         = 54,
                SymbolAspectRatio = 7f / 12f,
                AsciiTable        = PicToAsciiOptions.ASCIITABLE_SYMBOLIC_LIGHT
            };

            pic2ascii = new PicToAscii(options);

            font = new Font("Lucida Console", 12, FontStyle.Regular, GraphicsUnit.Pixel);

            writer = new VideoFileWriter( );
            writer.Open($"{MOV_PATH}~test.avi", width, height, 30, VideoCodec.MPEG4, 6000000);

            VideoFileSource videoSource = new VideoFileSource(MOVIESAMPLE_PATH);

            videoSource.NewFrame        += VideoSource_NewFrame;
            videoSource.PlayingFinished += VideoSource_PlayingFinished;
            videoSource.Start();

            Console.ReadLine();
            if (videoSource.IsRunning)
            {
                videoSource.SignalToStop();
                Console.ReadLine();
            }
        }
 public StereoGeminateAForgeFileVideoStreamProvider(String fileName, int frameInterval)
 {
     VideoFileSource fileVideo = new VideoFileSource(fileName);
     this.frameInterval = fileVideo.FrameInterval = (int)(1.0 / 30 * 1000);
     //VideoFileSource f = new VideoFileSource("");
     asyncVideoSource = new AsyncVideoSource(fileVideo);
     this.Init();
     asyncVideoSource.NewFrame += NewFrameCallback;
 }
Beispiel #6
0
        private void btnReconect_Click(object sender, System.EventArgs e)
        {
            vsp.Stop();

            vfs = new VideoFileSource("rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa");

            vsp.VideoSource = vfs;
            vsp.Start();
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            pbThreshold.SizeMode = PictureBoxSizeMode.StretchImage;
            pbMasked.SizeMode    = PictureBoxSizeMode.StretchImage;
            var path        = $@"{Application.StartupPath}\Mario.mp4";
            var videoSource = new VideoFileSource(path);

            vspMain.VideoSource = videoSource;
            vspMain.Start();
        }
        // Open file
        private void openFileItem_Click(object sender, System.EventArgs e)
        {
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                // create video source
                VideoFileSource fileSource = new VideoFileSource();
                fileSource.VideoSource = ofd.FileName;

                // open it
                OpenVideoSource(fileSource);
            }
        }
Beispiel #9
0
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();

            //For any other formats
            if (of.ShowDialog() == DialogResult.OK)
            {
                baca           = new VideoFileSource(of.FileName);
                baca.NewFrame += stream_NewFrame;
                baca.Start();
            }
        }
Beispiel #10
0
 public VideoStreamImp(VideoFileSource source, bool loopVideo, bool useAudio)
 {
     _source           = source;
     _source.NewFrame += NextFrame;
     if (loopVideo)
     {
         _source.PlayingFinished += PlayingFinished;
     }
     _source.VideoSourceError += VideoSourceError;
     _source.WaitForStop();
     _source.Start();
 }
Beispiel #11
0
        private void openvideo_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog Dialog = new OpenFileDialog();

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                videoSource = new VideoFileSource(Dialog.FileName);
                // set NewFrame event handler
                videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
                // start the video source
                videoSource.Start();
            }
        }
Beispiel #12
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog dialog = new OpenFileDialog())
     {
         dialog.InitialDirectory = @"C:\Temp";
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             _source = new VideoFileSource(dialog.FileName);
             videoSourcePlayer1.VideoSource = _source;
             videoSourcePlayer1.Start();
         }
     }
 }
        // Open video source
        public bool openInputSource(string identifier, TInputType type, bool isAutoPlay)
        {
            IVideoSource source;

            switch (type)
            {
            case TInputType.IMAGE:
                source = new ImageSource();
                break;

            case TInputType.VIDEO:
                source = new VideoFileSource();
                break;

            case TInputType.DEVICE:
                source = new CaptureDevice();
                break;

            default:
                return(false);
            }
            source.VideoSource = identifier;

            // close previous file
            closeInputSource();

            // create camera
            CCamera camera = new CCamera(source);

            // attach camera to camera window
            _cameraWindow.postRenderingEvent       = postRenderingEvent;
            _cameraWindow.camera                   = camera;
            _cameraWindow.camera.preRenderingEvent = preRenderingEvent;

            _inputType = type;
            if (isAutoPlay)
            {
                play();
            }
            else
            {
                //getFirstFrame();
            }

            // reset statistics
            _statIndex = _statReady = 0;

            return(true);
        }
Beispiel #14
0
        public long GetDuration(string path)
        {
            var s      = new VideoFileSource(path);
            var reader = new VideoFileReader();
            var uri    = new Uri(path);
            var fi     = new FileInfo(path);

            if (fi.Exists)
            {
                reader.Open(path);
                var seconds = reader.FrameCount / reader.FrameRate;
                return(seconds);
            }
            return(-1);
        }
Beispiel #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();

            //For any other formats
            if (kamera != null && kamera.IsRunning)
            {
                kamera.Stop();
            }
            if (of.ShowDialog() == DialogResult.OK)
            {
                baca           = new VideoFileSource(of.FileName);
                baca.NewFrame += new NewFrameEventHandler(kamera_ProsesFrame);
                baca.Start();
            }
        }
Beispiel #16
0
        private void startButton_Click(object sender, EventArgs e)
        {
            if (((Button)sender).Text == "Start")
            {
                if (FinalFrame != null)
                {
                    videoSourcePlayer.SignalToStop();
                }
                startButton.Text = "Stop";

                if (cbListDevices.SelectedIndex == cbListDevices.Items.Count - 1) // browse
                {
                    pictureBox1.BringToFront();
                    if (videoSourcePlayer.IsRunning)
                    {
                        videoSourcePlayer.Stop();
                    }
                    videoSource2           = new VideoFileSource(filePath);
                    videoSource2.NewFrame += new Accord.Video.NewFrameEventHandler(video_NewFrame);
                    // start the video source (local video)
                    videoSource2.Start();
                }
                else
                {
                    if (videoSource2 != null)
                    {
                        videoSource2.SignalToStop();
                    }
                    videoSourcePlayer.BringToFront();
                    FinalFrame = new VideoCaptureDevice(videoSource[cbListDevices.SelectedIndex].MonikerString);
                    //videoSourcePlayer.NewFrame += new VideoSourcePlayer.NewFrameHandler(this.videoSourcePlayer_NewFrame);
                    videoSourcePlayer.VideoSource = FinalFrame;
                    videoSourcePlayer.Start();
                }
            }
            else   // stop
            {
                videoSourcePlayer.SignalToStop();
                //videoSourcePlayer.SignalToStop();
                if (videoSource2 != null)
                {
                    videoSource2.SignalToStop();
                }
                ((Button)sender).Text = "Start";
            }
        }
Beispiel #17
0
        private void OpenVideoItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                Filter = "AVI files (*.avi)|*.avi",
                Title  = "Open movie"
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                VideoFileSource fileSource = new VideoFileSource()
                {
                    VideoSource = openFileDialog.FileName
                };
                OpenVideoSource(fileSource);
            }
        }
Beispiel #18
0
        private void StopProcessing()
        {
            this.Running = false;
            _frameController.Stop();

            if (_videoSource != null && _videoSource.IsRunning)
            {
                _videoSource.SignalToStop();
                _videoSource = null;
            }
            if (_videoFileSource != null && _videoFileSource.IsRunning)
            {
                _videoFileSource.SignalToStop();
                _videoFileSource = null;
            }
            this.Log("Video capture stopped");
            this.UpdateView(this);
        }
Beispiel #19
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "Start")
            {
                string filePath = @"C:\Users\Hot Dog\Desktop\Rehabot_영상\팔꿈치_재활운동용.mp4";
                _videoFile = new VideoFileSource(filePath);

                this.videoSourcePlayer1.VideoSource = _videoFile;
                this.videoSourcePlayer1.Start();

                this.button1.Text = "Stop";
            }
            else
            {
                this.button1.Text = "Start";
                _videoFile.Stop();
            }
        }
Beispiel #20
0
        private void browseVid_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog
            {
                Filter = "AVI Video (*.avi, *.mp4)|*avi; *mp4"
            };

            if (open.ShowDialog() == DialogResult.OK)
            {
                // create video source
                videoSource = new VideoFileSource(open.FileName);
                // set NewFrame event handler
                videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
                // start the video source
                videoSource.Start();
                // ...
                button3.Text = "Stop Video";
            }
        }
Beispiel #21
0
        private void Video_Player_NewFrame(object sender, ref Bitmap image)
        {
            //录像
            Graphics g = Graphics.FromImage(image);

            SolidBrush drawBrush = new SolidBrush(Color.Red);

            Font drawFont = new Font("Arial", 4, FontStyle.Italic, GraphicsUnit.Millimeter);
            int xPos = image.Width - (image.Width - 15);
            int yPos = 10;
            //写到屏幕上的时间
            drawDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            g.DrawString(drawDate, drawFont, drawBrush, xPos, yPos);
            if (!Directory.Exists(videoPath))
                Directory.CreateDirectory(videoPath);

            //开始录像
            if (createNewFile)
            {
                //videoFileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".flv";
                videoFileName = "wuwh.flv";
                videoFileFullPath = videoPath + "/" + videoFileName;
                createNewFile = false;
                if (videoWriter != null)
                {
                    videoWriter.Close();
                    videoWriter.Dispose();
                }
                videoWriter = new VideoFileWriter();
                //这里必须是全路径,否则会默认保存到程序运行根据录下了
                videoWriter.Open(videoFileFullPath, image.Width, image.Height, frameRate, VideoCodec.FLV1);
                videoWriter.WriteVideoFrame(image);

                VideoFileSource videoFileSource = new VideoFileSource(videoFileFullPath);

            }
            else
            {
                videoWriter.WriteVideoFrame(image);
            }
        }
Beispiel #22
0
        private void SetVideo(string fileName)
        {
            var source = new VideoFileSource(fileName);

            videoPlayer.VideoSource = source;
        }
Beispiel #23
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            this.Running = true;
            try
            {
                _frameController.Start();

                if (checkBoxUseWebcam.Checked)
                {
                    // List all available video sources. (That can be webcams as well as tv cards, etc)
                    FilterInfoCollection videosources = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                    //Check if atleast one video source is available
                    if (videosources != null)
                    {
                        //For example use first video device. You may check if this is your webcam.
                        VideoCaptureDevice webcam = new VideoCaptureDevice(videosources[0].MonikerString);
                        _videoSource = webcam;

                        try
                        {
                            //Check if the video device provides a list of supported resolutions
                            if (webcam.VideoCapabilities.Length > 0)
                            {
                                string highestSolution = "0;0";
                                //Search for the highest resolution
                                for (int i = 0; i < webcam.VideoCapabilities.Length; i++)
                                {
                                    if (webcam.VideoCapabilities[i].FrameSize.Width > Convert.ToInt32(highestSolution.Split(';')[0]))
                                    {
                                        highestSolution = webcam.VideoCapabilities[i].FrameSize.Width.ToString() + ";" + i.ToString();
                                    }
                                }
                                //Set the highest resolution as active
                                webcam.VideoResolution = webcam.VideoCapabilities[Convert.ToInt32(highestSolution.Split(';')[1])];
                            }
                        }
                        catch { }

                        //handle new frame event
                        webcam.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);

                        //Start recording
                        webcam.Start();

                        this.Resolution = $"({webcam.VideoResolution.FrameSize.Width}x{webcam.VideoResolution.FrameSize.Height})";
                        this.Log("Video capture started");
                    }
                }
                else if (!string.IsNullOrEmpty(textBoxVideoPath.Text))
                {
                    // let's process the video file
                    _videoFileSource           = new VideoFileSource(textBoxVideoPath.Text);
                    _videoFileSource.NewFrame += _videoFileSource_NewFrame;
                    // start the video source
                    _videoFileSource.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                this.Running = false;
            }
            this.UpdateView(this);
        }
Beispiel #24
0
        public void StartPlay()
        {
            try
            {
                LoadCamInfo();
                if (IsPlaying)
                {
                    return;
                }

                // create video source
                switch (_CamType)
                {
                case 1:    //Local Device
                    CaptureDevice CD = new CaptureDevice();
                    CD.Login       = _UserName;
                    CD.Password    = _Pass;
                    CD.VideoSource = _IP;
                    // open it
                    IsPlaying = OpenVideoSource(CD);
                    break;

                case 2:    //Axis Cam
                    MJPEGStream mjpegSource = new MJPEGStream();
                    mjpegSource.Login       = _UserName;
                    mjpegSource.Password    = _Pass;
                    mjpegSource.VideoSource = _IP;
                    // open it
                    IsPlaying = OpenVideoSource(mjpegSource);
                    break;

                case 3:    //Local Device
                    JPEGStream JS = new JPEGStream();
                    JS.Login       = _UserName;
                    JS.Password    = _Pass;
                    JS.VideoSource = _IP;

                    // open it
                    IsPlaying = OpenVideoSource(JS);
                    break;

                case 4:    //Open File Movie
                    VideoFileSource VF = new VideoFileSource();
                    VF.Login       = _UserName;
                    VF.Password    = _Pass;
                    VF.VideoSource = _IP;

                    // open it
                    IsPlaying = OpenVideoSource(VF);
                    break;
                }

                if (IsPlaying)
                {
                    toolStripStatusLabel1.Text = "Playing";
                }

                //toolStripButton2.Enabled = IsPlaying ;
            }
            catch (ArgumentException ArgEx)
            {
                IsPlaying = false;
                //MessageBox.Show(ArgEx.Message, "Error");
                toolStripStatusLabel2.Text = "" + ArgEx.Message;
            }
            catch (Exception Ex)
            {
                //MessageBox.Show(Ex.Message, "Error");
                toolStripStatusLabel2.Text = "" + Ex.Message;
            }
            finally
            {
                toolStripButton1.Enabled = false;
                EnableBar(IsPlaying);
            }
        }
Beispiel #25
0
 /// <summary>
 /// Creates a video stream from a local video file.
 /// </summary>
 /// <param name="filename">The path to the video file.</param>
 /// <param name="loopVideo">Defines whether the video sould be looped.</param>
 /// <param name="useAudio">Defines whether the video should be played with sound. Note that this option only affects the web build because at the moment
 /// videos with sound are not supported yet in the native build.</param>
 /// <returns>An <see cref="IVideoStreamImp"/>.</returns>
 /// <remarks>If you want to create a web-build, please pay attention to the video-codec and format as not all
 /// formats are supported in HTML5. The recommended format is .webm as this container is supported in all common browsers.</remarks>
 public IVideoStreamImp CreateVideoStreamImpFromFile(string filename, bool loopVideo, bool useAudio)
 {
     _source = new VideoFileSource(filename);
     return(_stream = new VideoStreamImp(_source, loopVideo, useAudio));
 }