MJPEG video source.

The video source downloads JPEG images from the specified URL, which represents MJPEG stream.

Sample usage:

// create MJPEG video source MJPEGStream stream = new MJPEGStream( "some url" ); // set event handlers stream.NewFrame += new NewFrameEventHandler( video_NewFrame ); // start the video source stream.Start( ); // ... // signal to stop stream.SignalToStop( );

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
Esempio n. 1
2
 private void InitializeCamera()
 {
     // create video source
     MJPEGStream mjpegSource = new MJPEGStream(cameraURL);
     textBoxDebug.AppendText("Camera URL" + System.Environment.NewLine);
     textBoxDebug.AppendText(cameraURL + System.Environment.NewLine);
     mjpegSource.Login = "******";
     mjpegSource.Password = "******";
     // open it
     OpenVideo(mjpegSource);
 }
Esempio n. 2
2
        public CameraRecorder(string address)
        {
            this.address = address;
            stream = new MJPEGStream(address + "/image?speed=0");

            recorder = new AVIWriter("XVID");
            recorder.FrameRate = 10;
            recorder.Open("c:\\test.avi", 736, 480);

            stream.NewFrame += newFrameEvent;

            stream.Login = "******";
            stream.Password = "******";
            stream.Start();
        }
Esempio n. 3
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();
		}
Esempio n. 4
0
        public CameraRecorder(MJPEGStream stream, string path, double fps)
        {
            this.path = path;
            this.stream = stream;
            this.fps = fps;

            startRecord(path, (int) fps);
            stream.NewFrame += newFrameEvent;
        }
Esempio n. 5
0
        public ToolboxControl()
        {
            InitializeComponent();

            formsHost.Child = vPlayer;

            MJPEGStream mjpegSource = new MJPEGStream("http://localhost:8080");

            // open it
            OpenVideoSource(mjpegSource);
        }
Esempio n. 6
0
        public CameraRecorder(ConnectionConfigData conf, string path, double fps)
        {
            this.address = "http://"+conf.Address;
            this.path = path;
            this.fps = fps;

            stream = new MJPEGStream("http://"+ address + "/image?speed=0");
            stream.NewFrame += newFrameEvent;
            startRecord(path, (int)fps);
            stream.Login = conf.UserName;
            stream.Password = conf.Password;
            stream.Start();
        }
Esempio n. 7
0
        /// <summary>
        /// Attempts to connect to an MJPEG feed from a given URL (ex. http://localhost:8080)
        /// and returns true/false depending on whether or not it succesfully connected. User must
        /// call StartVideo() to begin feed.
        /// </summary>
        /// <param name="URL"></param>
        /// <returns></returns>
        public bool setMJPEGVideoFeedSource(string URL){
            if (mjpegSource != null && mjpegSource.IsRunning) { //stop other streams from running if they are
                mjpegSource.Stop();
            }
            try {
                mjpegSource = new MJPEGStream(URL);
                mjpegSource.NewFrame += mjpegSource_NewFrame;
                return true;
            }
            catch {
                return false;
            }

        }
Esempio n. 8
0
        public static void VidTest()
        {
            List<Bitmap> frames = new List<Bitmap>();

            AVIWriter aw = new AVIWriter("DIB ");
            aw.FrameRate = 15;
            aw.Open("test2.avi",320,240);
            int i = 0;
            string surl = "";
            MJPEGStream ms = new MJPEGStream();
            ms.Login = "";
            ms.Password = "";
            ms.Source = surl;
            ms.NewFrame += (sender, e) =>
            {
                i++;
                //frames.Add(e.Frame);
                aw.AddFrame(e.Frame);
                e.Frame.Save("test" + i.ToString() + ".jpg", ImageFormat.Jpeg);

            //	            ((MJPEGStream)sender).Stop();
            };

            ms.Start();
            System.Threading.Thread.Sleep(4000);
            ms.Stop();
            aw.Close();

            //
        }
Esempio n. 9
0
 /*private void btn_capVid_Click(object sender, EventArgs e)
 {
     j++;
     if (j % 2 == 0) this.btn_capVid.Image = ((System.Drawing.Image)(Properties.Resources.capVidIcon));
     else this.btn_capVid.Image = ((System.Drawing.Image)(Properties.Resources.capVidIconA));
 }*/
 private void mjpegStreamForm_FormClosing(object sender, EventArgs e)
 {
     videoSource.SignalToStop();
     videoSource.WaitForStop();
     videoSource.Stop();
     videoSource = null;
     this.Close();
 }
