Solved

How do I stream jpeg data from an IP camera

Posted on 2008-10-09
8
1,655 Views
Last Modified: 2013-11-27
I'm trying to develop my own application to manipulate the video from an IP camera.  I can get the video data from this path:  

http://ip:port/cgi-bin/Stream?Video?UserName=user&PassWord=pass

And from the manufacture, I was given the following information to reconstruct the stream information:

The format of picture data transfer to Client as follow 
The first  20 BYTE is JPEG description by own defination.
It`s dedination as follow :
typedef struct{
    INT16U  Magic_Number;    // alway   \x2a\x2a
    INT32U  Jpg_Size;        // sizeof(jpg)
    INT16U  Width;
    INT16U  Height;
    INT8U   Qtable;
    INT8U   temp[9];
 } SVideoJpgHead;
The last 20 BYTE is real JPEG information . start as stand SOI
marker 0xFFD8 and end the JPEG fiel as  0xFFD9.

I use VB 2008 but I'm not sure how to do this. Can anyone help?

0
Comment
Question by:cer_petsafe
  • 4
  • 2
8 Comments
 
LVL 6

Accepted Solution

by:
alex_paven earned 250 total points
ID: 22684556
I don't think you really need that struct - since you're using .net it's a lot easier. My suggestion (and I've used this already, it works fine) is to get the source files from here; it's a very nice library that takes care of the low level stuff, and with a bit of tweaking you can get where you want. It's in C#, but that's not a problem: you can compile it into a separate dll and reference that. Or you can add the relevant project to your solution (doesn't matter that you're working in vb and the other project is in C#).

The article also contains heaps of general information; you can strip out what you don't need from the source files by the way, like the implementations for the different camera models. The generic stuff (videosource, mjpegsource) works fine on it's own, but of course you might need to tweak it a bit to suit your uses.

If you need any more help, ask away.
0
 

Author Comment

by:cer_petsafe
ID: 22687112
OK, I translated some of your code to VB and when I step through it, I get an error at req.GetResponse saying "The server committed a protocol violation. Section=ResponseStatusLine".

The code is attached.
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim sourceURL As String = "http://192.168.102.96/cgi-bin/Stream?Video?UserName=petsafe&PassWord=radiosys"

        Dim buffer(100000) As [Byte]

        Dim read As Integer = 0

        Dim total As Integer = 0

        Dim req As System.Net.HttpWebRequest = System.Net.WebRequest.Create(sourceURL)

        Dim resp As System.Net.WebResponse = req.GetResponse

        Dim aStream As System.IO.Stream = resp.GetResponseStream

        read = aStream.Read(buffer, total, 1000)

        While Not read = 0

            total = total + read

        End While

        Dim BMP As Bitmap = Bitmap.FromStream(New System.IO.MemoryStream(buffer, 0, total))
 

        PictureBox1.Image = BMP

    End Sub

Open in new window

0
 
LVL 6

Expert Comment

by:alex_paven
ID: 22687806
That never happened to me so I can't say for sure, but it looks like the camera doesn't obey some rules .net thinks it should. Are you sure it's set on MJpeg? Try sniffing the traffic with some tool (wireshark maybe?) and see what could be wrong. Sorry I can't be more helpful right now.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:cer_petsafe
ID: 23034709
Nothing seems to be working.  What I need is help with parsing the stream data into the "Bytes" as described in the above structure.  When I navigate to the "sourceURL" I get streaming data that fills my browser.  How do I access and parse this data in VB code?
0
 
LVL 6

Expert Comment

by:alex_paven
ID: 23040064
Wait, you're saying you see raw data in a browser? That really shouldn't be happening I think, whenever I tried it the browser displayed pictures - some browsers are smart enough to actually refresh the picture automatically whenever a new frame is available; what you'd need to do is take a chunk of the data you're receiving and search for the jpeg header: see here for details (basically the chunk between two headers should be one picture, and .net makes it dead easy to load it). And again, make sure the camera is set on MJpeg instead of other more exotic formats.
0
 
LVL 6

Expert Comment

by:alex_paven
ID: 23040101
Well, I took another look at the question and I noticed that the standard header information comes after the header defined in that struct; that must be why the browser doesn't know how to display the data: extra information that doesn't fit anywhere; what you'd need to do is search the stream for the magic number in that struct, than move forward the number of bytes the struct takes and only start loading data from the SOI. Or change the camera to a more standards-compliant one, if this is indeed the case.
0
 
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 250 total points
ID: 26598840
Hi,

I have posted a related question and in trouble finding a solution. can you guys have a look at it please ?
http://www.experts-exchange.com/Software/MultiMedia_Applications/Q_25149824.html

Any help would be highly appreciated.
Thanks
~Raj
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
It started not too long ago. It was at first annoying. My keystrokes seemed to be randomly generated, not the ones I typed on the keyboard. For some reason this only happened in certain applications (especially browsers such as IE11, Firefox and Chr…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now