I've used AForge library to make this little program, that shows live feed from a webcam into a PictureBox.
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideoDevice;
private void Form1_Load(object sender, EventArgs e)
{
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
try
{
foreach (FilterInfo VidCapDev in VideoCaptureDevices)
{
comboBox1.Items.Add(VidCapDev.Name);
comboBox1.SelectedIndex = 0;
}
FinalVideoDevice = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
FinalVideoDevice.NewFrame += new NewFrameEventHandler(FinalVideoDevice_NewFrame);
FinalVideoDevice.Start();
}
catch
{
MessageBox.Show("No camera found. Please connect your camera and click RESET.");
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void FinalVideoDevice_NewFrame(object sender, NewFrameEventArgs e)
{
try
{
pictureBox1.Image = (Bitmap)e.Frame.Clone();
}
catch { }
}
But I also need to get a stream from an IP camera. Any ideas what would be the best way to get it?
An IP camera can connect directly to your network or computer, and there are three ways to do so. The three ways listed below do not require a NVR. A NVR, or Network Video Recorder, is the device that IP cameras connect to.
Solved it with MJPEGStream from the same AForge.net :)
MJPEGStream stream = new MJPEGStream("http://192.168.2.5:8080/videofeed");
stream.NewFrame += new NewFrameEventHandler(video_NewFrame);
stream.Start();
IP cameras do not have specific media interfaces/APIs in Windows, they are just devices on LAN. Also there are hundreds and thousands of models and they don't share common access interfaces (even close).
So first of all, you have to be specific about the model of your interest.
Also some vendors provide additional "drivers" that expose IP cameras as multimedia devices, such as "DirectShow driver for IP camera". In most cases these are vendor specific and won't work with other cameras.
Next chance is that camera implements a well known streaming protocol, in which case some generic driver might work out fine as well.
Or, as long as you are C# guy, you can check HTTP/CGI API of the IP camera and implement streaming yourself in code, sending and receiving data over HTTP/TCP/UDP connection with the device.
I once worked with the directShow.net library. It gives you access to the most functions of DirectShow and one of them is Capturing. If you can use the ip webcam with DirectShow you can use it in your program as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With