Esempio n. 10
0
        private void btnView_Click(object sender, EventArgs e)
        {
            stream = new MJPEGStream("http://"+conf[0].Address + "/videostream.cgi");
            stream.NewFrame += videoSource_NewFrame;
            stream.Login = conf[0].UserName;
            stream.Password = conf[0].Password;
            if (conf.Count > 1)
            {
                stream2 = new MJPEGStream("http://" + conf[1].Address + "/videostream.cgi");
                //stream2.NewFrame += videoSource_NewFrame;
                stream2.Login = conf[1].UserName;
                stream2.Password = conf[1].Password;

                videoSourcePlayer2.VideoSource = stream2;
            }
            if (conf.Count > 2)
            {
                stream3 = new MJPEGStream("http://" + conf[2].Address + "/videostream.cgi");
                //stream2.NewFrame += videoSource_NewFrame;
                stream3.Login = conf[2].UserName;
                stream3.Password = conf[2].Password;

                videoSourcePlayer3.VideoSource = stream3;
            }

            btnView.Enabled = false;
            btndesconect.Enabled = true;
            btnConfig.Enabled = false;
            btnRecoder.Enabled = true;

            // motionDetector = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionAreaHighlighting());

            videoSourcePlayer1.VideoSource = stream;

            stream.Start();
            stream2.Start();

            Text = "[Conectado] IPCam";
        }
        // Open MJPEG URL
        private void openMJPEGURLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            URLForm form = new URLForm();

            form.Description = "Enter URL of an MJPEG video stream:";

            form.URLs = new string[]

                {//predef form

                    "http://10.7.6.19/axis-cgi/mjpg/video.cgi?resolution=640x480",

                    "http://10.xx.yy.zz/axis-cgi/mjpg/video.cgi?resolution=640x480",
                    "http://wc2.dartmouth.edu/axis-cgi/mjpg/video.cgi?resolution=640x480",

                };

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                // create video source
                MJPEGStream mjpegSource = new MJPEGStream(form.URL);
                // open it
                OpenVideoSource(mjpegSource);
            }
        }
Esempio n. 12
0
        private void mjpegToolStripMenuItem_Click(object sender, EventArgs e)
        {
            URLForm form = new URLForm();
            form.Description = "Enter URL of an updating JPEG from a web camera";

            //Load recent URLs
            String[] urls = new String[recentURLs.Count];
            recentURLs.CopyTo(urls, 0);
            form.URLs = urls;

            form.StartPosition = FormStartPosition.CenterScreen;
            if (form.ShowDialog(this) == DialogResult.OK)
            {
                //remove existing item (so it will be placed at top of list)
                if (recentURLs.Contains(form.URL))
                {
                    recentURLs.Remove(form.URL);
                }
                //update recent URLs
                if (recentURLs.Count == RECENT_URL_LIMIT)
                {
                    recentURLs.RemoveAt(RECENT_URL_LIMIT - 1);
                }
                recentURLs.Add(form.URL);

                //open the stream
                String sourceName = showGetSourceNameBox();
                if (sourceName != null) //user didn't select cancel
                {
                    MJPEGStream s = new MJPEGStream();
                    s.Source = form.URL;
                    Log.info(String.Format("Video source: {0}", s.Source));
                    VideoSource v = new VideoSource(sourceName, s);
                    sources.Add(v);
                    v.RemoveSelected += new VideoSource.RemoveEventHandler(r_RemoveSelected);
                    v.setViewerGlobalStickey(showAllToolStripMenuItem.Checked);
                    globalOptions.updateViewer(v);
                    v.startCamera(); //start camera by default
                }
            }
        }
