AForge.NET

Testimonials
Features
Samples
Tools
Documentation
License
Downloads
Sources
Discussions
Partners
Projects
Members
Donate

AForge.NET Framework
2.2.5 version is available!

Access to JPEG and MJPEG video streams

AForge.NET framework provides classes to access JPEG snapshots and MJPEG video stream over HTTP. This API is quite useful taking into account the fact, that most IP cameras support access to their video data through these simple protocols. Also usage of these classes is not only limited to IP cameras, since other sources may also provide JPEG snapshots and MJPEG video streams over HTTP.

JPEGStream class
This class represents the simplest way of getting access to continuously updating JPEG image over HTTP. Usually such updating JPEG images come from IP cameras, but any URL may be used to download image from there in loop. If the given URL points to static JPEG, the class will not be so useful. But once the URL points to CGI script (or any other server side application), the class will download updating JPEG images from there.

As an example, below code shows how to get video data (in form of consequent JPEG updates) from Axis cameras (see Axis documentation for their HTTP API):

// create JPEG video source
JPEGStream stream = new JPEGStream(
        "http://<axis_camera_ip>/axis-cgi/jpg/image.cgi" );
// 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
}

MJPEGStream class
The class has similar idea as the above one, but provides access not to JPEG images over HTTP, but to MJPEG video streams - streams, which are made of multiple JPEG images joint in sequence. Such type of video streams are usually provided by IP cameras, however may be also provided by other services, which broadcast video to network using the simple protocol.

The below sample code also demonstrates accessing Axis camera, but now its MJPEG video stream:

// create MJPEG video source
MJPEGStream stream = new MJPEGStream(
        "http://<axis_camera_ip>/axis-cgi/mjpg/video.cgi" );
// set event handlers
stream.NewFrame += new NewFrameEventHandler( video_NewFrame );
// start the video source
stream.Start( );
// ...
// signal to stop
stream.SignalToStop( );