Solved

How do I stream jpeg data from an IP camera

Posted on 2008-10-09
8
1,702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

759 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