locked
Stream Video from IP Camera with threading in asp.net RRS feed

  • Question

  • Dear All :

    Recent, I have writen the code about capture the live view from IP Camera and broadcast to outside by using asp.net

    The code like the following

    using

     

    System;

    using

     

    System.Collections;

    using

     

    System.Configuration;

    using

     

    System.Data;

    using

     

    System.Linq;

    using

     

    System.Web;

    using

     

    System.Web.Security;

    using

     

    System.Web.UI;

    using

     

    System.Web.UI.HtmlControls;

    using

     

    System.Web.UI.WebControls;

    using

     

    System.Web.UI.WebControls.WebParts;

    using

     

    System.Xml.Linq;

    using

     

    System.Net;

    using

     

    System.IO;

    using

     

    System.Drawing;

    using

     

    System.Drawing.Imaging;

    using

     

    System.Threading;

     

    protected void Button1_Click(object sender, EventArgs e)

    {

    req = (

    HttpWebRequest)WebRequest.Create(UrlLink);

    req.Credentials =

    new NetworkCredential(login, password);

    resp = req.GetResponse();

    stream = resp.GetResponseStream();

     

    while (read != 0)

    {

     

    // check total read

     

    if (total > bufSize - readSize)

    {

    total = 0;

    }

     

    // read next portion from stream

     

    if ((read = stream.Read(buffer, total, readSize)) == 0)

     

    break;

    total += read;

    bytesReceived += read;

    }

     

     

    Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total));

     

    MemoryStream result = new MemoryStream();

    bmp.Save(result,

    ImageFormat.Bmp);

    bmp.Dispose();

    bmp =

    null;

    Response.Clear();

    Response.ContentType =

    "image/jpeg";

     

    byte[] getBuffer = result.ToArray();

    Response.BinaryWrite(getBuffer);

    Response.End();

    }

    It's work and show the live view picture on the web. However, they cannot refresh picture interval. As I want to create threading to refresh the live view picture automatically.  Can anyone provide some example to me. So I have using threading method to refresh the picture on server side ?

    Thanks

    Michael Yip

     

     

     

     

    Wednesday, April 7, 2010 8:46 AM

All replies

  • Can you explain how to capture and record video from IP Camera (Panasonic) and my link is "http://192.168.1.253:2100/CgiStart?page=Single&Language=0" using asp.net c#.......[IE,Firefox,etc.]

    My emailid is : helptoasp@gmail.com

     

    And not getting what is while (read != 0) in the above code......

    Thanks in Advance...

    Friday, September 17, 2010 6:45 AM
  • Hi,

    Did u by chance figure out how to solve this issue?

    Friday, November 4, 2011 9:38 AM
  • Web server processes are general mean to be "done and forget" with a few exceptions (that's why there's need to use Session Key to store session data on other relatively persistant media). Therefore your "server thread" shouldn't run for a long time.

    And there's no way for the server-side to "push" the content to client without the use of plugins.

    If you want to refresh your image, you should consider using a javascript setTimeout() function to pull the updated images on intervals. As long as your "Last-Modified" header changes between request, the browsers should load the updated image.


    • Edited by cheong00 Monday, November 7, 2011 2:39 AM
    Monday, November 7, 2011 2:39 AM
  • read should be a variable that Micheal chosen to omit. I suspected him leaved the following line out after the GetResponseStream() call.

    int read = stream.Read(buffer, total, readSize);
    

    Of course, the other variables byte[] buffer, int total and constant int readSize etc. are also omitted.

    Monday, November 7, 2011 2:47 AM