JPEG video source.

The video source constantly downloads JPEG files from the specified URL.

Sample usage:

// create JPEG video source JPEGStream stream = new JPEGStream( "some url" ); // set NewFrame event handler stream.NewFrame += new NewFrameEventHandler( video_NewFrame ); // start the video source stream.Start( ); // ... // signal to stop stream.SignalToStop( ); // ... private void video_NewFrame( object sender, NewFrameEventArgs eventArgs ) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame }

Some cameras produce HTTP header, which does not conform strictly to standard, what leads to .NET exception. To avoid this exception the useUnsafeHeaderParsing configuration option of httpWebRequest should be set, what may be done using application configuration file.

<configuration> <system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true" /> </settings> </system.net> </configuration>
Inheritance: IVideoSource
Exemple #1
1
		private void btnOk_Click(object sender, EventArgs e)
		{
			// I'm making sure that filters actually contains something.
			if (rdoCaptureDevice.Checked && filters.Count > 0)
			// Chose to use a capture videoSource.
			{
				// create video source
				VideoCaptureDevice localSource = new VideoCaptureDevice();
				localSource.Source = filters[deviceCombo.SelectedIndex].MonikerString;
				localSource.DesiredFrameSize = new Size(int.Parse(txtWidth.Text), int.Parse(txtHeight.Text));
				videoSource = localSource;
			}
			// Make sure that the text box contains a path.
			else if (!txtFileName.Text.Equals(String.Empty)) // Chose to load a movie.
			{
				// create video source
				AVIFileVideoSource fileSource = new AVIFileVideoSource();
				fileSource.Source = txtFileName.Text;
				videoSource = fileSource;
			} else if (!txtMjpegUrl.Text.Equals(String.Empty)) // Chose to load a url.
			{
				MJPEGStream stream = new MJPEGStream(txtMjpegUrl.Text);
				videoSource = stream;
			} else if (!txtJpgUrl.Text.Equals(String.Empty)) // Chose to load a url.
			{
				JPEGStream stream = new JPEGStream(txtJpgUrl.Text);
				videoSource = stream;
			}
			else // Unable to display.
			{
				showErrorMessage("No video source was chosen.");
				return;
			}

			DialogResult = DialogResult.OK;
			Hide();
		}
Exemple #2
0
 public JLvideo()
 {
     // create JPEG video source
     mStream = new AForge.Video.JPEGStream();
     // set NewFrame event handler
     mStream.NewFrame += new AForge.Video.NewFrameEventHandler(video_NewFrame);
     // instantiate AVI writer, use WMV3 codec
     mAviWriter = new AVIWriter( "wmv3" );
 }
