Connect cameras to the cloud using a remote device adapter

cloud icon
Alternatively, check out topics under Create intelligent video applications on the edge.


Note

Azure Video Analyzer has been retired and is no longer available.

Azure Video Analyzer for Media is not affected by this retirement. It is now rebranded to Azure Video Indexer. Click here to read more.

Azure Video Analyzer service allows users to capture and record video from RTSP cameras that are connected to the cloud. This requires that such cameras must be accessible over the internet. In cases where this may not be permissible, the Video Analyzer edge module can instead be deployed to a lightweight edge device with internet connectivity. With the lightweight edge device on the same (private) network as the RTSP cameras, the edge module can now be set up as an adapter that enables the Video Analyzer service to connect to the remote devices (cameras). The edge module enables the edge device to act as a transparent gateway for video traffic between the RTSP cameras and the Video Analyzer service.

Connect cameras to the cloud with a remote device adapter

Pre-reading

Prerequisites

Overview

In order to connect a camera to the Video Analyzer service using a remote device adapter, you need to:

  1. Create an IoT device in the IoT Hub to represent the RTSP camera
  2. Create a device adapter on the Video Analyzer edge module to act as the transparent gateway for the above device
  3. Use the IoT device and the device adapter when creating a live pipeline in the Video Analyzer service to capture and record video from the camera

Create an IoT device

Create an IoT device to represent each RTSP camera that needs to be connected to the Video Analyzer service. In the Azure portal:

  1. Navigate to the IoT Hub
  2. Select the Devices pane under Device management
  3. Select +Add device
  4. Enter a Device ID using a unique string (Ex: building404-camera1)
  5. Authentication type can be left as Symmetric key
  6. All other properties can be left as default
  7. Select Save to create the IoT device
  8. Select the IoT device, and record the Primary key or Secondary key, as it will be needed below

Create a remote device adapter

To enable the Video Analyzer edge module to act as a transparent gateway for video between the camera and the Video Analyzer service, you must create a remote device adapter for each camera. Invoke the remoteDeviceAdapterSet direct method that requires the following values:

  • Device ID for the IoT device
  • Primary key for the IoT device
  • Camera's IP address

In the Azure portal:

  1. Navigate to the IoT Hub
  2. Select the IoT Edge pane under Device management
  3. Select the IoT Edge device (such as ava-sample-device) to which Video Analyzer edge module has been deployed
  4. Under modules, select the Video Analyzer edge module (such as avaedge)
  5. Select </> Direct Method
  6. Enter remoteDeviceAdapterSet for the Method Name
  7. Enter the following for Payload:
 {
   "@apiVersion" : "1.1",
   "name": "<name of remote device adapter such as remoteDeviceAdapterCamera1>",
   "properties": {
     "target": {
       "host": "<Camera's IP address>"
      },
     "iotHubDeviceConnection": {
      "deviceId": "<IoT Hub Device ID>",
      "credentials": {
        "@type": "#Microsoft.VideoAnalyzer.SymmetricKeyCredentials",
        "key": "<Primary or Secondary Key>"
       }
     }
   }
 }
 

If successful, you will receive a response with a status code 201.

To list all of the remote device adapters that are set, invoke the remoteDeviceAdapterList direct method with the following payload:

 {
   "@apiVersion" : "1.1"
 }

Create pipeline topology in the Video Analyzer service

When creating a cloud pipeline topology to ingest from a camera behind a firewall, tunneling must be enabled on the RTSP source node of the pipeline topology. See an example of such a pipeline topology.

The following values, based on the IoT device created in the previous instructions, are required to enable tunneling on the RTSP source node:

  • IoT Hub Name
  • IoT Hub Device ID
            {
                "@type": "#Microsoft.VideoAnalyzer.RtspSource",
                "name": "rtspSource",
                "transport": "tcp",
                "endpoint": {
                    "@type": "#Microsoft.VideoAnalyzer.UnsecuredEndpoint",
                    "url": "${rtspUrlParameter}",
                    "credentials": {
                        "@type": "#Microsoft.VideoAnalyzer.UsernamePasswordCredentials",
                        "username": "${rtspUsernameParameter}",
                        "password": "${rtspPasswordParameter}"
                    },
                    "tunnel": { 
                        "@type": "#Microsoft.VideoAnalyzer.SecureIotDeviceRemoteTunnel",
                        "iotHubName" : "<IoT Hub Name>",
                        "deviceId": "${ioTHubDeviceIdParameter}"
                    }
                }
            }

Ensure that:

  • Transport is set to tcp
  • Endpoint is set to UnsecuredEndpoint
  • Tunnel is set to SecureIotDeviceRemoteTunnel

This quickstart can be used a reference as it outlines the steps for creating a pipeline topology and live pipeline in Azure portal. Use the sample topology Live capture, record, and stream from RTSP camera behind firewall.

Create and activate a live pipeline

When creating the live pipeline, the RTSP URL, RTSP username, RTSP password, and IoT Hub Device ID must be defined. A sample payload is below.

   {
    "name": "record-from-building404-camera1",
    "properties": {
        "topologyName": "record-camera-behind-firewall",
        "description": "Capture, record and stream video from building404-camera1 via a remote device adapter",
        "bitrateKbps": 1500,
        "parameters": [
            {
                "name": "rtspUrlParameter",
                "value": "<RTSP URL for building404-camera1 such as rtsp://localhost:554/media/video>"
            },
            {
                "name": "rtspUsernameParameter",
                "value": "<User name for building404-camera1>"
            },
            {
                "name": "rtspPasswordParameter",
                "value": "<Password for building404-camera1>"
            },
            {
                "name": "ioTHubDeviceIdParameter",
                "value": "<IoT Hub Device ID such as building404-camera1>"
            },
            {
                "name": "videoName",
                "value": "video-from-building404-camera1"
            }
          ]
       }
   }

The RTSP URL IP address must be localhost. Ensure that thebitrateKbps value matches the maximum bitrate setting for the video from the RTSP camera.

After creating the live pipeline, the pipeline can be activated to start recording to the Video Analyzer video resource. The quickstart mentioned in the previous step also outlines how to activate a live pipeline in Azure portal.

Playback recorded video in the Azure portal

  1. After activating the live pipeline, the video resource will be available under the Video Analyzer account Videos pane in Azure portal. The status will indicate Is in use as pipeline is active and recording.
  2. Select the video resource that was defined in the live pipeline to view the video.

Screenshot of the live video captured by live pipeline in the cloud.

If you encounter errors while attempting to playback the video, follow the steps in this troubleshooting guide.

Note

Because the source of the video was a container simulating a camera feed, the time stamps in the video are related to when you activated the live pipeline and when you deactivated it.

To deactivate the pipeline, go to your Video Analyzer account, and select Live > Pipelines on the left panel. Select the pipeline and then select Deactivate in the pipeline grid to stop the recording.

Next steps

Now that a video exists in your Video Analyzer account, you can export a clip of this recorded video to MP4 format using this tutorial.