locked
ip camera RRS feed

  • Question

  • Imports System.Net
    Imports System.IO

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim sourceURL As String = "http://208.42.203.54:8588"
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create(sourceURL), HttpWebRequest)
            Dim resp As WebResponse = req.GetResponse()

            Dim buffer As Byte() = New Byte(DirectCast(resp, HttpWebResponse).ContentLength - 1) {}
            Dim read As Integer, total As Integer = 0
            '   Dim req As HttpWebRequest = DirectCast(WebRequest.Create(sourceURL), HttpWebRequest)
            req.Credentials = New NetworkCredential("admin", "admin")

            Dim stream As IO.Stream = resp.GetResponseStream()
            While (read = stream.Read(buffer, total, DirectCast(resp, HttpWebResponse).ContentLength - 1)) <> 0
                total += read
            End While
            Dim bmp As Bitmap = DirectCast(Bitmap.FromStream(New MemoryStream(buffer, 0, total)), Bitmap)
            PictureBox1.Image = bmp


        End Sub
    End Class

    i tried this code to get preview of camera but there is error ( Dim bmp As Bitmap = DirectCast(Bitmap.FromStream(New MemoryStream(buffer, 0, total)), Bitmap) Parameter is not valid. 

    • Moved by Kristin Xie Wednesday, March 11, 2015 5:17 AM this issue related to VB language
    Tuesday, March 10, 2015 9:42 AM

Answers

All replies

  • Does it work after this simplification?

       
        Dim resp As WebResponse = req.GetResponse()
        PictureBox1.Image = Bitmap.FromStream(resp.GetResponseStream())

    Tuesday, March 10, 2015 9:51 AM
  • Still same error (parameter is not valid)
    Tuesday, March 10, 2015 1:04 PM
  • Then maybe it does not return an image. What happen if you access the same address from browser?

    Tuesday, March 10, 2015 1:09 PM
  •  its displaying camera view. is it not working because its public static ip?
    Tuesday, March 10, 2015 1:11 PM
  • Imports System.Net
    Imports System.IO

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim sourceURL As String = "http://208.42.203.54:8588"
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create(sourceURL), HttpWebRequest)
            Dim resp As WebResponse = req.GetResponse()

            Dim buffer As Byte() = New Byte(DirectCast(resp, HttpWebResponse).ContentLength - 1) {}
            Dim read As Integer, total As Integer = 0
            '   Dim req As HttpWebRequest = DirectCast(WebRequest.Create(sourceURL), HttpWebRequest)
            req.Credentials = New NetworkCredential("admin", "admin")

            Dim stream As IO.Stream = resp.GetResponseStream()
            While (read = stream.Read(buffer, total, DirectCast(resp, HttpWebResponse).ContentLength - 1)) <> 0
                total += read
            End While
            Dim bmp As Bitmap = DirectCast(Bitmap.FromStream(New MemoryStream(buffer, 0, total)), Bitmap)
            PictureBox1.Image = bmp


        End Sub
    End Class

    i tried this code to get preview of camera but there is error ( Dim bmp As Bitmap = DirectCast(Bitmap.FromStream(New MemoryStream(buffer, 0, total)), Bitmap) Parameter is not valid. 

    I would guess the issue is that the camera is streaming video also and not just sending a single image of some type therefore I don't believe you could save a stream from the site as a Bitmap. After all a Bitmap has a certain format as do the streams listed in the image below which can apparently be received from the website. Although my IE can not receive them probably due to not having appropriate codecs for doing so or proper plugin like Apple Quicktime on my system I'm guessing.


    La vida loca

    • Edited by Mr. Monkeyboy Wednesday, March 11, 2015 6:00 AM
    • Proposed as answer by IronRazerz Wednesday, March 11, 2015 10:34 AM
    Wednesday, March 11, 2015 5:56 AM
  • My browser, according to this link Microsoft - Video Format Support - for IE, was supporting H.264 video even though at the link you provided "http://208.42.203.54:8588" I was unable to view the H.264 selection.

    I also went to this link WebM Media Foundation Components for Microsoft Internet Explorer and then went to the download page for WebM and downloaded WebM for IE 9+. Then immediately IE could view the WebM (HTML5 video) which it was unable to do previously as can be seen in the image below.

    I found these links however which may be of interest to you.

    MPEG-4 Support in Media Foundation

    H.264 Video Decoder

    I suspect the WebBrowser control could display video stream now, since it takes on the properties of IE, but have not tested it with the Video Format Support link above.

    Have you ever seen one of the streams from the site you reference in a browser? All that happens when I access the site is a popup wanting me to install Apple Quicktime and a note that maybe there are too many browsers accessing the website for my browser to get access to any of the streams available.


    La vida loca

    Wednesday, March 11, 2015 6:28 AM
  • My first guess would be as Mr. Monkeyboy mentioned, that it is a Video stream, not an Image stream.

    If you say it can`t be done then i`ll try it

    Wednesday, March 11, 2015 10:40 AM
  • I just looked at the window provided when Help is selected on the Website for the link you provided. There is a Snapshot function but that requires a button to be selected in order to create a Snapshot from the video stream. But if you read what Snapshot does it displays a new window of an image which can be right click on to download/save the image.

    Also this requires Setup to be used which itself requires an adminstrators user name and password to do that. Which perhaps you have. But that is not "admin" "admin" as you display in your code as I tried using that with Setup when it asked for a user name and password but it didn't work.

    Regardless you would be required to access Setup so that you could use Snapshot. And then if a Snapshot is performed you would need to get the URL of the displayed Image if that was available somewhere (like in the source code of the window displaying the image) and then download that image which that part you could use a WebClient to save the image to a file or I suppose maybe create a memory stream of the image and provide it to a PictureBox as an image from a memory stream.

    However what your code does now is as far as I know does not do anything even close to what needs to be done in order to do all of that.

    Plus your code gets the entire web response which would be the displayed webpage first and I suppose if video was streaming on the page then it would constantly be reading that also and tries to convert all that to a Bitmap. You can't convert a Webpage to a bitmap since it's HTML code and you can't convert a constant video stream to a bitmap if one was being received since it is not a bitmap format.

    It is possible if your code was receiving a video stream and for that video stream type (MJPeg, MPeg-4, H.264) if you knew the byte format of that video stream format that perhaps you could capture a Frame I suppose from the video streams bytes and convert that to a bitmap if you knew how to perform the conversion.

    But IE on my system, whenever I access that link, never displays any video stream for any stream type selected from the dropdown menu even though I know now that my IE can display H.264 streams.

    _______________________________________________________________________

    Live View
    Live View is the default page that opens when accessing the AXIS M1011-W Network Camera. Live video is displayed directly in the browser window.
    Stream profile
    To quickly switch between pre-defined or created stream profiles, select the profile from the drop-down list.

    The stream profile only changes on the Live View page - the default stream profile, as set on the Setup > Live View Config > Layout page is not affected.
    Event Trigger Buttons
    When selected as the Trigger type in the event type configuration, these buttons can be used to manually start and stop the event.
    Note that these buttons are only displayed if this is enabled in Setup > Live View Config > Layout.
    Snapshot
    Clicking this button opens a new window showing a snapshot image from the video stream. Right-click on the image to save it as a JPEG.

    This button is mainly intended for use with browsers other than Microsoft Internet Explorer, or when otherwise not using ActiveX to view the video stream.  The ActiveX viewing component for Microsoft Internet Explorer (AXIS Media Control) provides its own snapshot button (see below.)
    Note that this button is not displayed by default - it must first be enabled in Setup > Live View Config > Layout.
    Setup
    This link displays the setup tools. An operator will be able to access all the tools not included in System Options, which are only available to administrators.

    The page that opens when clicking on this link can be set to an alternative configuration page, called Plain Config. This is a simple web page that provides direct access to all of the parameters in the AXIS M1011-W Network Camera. This should only be used by advanced users.

    To use the Plain Config page as the default configuration page, open the page from Setup > System Options > Advanced > Plain Config and then check the box provided at the top of the page.
    The Viewer Toolbar
    The Viewer Toolbar is displayed immediately below the video stream and provides various buttons and controls for performing common tasks. There are several different viewers available, the one to use is selected and enabled from Setup > Live View Config > Layout.

    The buttons shown below are for the AMC toolbar, which is configured from the AXIS Media Control Applet. This can be accessed from the Windows Control Panel, or it can be started directly by right-clicking in the image and clicking Settings in the menu that appears.

    The Play/Stop button toggles start/stop of the live video stream.

    Clicking the Snapshot button saves a JPEG snapshot of the image currently being displayed in the video stream.  
    Note that the Snapshot function's behaviour and the target directory for saving snapshots can be configured from the AXIS Media Control applet, which is opened from the Windows Control Panel, or by right-clicking in the image and selecting Settings.
    Clicking the View Full Screen button causes the video image to fill the entire screen area. No other windows will be visible. Press the 'Esc' button on the computer keyboard to cancel full screen view.


    La vida loca

    Wednesday, March 11, 2015 4:02 PM
  • Thanx to all . it was helpful
    Wednesday, March 11, 2015 6:24 PM
  • Thanx to all . it was helpful

    I suppose. In the future I would recommend before writing a program for doing something like this that research should be used to determine what may need to be done in order to have a program perform what it needs to do.

    La vida loca

    Wednesday, March 11, 2015 8:25 PM