Exemple #3
0
        // Open JPEG URL
        private void openJPEGURLToolStripMenuItem_Click( object sender, EventArgs e )
        {
            URLForm form = new URLForm( );

            form.Description = "Enter URL of an updating JPEG from a web camera:";
            form.URLs = new string[]
				{
					"http://195.243.185.195/axis-cgi/jpg/image.cgi?camera=1",
				};

            if ( form.ShowDialog( this ) == DialogResult.OK )
            {
                // create video source
                JPEGStream jpegSource = new JPEGStream( form.URL );

                // open it
                OpenVideoSource( jpegSource );
            }
        }
        public void Enable()
        {
            _processing = true;

            switch (Camobject.settings.sourceindex)
            {
                case 0:
                    var jpegSource = new JPEGStream(Camobject.settings.videosourcestring);
                    if (Camobject.settings.frameinterval != 0)
                        jpegSource.FrameInterval = Camobject.settings.frameinterval;
                    if (Camobject.settings.login != "")
                    {
                        jpegSource.Login = Camobject.settings.login;
                        jpegSource.Password = Camobject.settings.password;
                    }
                    //jpegSource.SeparateConnectionGroup = true;
                    jpegSource.RequestTimeout = iSpyServer.Default.IPCameraTimeout;
                    OpenVideoSource(jpegSource, false);
                    break;
                case 1:
                    var mjpegSource = new MJPEGStream(Camobject.settings.videosourcestring)
                                          {
                                              Login = Camobject.settings.login,
                                              Password = Camobject.settings.password,
                                              RequestTimeout = iSpyServer.Default.IPCameraTimeout,
                                              HttpUserAgent = Camobject.settings.useragent
                                          };
                    //mjpegSource.SeparateConnectionGroup = true;
                    OpenVideoSource(mjpegSource, false);
                    break;
                case 2:
                    //var fileSource = new AVIFileVideoSource(Camobject.settings.videosourcestring);
                    //OpenVideoSource(fileSource, true);
                    break;
                case 3:
                    string moniker = Camobject.settings.videosourcestring;

                    var videoSource = new VideoCaptureDevice(moniker);
                    string[] wh = Camobject.resolution.Split('x');
                    var sz = new Size(Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1]));
                    var vc = videoSource.VideoCapabilities.Where(p => p.FrameSize == sz).ToList();
                    if (vc.Count>0)
                    {
                        var vc2 = vc.FirstOrDefault(p => p.AverageFrameRate == Camobject.settings.framerate) ??
                                  vc.FirstOrDefault();
                        videoSource.VideoResolution = vc2;
                    }

                    if (Camobject.settings.crossbarindex!=-1 && videoSource.CheckIfCrossbarAvailable())
                    {
                        var cbi =
                            videoSource.AvailableCrossbarVideoInputs.FirstOrDefault(
                                p => p.Index == Camobject.settings.crossbarindex);
                        if (cbi!=null)
                        {
                            videoSource.CrossbarVideoInput = cbi;
                        }
                    }

                    OpenVideoSource(videoSource, true);
                    break;
                case 4:
                    Rectangle area = Rectangle.Empty;
                    if (!String.IsNullOrEmpty(Camobject.settings.desktoparea))
                    {
                        var i = Array.ConvertAll(Camobject.settings.desktoparea.Split(','), int.Parse);
                        area = new Rectangle(i[0],i[1],i[2],i[3]);
                    }
                    var desktopSource = new DesktopStream(Convert.ToInt32(Camobject.settings.videosourcestring), area)
                                            {MousePointer = Camobject.settings.desktopmouse};
                    if (Camobject.settings.frameinterval != 0)
                        desktopSource.FrameInterval = Camobject.settings.frameinterval;
                    OpenVideoSource(desktopSource, false);
                    break;
                case 5:
                    var ks = new KinectStream(Nv("UniqueKinectId"), Convert.ToBoolean(Nv("KinectSkeleton")));
                    OpenVideoSource(ks, true);
                    break;
            }

            if (Camera != null)
            {
                if (!Camera.IsRunning)
                {
                    Camera.Start();
                }

                Camobject.settings.active = true;

                if (File.Exists(Camobject.settings.maskimage))
                {
                    Camera.Mask = Image.FromFile(Camobject.settings.maskimage);
                }
            }
            _frameCount = 0;
            VideoSourceErrorState = false;
            VideoSourceErrorMessage = "";
            Camobject.ftp.ready = true;
            MainForm.NeedsSync = true;

            Invalidate();
            _lastRun = DateTime.Now.Ticks;
            _processing = false;
        }
Exemple #5
0
        private void OpenVideoPlayer()
        {
            StopVideoPlayer();

            JPEGStream cameraStream = new JPEGStream(
                Properties.Settings.Default.CameraURL);
            cameraStream.Login = Properties.Settings.Default.CameraUser;
            cameraStream.Password = Properties.Settings.Default.CameraPassword;
            this.Cursor = Cursors.WaitCursor;

            videoPlayer.VideoSource = cameraStream;
            videoPlayer.Start(); ;
            this.Cursor = Cursors.Default;
        }
 private void StartIPCam(CaptureDevice selectedDevice)
 {
     var stream = new JPEGStream(selectedDevice.Id);
     // create async video source
     var asyncSource = new AsyncVideoSource(stream);
     // set NewFrame event handler
     asyncSource.NewFrame += FrameReady;
     // start the video source
     asyncSource.Start();
 }
Exemple #7
0
        private void OpenJpegUrlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var form = new UrlForm();

            form.Description = "Enter URL of an updating JPEG from a web camera:";
            form.Urls = new[]
                            {
                                "http://195.243.185.195/axis-cgi/jpg/image.cgi?camera=1"
                            };

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                var jpegSource = new JPEGStream(form.Url);
                OpenVideoSource(jpegSource);
            }
        }