|
| 1 | +--- |
| 2 | +title: How to use the media connector (preview) |
| 3 | +description: How to use the media connector (preview) to perform tasks such as sending an image snapshot to the MQTT broker or saving a video stream to a local file system. |
| 4 | +author: dominicbetts |
| 5 | +ms.author: dobett |
| 6 | +ms.service: azure-iot-operations |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 10/07/2024 |
| 9 | + |
| 10 | +#CustomerIntent: As an industrial edge IT or operations user, I want to configure the media connector so that I can access snapshots and videos from a media source such as a IP video camera. |
| 11 | +--- |
| 12 | + |
| 13 | +# Configure the media connector (preview) |
| 14 | + |
| 15 | +In Azure IoT Operations, the media connector (preview) enables access to media from media sources such as edge-attached cameras. This article explains how to use the media connector to perform tasks such as sending an image snapshot to the MQTT broker or saving a video stream to a local file system. |
| 16 | + |
| 17 | +The media connector: |
| 18 | + |
| 19 | +- Uses _asset endpoints_ to access media sources. An asset endpoint defines a connection to a media source such as a camera. The asset endpoint configuration includes the URL of the media source, the type of media source, and any credentials needed to access the media source. |
| 20 | + |
| 21 | +- Uses _assets_ to represent media sources such as cameras. An asset defines the capabilities and properties of a media source such as a camera. |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +A deployed instance of Azure IoT Operations. If you don't already have an instance, see [Quickstart: Run Azure IoT Operations Preview in GitHub Codespaces with K3s](../get-started-end-to-end-sample/quickstart-deploy.md). |
| 26 | + |
| 27 | +## Deploy the media server |
| 28 | + |
| 29 | +If you're using the media connector to stream live video, you need to install your own media server. To deploy a sample media server to use with the media connector, run the following command: |
| 30 | + |
| 31 | +```console |
| 32 | +kubectl create namespace media-server --dry-run=client -o yaml | kubectl apply -f - & kubectl apply -f https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/refs/heads/main/samples/media-connector-invoke-test/media-server/media-server-deployment.yaml --validate=false & kubectl apply -f https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/refs/heads/main/samples/media-connector-invoke-test/media-server/media-server-service.yaml --validate=false & kubectl apply -f https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/refs/heads/main/samples/media-connector-invoke-test/media-server/media-server-service-public.yaml --validate=false |
| 33 | +``` |
| 34 | + |
| 35 | +## Use Bicep to configure the media connector (preview) |
| 36 | + |
| 37 | +You can use Bicep to define the asset endpoint and asset for a media source such as a camera. The following Bicep code shows how to define an asset endpoint and asset for a media source. The asset endpoint uses the anonymous authentication method to connect to the video stream: |
| 38 | + |
| 39 | +```bicep |
| 40 | +metadata description = 'Asset endpoint profile and asset for a media source' |
| 41 | +param resourceName string |
| 42 | +param targetAddress string |
| 43 | +param customLocationName string |
| 44 | +param assetName string |
| 45 | +param strDescription string |
| 46 | +param bolEnabled bool |
| 47 | +param datasetsName string |
| 48 | +param datasetsDataPoints array |
| 49 | +
|
| 50 | +/*****************************************************************************/ |
| 51 | +/* Existing AIO cluster */ |
| 52 | +/*****************************************************************************/ |
| 53 | +resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = { |
| 54 | + name: customLocationName |
| 55 | +} |
| 56 | +/*****************************************************************************/ |
| 57 | +/* Asset endpoint profile */ |
| 58 | +/*****************************************************************************/ |
| 59 | +resource assetEndpoint 'Microsoft.DeviceRegistry/assetEndpointProfiles@2024-11-01' = { |
| 60 | + name: resourceName |
| 61 | + location: resourceGroup().location |
| 62 | + extendedLocation: { |
| 63 | + type: 'CustomLocation' |
| 64 | + name: customLocation.id |
| 65 | + } |
| 66 | + properties: { |
| 67 | + targetAddress: targetAddress |
| 68 | + endpointProfileType: 'Media' |
| 69 | + authentication: { |
| 70 | + method: 'Anonymous' |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | +/*****************************************************************************/ |
| 75 | +/* Asset */ |
| 76 | +/*****************************************************************************/ |
| 77 | +resource asset 'Microsoft.DeviceRegistry/assets@2024-11-01' = { |
| 78 | + name: assetName |
| 79 | + location: resourceGroup().location |
| 80 | + extendedLocation: { |
| 81 | + type: 'CustomLocation' |
| 82 | + name: customLocation.id |
| 83 | + } |
| 84 | + properties: { |
| 85 | + displayName: assetName |
| 86 | + assetEndpointProfileRef: assetEndpoint.name |
| 87 | + description: strDescription |
| 88 | + enabled: bolEnabled |
| 89 | + datasets: [ |
| 90 | + { |
| 91 | + name: datasetsName |
| 92 | + dataPoints: datasetsDataPoints |
| 93 | + } |
| 94 | + ] |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +The following JSON snippet shows a set of parameter values to use: |
| 100 | + |
| 101 | +```json |
| 102 | +{ |
| 103 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", |
| 104 | + "contentVersion": "1.0.0.0", |
| 105 | + "parameters": { |
| 106 | + "resourceName": { |
| 107 | + "value": "aep-public-http-anonymous-1" |
| 108 | + }, |
| 109 | + "assetName": { |
| 110 | + "value": "asset-public-http-anonymous-1-snapshot-to-mqtt-autostart" |
| 111 | + }, |
| 112 | + "strDescription": { |
| 113 | + "value": "snapshot to mqtt (autostart)" |
| 114 | + }, |
| 115 | + "bolEnabled": { |
| 116 | + "value": true |
| 117 | + }, |
| 118 | + "targetAddress": { |
| 119 | + "value": "https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/refs/heads/main/samples/shared-multimedia/IntroducingAzureIoTOperations.mp4" |
| 120 | + }, |
| 121 | + "datasetsName": { |
| 122 | + "value": "snapshot-to-mqtt-autostart" |
| 123 | + }, |
| 124 | + "datasetsDataPoints": { |
| 125 | + "value": [ |
| 126 | + { |
| 127 | + "name": "snapshot-to-mqtt", |
| 128 | + "dataSource": "snapshot-to-mqtt", |
| 129 | + "dataPointConfiguration": "{\"taskType\":\"snapshot-to-mqtt\",\"autostart\":true,\"realtime\":true,\"loop\":true,\"format\":\"jpeg\",\"fps\":1}" |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +These parameters configure: |
| 138 | + |
| 139 | +- The asset endpoint to connect to a video stream at `https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/refs/heads/main/samples/shared-multimedia/IntroducingAzureIoTOperations.mp4`. |
| 140 | +- The asset to capture snapshots from the video stream and publish them to an MQTT topic. |
| 141 | + |
| 142 | +The default MQTT topic name that the connector publishes to is `<connector namespace>/data/<asset name>`. |
| 143 | + |
| 144 | +To apply the previous configuration, save the previous examples as files, and run the following command: |
| 145 | + |
| 146 | +```azurecli |
| 147 | +az deployment group create --resource-group <your resource group> --template-file aep-camera-anonymous.bicep --parameters snapshot-to-mqtt-autostart.json --parameters customLocationName=<your custom location> |
| 148 | +``` |
| 149 | + |
| 150 | +[!INCLUDE [discover-custom-location](../includes/discover-custom-location.md)] |
| 151 | + |
| 152 | +This asset configuration publishes snapshots from the video stream to an MQTT topic. To view the snapshots, you can subscribe to the MQTT topic. To learn more about how to subscribe to an MQTT topic in a nonproduction environment, see [Test connectivity to MQTT broker with MQTT clients](../manage-mqtt-broker/howto-test-connection.md). |
| 153 | + |
| 154 | +## Dataset configuration |
| 155 | + |
| 156 | +The `datasetsDataPoints` parameter specifies the action the media connector takes on the asset. The previous example configures the camera to capture snapshots to publish to an MQTT broker topic. A camera asset supports the following five task types: |
| 157 | + |
| 158 | +| Task type | Description | |
| 159 | +|-----------|-------------| |
| 160 | +| `snapshot-to-mqtt` | Capture snapshots from a camera and publishes them to an MQTT topic. | |
| 161 | +| `snapshot-to-fs` | Capture snapshots from a camera and saves them to the local file system. | |
| 162 | +| `clip-to-mqtt` | Capture video clips from a camera and publishes them to an MQTT topic. | |
| 163 | +| `clip-to-fs` | Capture video clips from a camera and saves them to the local file system. | |
| 164 | +| `stream-to-rtsp` | Sends a live video stream from a camera to a media server. | |
| 165 | + |
| 166 | +You can use the following settings to configure individual tasks: |
| 167 | + |
| 168 | +- `autostart`: Whether the task starts automatically when the asset starts. |
| 169 | +- `realtime`: Whether the task runs in real time. |
| 170 | +- `loop`: Whether the task runs continuously. |
| 171 | +- `format`: The format of the media file. |
| 172 | +- `fps`: The frames per second for the media file. |
| 173 | +- `audioEnabled`: Whether audio is enabled for the media file. |
| 174 | +- `duration`: The duration of the media file. |
| 175 | + |
| 176 | +The following YAML snippets show example dataset configurations for each task type. The `taskType` value determines the task type to configure: |
| 177 | + |
| 178 | +```yaml |
| 179 | +datasets: |
| 180 | + - name: dataset1 |
| 181 | + dataPoints: |
| 182 | + - name: snapshot-to-mqtt |
| 183 | + dataSource: snapshot-to-mqtt |
| 184 | + dataPointConfiguration: |- |
| 185 | + { |
| 186 | + "taskType": "snapshot-to-mqtt", |
| 187 | + "autostart": true, |
| 188 | + "realtime": true, |
| 189 | + "loop": true, |
| 190 | + "format": "jpeg", |
| 191 | + "fps": 1 |
| 192 | + } |
| 193 | +``` |
| 194 | +
|
| 195 | +```yaml |
| 196 | +datasets: |
| 197 | + - name: dataset1 |
| 198 | + dataPoints: |
| 199 | + - name: snapshot-to-fs |
| 200 | + dataSource: snapshot-to-fs |
| 201 | + dataPointConfiguration: |- |
| 202 | + { |
| 203 | + "taskType": "snapshot-to-fs", |
| 204 | + "autostart": false, |
| 205 | + "realtime": true, |
| 206 | + "loop": true, |
| 207 | + "format": "jpeg", |
| 208 | + "fps": 1 |
| 209 | + } |
| 210 | +``` |
| 211 | +
|
| 212 | +
|
| 213 | +```yaml |
| 214 | + datasets: |
| 215 | + - name: dataset1 |
| 216 | + dataPoints: |
| 217 | + - name: clip-to-mqtt |
| 218 | + dataSource: clip-to-mqtt |
| 219 | + dataPointConfiguration: |- |
| 220 | + { |
| 221 | + "taskType": "clip-to-mqtt", |
| 222 | + "format": "avi", |
| 223 | + "autostart": true, |
| 224 | + "realtime": true, |
| 225 | + "loop": true, |
| 226 | + "fps": 3, |
| 227 | + "audioEnabled": false, |
| 228 | + "duration": 3 |
| 229 | + } |
| 230 | +``` |
| 231 | +
|
| 232 | +```yaml |
| 233 | +datasets: |
| 234 | + - name: dataset1 |
| 235 | + dataPoints: |
| 236 | + - name: clip-to-fs |
| 237 | + dataSource: clip-to-fs |
| 238 | + dataPointConfiguration: |- |
| 239 | + { |
| 240 | + "taskType": "clip-to-fs", |
| 241 | + "format": "avi", |
| 242 | + "autostart": true, |
| 243 | + "realtime": true, |
| 244 | + "loop": true, |
| 245 | + "duration": 3 |
| 246 | + } |
| 247 | +``` |
| 248 | +
|
| 249 | +```yaml |
| 250 | +datasets: |
| 251 | + - name: dataset1 |
| 252 | + dataPoints: |
| 253 | + - name: stream-to-rtsp |
| 254 | + dataSource: stream-to-rtsp |
| 255 | + dataPointConfiguration: |- |
| 256 | + { |
| 257 | + "taskType": "stream-to-rtsp", |
| 258 | + "autostart": true, |
| 259 | + "realtime": true, |
| 260 | + "loop": true |
| 261 | + } |
| 262 | +``` |
| 263 | +
|
| 264 | +## Samples |
| 265 | +
|
| 266 | +For more examples that show how to configure and use the media connector, see the [Azure IoT Operations samples repository](https://github.com/Azure-Samples/explore-iot-operations/blob/main/samples/media-connector-invoke-test/README.md). |
0 commit comments