Esempio n. 13
0
 public Camera(MJPEGStream source, MotionDetector detector, string _name)
 {
     ipCamera = true;
     cameraName = _name;
     pubFrame = null;
     this.videoSource = source;
     this.motionDetecotor = detector;
     videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
 }
        private void button2_Click(object sender, EventArgs e)
        {
            /*
            FilterInfoCollection CamCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            VideoCaptureDevice stream = new VideoCaptureDevice(CamCollection[0].MonikerString);
            */

            MJPEGStream stream = new MJPEGStream("http://192.168.0.16:8080/videofeed");
               stream.Login = "******";
               stream.Password = "******";

            mov2 = false;
            mov = true;

            framesProcessing.fWidth = 640*2;
            framesProcessing.fHeight = 720;

            //Bitmap plate = new Bitmap("C:\\Users\\User\\Desktop\\tesis\\placa4.png");
            //getPlateLetters(plate);
            //persistDBLog("KFM276", "A-3");
            //Bitmap a = new Bitmap(@"placa1.jpg");
            //pictureBox3.Image = a;

            //pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
            //catchPlate(a);

            //Set Timer <-----------------

            timer1.Tick += new EventHandler(timer_tick);
            timer1.Interval = 1000; //miliseconds
            timer1.Start();

            cont = 0;
            asyncSource = new AsyncVideoSource(stream);

            // set NewFrame event handler
            asyncSource.NewFrame += new NewFrameEventHandler(video_NewFrame);

            // start the video source
            asyncSource.Start();
        }
        /**
         * Live control execution
         */
        #region Live control

        /// <summary>
        /// Start streamming video
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Streaming_Trigger(object sender, RoutedEventArgs e)
        {
            if (!CheckConfig())
            {
                MessageBox.Show("Configuration is required to perform this task.", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (viewCam.VideoSource == null)
            {
                // get new source from IP
                string cameraUrl = "http://" + Configuration.CameraIp + ":" + Configuration.CameraPort + "/videostream.cgi";
                //string cameraUrl = "http://192.168.2.100:80/videostream.cgi";
                MJPEGStream source = new MJPEGStream(cameraUrl) 
                    {
                        Login = Configuration.Login,
                        Password = Configuration.Password
                    };

                OpenVideoSource(new VideoCaptureDevice(LocalVideoDevices[0].MonikerString));
                //OpenVideoSource(source);
                hostCam.Visibility = Visibility.Visible;
                imgSplash.Visibility = Visibility.Collapsed;
            }
            else
            {
                if (rdModeObjTracking.IsChecked == true)
                {
                    rdModeObjTracking.IsChecked = false;
                }
                
                CloseCurrentVideoSource();
                hostCam.Visibility = Visibility.Collapsed;
                imgSplash.Visibility = Visibility.Visible;
            }
        }
Esempio n. 16
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO get cams from DB
            pb = new PictureBox[2];
            cams = new Edge.IPCameras.IPCamera[2];
            streams = new MJPEGStream[2];
            detectors = new MotionDetector[2];

            // TODO determine width/height based on number of cams
            int width = 480, height = 360;

            // Reset filters with determined width/height
            filter = new ResizeNearestNeighbor(width, height);

            // Add picturebox for each cam
            pb[0] = new PictureBox() { Width = width, Height = height, ImageLocation = "Images/testbeeld.png" };
            flowLayoutPanel1.Controls.Add(pb[0]);
            pb[1] = new PictureBox() { Width = width, Height = height, ImageLocation = "Images/testbeeld.png" };
            flowLayoutPanel1.Controls.Add(pb[1]);

            // Add cams to array
            cams[0] = new Edge.IPCameras.Foscam()
            {
                Description = "Woonkamer",
                Host = "10.30.59.81",
                Port = 8081,
                Username = "******",
                Password = "******",
            };
            cams[1] = new Edge.IPCameras.Foscam()
            {
                Description = "Buiten",
                Host = "10.30.59.82",
                Port = 8082,
                Username = "******",
                Password = "******",
            };

            // Setup motion detection
            for (int i = 0; i < cams.Count(); i++)
            {
                detectors[i] = new MotionDetector(
                                   new SimpleBackgroundModelingDetector(),
                                   new BlobCountingObjectsProcessing());
            }

            // Start streaming
            for (int i = 0; i < cams.Count(); i++)
            {
                streams[i] = new MJPEGStream(cams[i].MJPEGStreamURL);
                streams[i].NewFrame += new NewFrameEventHandler(Form1_NewFrame);
                streams[i].Start();
            }
        }
Esempio n. 17
0
 private void button1_Click(object sender, EventArgs e)
 {
     videoSource.SignalToStop();
     videoSource.WaitForStop();
     videoSource.Stop();
     videoSource = null;
     this.Close();
 }
Esempio n. 18
0
        private void button1_Click(object sender, EventArgs e)
        {
            string res="8";

            if (conf.HighResolution)
            {
                res = "32";
            }
            else
            {
                res = "8";
            }

            stream = new MJPEGStream(conf.Address+"/image?speed=0");
            stream.NewFrame += videoSource_NewFrame;
            a = new AVIWriter("wmv3");
            a.FrameRate = 20;
            a.Open("c:\\test.avi", 736, 480);
            stream.Login = conf.UserName;
            stream.Password = conf.Password;
            button1.Enabled = false;
            button2.Enabled = true;

            //motionDetector = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionAreaHighlighting());

            videoSourcePlayer1.VideoSource = stream;
            stream.Start();
            Text = "[Conectado] IPCam";
        }
Esempio n. 19
0
        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;
        }
