Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I stream jpeg data from an IP camera

Posted on 2008-10-09
8
Medium Priority
?
1,750 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
7 Comments
 
LVL 6

Accepted Solution

by:
alex_paven earned 1000 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
Reclaim your office - Try the MB 660 headset now!

High level of background noise often makes it difficult for employees to concentrate fully on their jobs – or to communicate clearly on calls. The MB 660 headset helps you create a disruption free workspace.  

 

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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well I am not sure whether i deserve anything (credit or points) for this article, since I have not written the source code but discovered the same while browsing the net. I only wish to help EE users save some money and probably help the environmen…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

877 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