

First are the cr lf cr lf bytes that separate the headers of a part from the body of part. On line 4 till 7 you can see the private fields. Here is the code:ģ: //Specs say that the body of each part and it's header are seperated by two crlf'sĤ: private byte _seperatorBytes = ( "rnrn") ĥ: private byte _headerbytes = new byte Ħ: private Regex _contRegex = new Regex( "Content-Length: (?+)rn", RegexOptions.Compiled | RegexOptions.IgnoreCase) ġ0: public MultiPartStream(Stream multipartStream)ġ2: _reader = new BinaryReader( new BufferedStream(multipartStream)) ġ5: private int GetPartLength( string headerSection)ġ7: Match m = _contRegex.Match(headerSection) ġ8: return int.Parse(m.Groups.Value) Ģ1: private bool SeperatorBytesExistsInArray( int position, byte array)Ģ4: for ( int i = position, j = 0 j NextPartAsync()Ħ7: string headerSection = ReadContentHeaderSection(_reader) Ħ8: // let's parse the header section for the content-lengthĦ9: int length = GetPartLength(headerSection) It has no notion of images, it is just an object oriented multi part stream. This class represents a MultiPartStream and has methods like NextPart() which returns the bytes that belong to the next part in the stream. The first class I have defined is a MultiPartStream class. Read exactly the amount of bytes specified in the header from the part’s body data. Read the length of the image from the header Luckily, my camera provides the length of each part in a Content-Length part header.

This means you would need to check constantly for the the boundary when you are reading the part’s body. Normally one would read the body of the httpstream till boundary, parse the headers, read the part data till boundary, and repeat this in a loop. The part data is seperated from the part headers by cr lf cr lf. Every header is separated by a carriage return character followed by a linefeed character.

When I ask a video stream from my camera it will repeat endlessly. You can see, the body the of the http response will contain: one or more partheaders –> part data –> boundary->nextpartheaders –>part data –> boundary and this repeats. According to the spec the http response will look something like this (it is just http multi part, only the parts are images): After reading this you realize it is quite simple! MJPEG over http is really an http multi part response where each part is an image. It is called a MJPEG (Motion JPEG) stream. For a video of 640 * 480 at 30 fps (my max rate ) we would use the url The only problem is, in which format do we get our response? Well after a bit of research and monitoring with fiddler I came to the conclusion that a lot of IP Camera’s use the same format. As you can see there are also parameters for resolution and the rate in which the camera sends us back images.

This tells me that there is a way to do one http request and get an imagestream back! This is really what we want.
#SECURITY IP CAMERA VIEWER PDF#
So browsing a little further in our developer pdf I came across the following api. The disadvantage is that we have to send and receive a lot of http requests and those will cause a lot of overhead. This method is really simple and it allows the client application to control the refresh rate. We could use this url to read images in a loop and display them to the user. With this information we can basically create a video stream. This means that when I browse to that url with an IP Camera in my network my browser will show me an image. This pdf tells me the different url’s and parameters to make a camera pan, and it tells me that the url to capture an snapshot is something like with optional parameters for an usename and password.
#SECURITY IP CAMERA VIEWER HOW TO#
I believe that the http api’s may differ per brand, but once you know how to get an image stream, they mostly work the same.Īfter a bit of searching on the internet, I came across the following foscam developer pdf. The camera I bought is a FOSCAM I8910W, although the brand is not that important. These are really cool camera’s, because they can be connected to an TCP/IP network and usually provide an http api to control the camera en read images from it. A little while ago I ran out of new gadgets, so I decided to buy an IP Camera. I think every geek will recognize this somewhat. Hello again! It is time for another blog post! This time I am not going to blog about something that I have learned on the job (although I did learn a lot that I could use doing my job), instead I am going to blog about a little hobby project I did.
