Connect to IP Cameras

You connect to an IP camera by creating the ipcam object. To create the object, you need the URL of the camera. If the camera requires authentication, you can supply a user name and password.

The URL must be for a Motion JPEG (mjpeg) HTTP or RTSP stream, so the URL must start with http. For information about finding the URL, see Tips for Finding the IP Camera URL.

Connect without User Authentication

  1. Create an object, cam, using only the URL of the IP camera.

    cam = ipcam('http://172.28.17.193/video.mjpeg')
    cam = 
    
    Display Summary for ipcam:
    
                 URL: 'http://172.28.17.193/video.mjpeg'
            Username: ''
            Password: ''
             Timeout: 10
                 

    It creates the object and connects it to the IP camera with the specified URL. This way of creating the object requires no user authentication, so the Username and Password properties are blank in the object display. A default Timeout of 10 is used if you do not specify the property when creating the object.

  2. After creating the object, you can preview the image and take snapshots from the camera. For more information, see Acquire Images from IP Cameras.

Connect with User Authentication

  1. Create an object, cam, using the URL of the IP camera, and the optional arguments for user authentication. Username is a character vector representing the user name for the IP camera, and must be the second argument. Password is a character vector representing the password for the IP camera, and must be the third argument.

    cam = ipcam('http://172.28.17.193/video.mjpeg', 'admin', 'myfoscam')
    cam = 
    
    Display Summary for ipcam:
    
                 URL: 'http://172.28.17.193/video.mjpeg'
            Username: 'admin'
            Password: '********'
             Timeout: 10
                 

    If the authentication is valid, it creates the object and connects it to the IP camera. The Password is shown as asterisks, for security reasons. If no password is entered, it shows a blank character vector.

  2. After creating the object you can preview the image and take snapshots from the camera. For more information, see Acquire Images from IP Cameras.

Tips for Finding the IP Camera URL

You need the URL of the camera to create the ipcam object. The URL must be for a Motion JPEG (mjpeg) HTTP or RTSP stream, so the URL must start with http.

The URL is made up of the IP address of the camera, followed by a resource designation, such as video.mjpeg or mjpg.cgi, as defined by the camera vendor. For example:

cam = ipcam('http://172.28.17.104/video/mjpg.cgi')

If you do not know the URL to use for the camera:

  • Try the camera utility or the camera web interface. Either may list the URL.

  • Search the Internet for your camera model.

  • You can use a browser, such as Mozilla® Firefox®. For example, in Firefox, go to your camera’s web interface. Right-click inside the browser and select View Image Information. The URL is listed.

  • MathWorks® technical support is unable to find the URL. Refer to the camera documentation, or call the vendor. Only the manufacturer can supply the camera URL.

If the URL is not working in MATLAB®, verify the URL that the camera is using by looking at it in a browser, as described in the last tip, or by looking at it in VLC media player (an open source cross-platform multimedia player).

The following table lists some popular IP camera models and their URLs. The URLS show the video file designations, and you can substitute the IP address of your camera in place of <IP address:port>.

VendorModel NumberHTTP MJPEG URL
FoscamFI9821W V2http://<IP address:port>/cgi-bin/CGIStream.cgi?cmd=GetMJStream
DlinkDCS-2132Lhttp://<IP address:port>/video1.mjpg
TrendnetTV-IP572WIhttp://<IP address:port>/video/mjpg.cgi
VivotekIB8168http://<IP address:port>/video.mjpg
Axis0519-004http://<IP address:port>/mjpg/video.mjpg
SonySNC-CH110http://<IP address:port>/mjpeg

Tips for Finding the Stream Codec for RTSP

To use an IP camera over RTSP, the stream codec must be Motion JPEG in order to be recognized in MATLAB. Use the VLC media player to check the codec type.

  1. Open VLC media player.

  2. In VLC, select Media > Open Network Stream.

  3. Select Tools > Codec to open the Current Media Information dialog box.

  4. On the Codec tab, check the Codec field to verify whether it is using Motion JPEG. The example shown here is using Motion JPEG.

  5. If your camera is not using Motion JPEG, use the camera’s web interface to change the codec to Motion JPEG.