Esempio n. 20
0
        // Open MJPEG URL
        private void openMJPEGURLToolStripMenuItem_Click( object sender, EventArgs e )
        {
            MJPEGStream mjpegSource = new MJPEGStream( "http://10.14.50.11/?action=stream" );

            // open it
            OpenVideoSource( mjpegSource );
        }
Esempio n. 21
0
 private void button5_Click(object sender, EventArgs e)
 {
     if(button5.Text=="连接")
     {
         button5.Text = "断开连接";
         textBox1.Enabled = false;
         textBox2.Enabled = false;
         textBox4.Enabled = false;
         button1.Enabled = true;
         button2.Enabled = true;
         button4.Enabled = true;
         button3.Enabled = true;
         button6.Enabled = true;
         ip = IPAddress.Parse(textBox1.Text);
         try
         {
             clientSocket.Connect(ip,int.Parse(textBox4.Text));
         }
         catch { }
         url = "http://" + textBox1.Text + ":"+textBox2.Text + "/";
         MJPEGStream mjpegSource = new MJPEGStream(url + "?action=stream");
         OpenVideoSource(mjpegSource);
     }
     else
     {
         button5.Text = "连接";
         textBox1.Enabled = true;
         textBox2.Enabled = true;
         textBox4.Enabled = true;
         videoSourcePlayer.Stop();
         button1.Enabled = false;
         button2.Enabled = false;
         button4.Enabled = false;
         button3.Enabled = false;
         button6.Enabled = false;
     }
 }
 public override void Init()
 {
     if (stream != null)
     {
         throw new Exception("Stream Allready Initialized. Use RestartStream To Create A New One");
     }
     stream = new MJPEGStream(CameraURL);
     stream.NewFrame += stream_NewFrame;
     stream.Proxy = null;
     setSource();
     stream.Start();
     isRunning = true;
 }
Esempio n. 23
0
        // Open MJPEG URL
        private void openMJPEGURLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            URLForm form = new URLForm();

            form.Description = "Enter URL of an MJPEG video stream:";
            form.URLs = new string[]
                {
                    "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=3",
                    "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=4",
                };

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

                // open it
                OpenVideoSource(mjpegSource);
            }
        }
 public override void StopStream()
 {
     if (stream != null)
     {
         stream.SignalToStop();
         stream.WaitForStop();
         stream = null;
         isRunning = false;
     }
 }
Esempio n. 25
0
        private void OpenVideoStream()
        {
            string url = "http://localhost:8080/";

            Console.WriteLine ("Connecting to {0}", url);
            videoStream = new MJPEGStream (url);

            videoStream.NewFrame += (Object sender, NewFrameEventArgs eventArgs) => {
                if (videoFrame != null)
                    lock (videoFrame) {
                        videoFrame = new Bitmap (eventArgs.Frame);
                    }
                else
                    videoFrame = new Bitmap (eventArgs.Frame);

            };

            videoStream.Start ();
        }
Esempio n. 26
0
        private void OpenMJpegUrlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var form = new UrlForm();

            form.Description = "Enter URL of an MJPEG video stream:";
            form.Urls = new[]
                            {
                                "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=4",
                                "http://195.243.185.195/axis-cgi/mjpg/video.cgi?camera=3"
                            };

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