教程:将基于事件的视频录制到云中并从云中播放Tutorial: Event-based video recording to the cloud and playback from the cloud

在本教程中,你将了解如何使用 Azure IoT Edge 上的 Azure 实时视频分析,选择性地将实时视频源的部分内容录制到云中的 Azure 媒体服务。In this tutorial, you'll learn how to use Azure Live Video Analytics on Azure IoT Edge to selectively record portions of a live video source to Azure Media Services in the cloud. 此用例在本教程中称为基于事件的视频录制 (EVR)。This use case is referred to as event-based video recording (EVR) in this tutorial. 要录制实时视频的部分内容,你将使用对象检测 AI 模型在视频中查找对象,并仅在检测到某种类型的对象时录制视频剪辑。To record portions of a live video, you'll use an object detection AI model to look for objects in the video and record video clips only when a certain type of object is detected. 你还将了解如何使用媒体服务播放录制的视频剪辑。You'll also learn about how to play back the recorded video clips by using Media Services. 对于需要保留所需视频剪辑的各种场景,此功能非常有用。This capability is useful for a variety of scenarios where there's a need to keep an archive of video clips of interest.

在本教程中,将:In this tutorial, you will:

  • 设置相关资源。Set up the relevant resources.
  • 检查执行 EVR 的代码。Examine the code that performs EVR.
  • 运行示例代码。Run the sample code.
  • 检查结果并查看视频。Examine the results, and view the video.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

建议的读前准备Suggested pre-reading

在开始之前,请阅读以下文章:Read these articles before you begin:

先决条件Prerequisites

本教程的先决条件如下:Prerequisites for this tutorial are:

完成这些步骤后,你将在 Azure 订阅中部署相关 Azure 资源:At the end of these steps, you'll have relevant Azure resources deployed in your Azure subscription:

  • Azure IoT 中心Azure IoT Hub
  • Azure 存储帐户Azure Storage account
  • Azure 媒体服务帐户Azure Media Services account
  • Azure 中的 Linux VM,已安装 IoT Edge 运行时Linux VM in Azure, with the IoT Edge runtime installed

概念Concepts

基于事件的视频录制是指由事件触发的视频录制过程。Event-based video recording refers to the process of recording video triggered by an event. 可以从以下内容生成该事件:That event could be generated from:

  • 视频信号本身的处理,例如在视频中检测到移动的对象时。Processing of the video signal itself, for example, upon detecting a moving object in the video.
  • 独立源,例如打开门。An independent source, for example, the opening of a door.

或者,可以仅在推理服务检测到特定事件发生时触发录制。Alternatively, you can trigger recording only when an inferencing service detects that a specific event has occurred. 本教程将使用在高速公路上移动的车辆的视频,并在检测到卡车时录制视频剪辑。In this tutorial, you'll use a video of vehicles moving on a freeway and record video clips whenever a truck is detected.

媒体图

该图以图画形式呈现了媒体图以及用于完成所需方案的其他模块。The diagram is a pictorial representation of a media graph and additional modules that accomplish the desired scenario. 共涉及四个 IoT Edge 模块:Four IoT Edge modules are involved:

  • IoT Edge 上的实时视频分析模块。Live Video Analytics on an IoT Edge module.
  • Edge 模块,它在 HTTP 终结点后面运行 AI 模型。An edge module running an AI model behind an HTTP endpoint. 此 AI 模块使用 YOLO v3 模型,该模型能够检测许多类型的对象。This AI module uses the YOLO v3 model, which can detect many types of objects.
  • 一个用于筛选对象并对其进行计数的自定义模块,该模块在图中称为对象计数器。A custom module to count and filter objects, which is referred to as an Object Counter in the diagram. 在本教程中,你将生成一个对象计数器并对其进行部署。You'll build an Object Counter and deploy it in this tutorial.
  • RTSP 模拟器模块用于模拟 RTSP 摄像机。An RTSP simulator module to simulate an RTSP camera.

如图所示,你将使用媒体图中的 RTSP 源节点捕获模拟的实时视频(高速公路上的交通流视频),并将该视频发送到两条路径:As the diagram shows, you'll use an RTSP source node in the media graph to capture the simulated live video of traffic on a highway and send that video to two paths:

  • 第一条路径的目的地是帧速率筛选处理器节点,该节点以指定(降低的)帧速率输出视频帧。The first path is to a frame rate filter processor node that outputs video frames at the specified (reduced) frame rate. 这些视频帧将发送到 HTTP 扩展节点。Those video frames are sent to an HTTP extension node. 然后,该节点将这些帧作为图像转发到 AI 模块 YOLO v3(一个对象检测器)。The node then relays the frames, as images, to the AI module YOLO v3, which is an object detector. 该节点接收结果,这些结果是模型检测到的对象(交通流中的车辆)。The node receives the results, which are the objects (vehicles in traffic) detected by the model. 然后,HTTP 扩展节点会通过 IoT 中心消息接收器节点向 IoT Edge 中心发布结果。The HTTP extension node then publishes the results via the IoT Hub message sink node to the IoT Edge hub.
  • 设置了 objectCounter 模块,目的是从 IoT Edge 中心接收消息,其中包括对象检测结果(交通流中的车辆)。The objectCounter module is set up to receive messages from the IoT Edge hub, which include the object detection results (vehicles in traffic). 该模块将检查这些消息,并查找通过设置进行配置的特定类型的对象。The module checks these messages and looks for objects of a certain type, which were configured via a setting. 当找到此类对象时,此模块将向 IoT Edge 中心发送消息。When such an object is found, this module sends a message to the IoT Edge hub. 然后系统将这些“找到对象”消息路由到媒体图的 IoT 中心源节点。Those "object found" messages are then routed to the IoT Hub source node of the media graph. 接收到此类消息后,媒体图中的 IoT 中心源节点会触发信号入口处理器节点。Upon receiving such a message, the IoT Hub source node in the media graph triggers the signal gate processor node. 然后,信号入口处理器节点会在配置的时间内处于开启状态。The signal gate processor node then opens for a configured amount of time. 在此持续时间内,视频流会经过入口到达资产接收器节点。Video flows through the gate to the asset sink node for that duration. 然后,实时流的这一部分将通过资产接收器节点被记录到 Azure 媒体服务帐户中的资产内。That portion of the live stream is then recorded via the asset sink node to an asset in your Azure Media Services account.

设置开发环境Set up your development environment

在开始之前,请检查是否满足先决条件中的第三条。Before you begin, check that you completed the third bullet in Prerequisites. 资源设置脚本完成后,选择大括号,公开文件夹结构。After the resource setup script finishes, select the curly brackets to expose the folder structure. 你将看到一些创建的文件。You'll see a few files created.

应用设置

本教程中涉及以下文件:Of interest in this tutorial are the files:

  • edge-deployment/.env:包含 Visual Studio Code 用来将模块部署到边缘设备的属性。edge-deployment/.env: Contains properties that Visual Studio Code uses to deploy modules to an edge device.
  • appsetting.json:由 Visual Studio Code 用于运行示例代码。appsetting.json: Used by Visual Studio Code for running the sample code.

以下步骤将需要这些文件。You'll need the files for these steps.

  1. 从 GitHub 链接 https://github.com/Azure-Samples/live-video-analytics-iot-edge-csharp 克隆存储库。Clone the repo from the GitHub link https://github.com/Azure-Samples/live-video-analytics-iot-edge-csharp.

  2. 启动 Visual Studio Code,然后打开将存储库下载到的文件夹。Start Visual Studio Code, and open the folder where you downloaded the repo.

  3. 在 Visual Studio Code 中,浏览到 src/cloud-to-device-console-app 文件夹,然后创建一个名为 appsettings.json 的文件。In Visual Studio Code, browse to the src/cloud-to-device-console-app folder and create a file named appsettings.json. 该文件包含运行程序所需的设置。This file contains the settings needed to run the program.

  4. 从 appsettings.json 文件复制内容。Copy the contents from the appsettings.json file. 文本应如下所示:The text should look like:

    {  
        "IoThubConnectionString" : "HostName=xxx.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=XXX",  
        "deviceId" : "lva-sample-device",  
        "moduleId" : "lvaEdge"  
    }
    

    借助 IoT 中心连接字符串,可以使用 Visual Studio Code 通过 Azure IoT 中心将命令发送到 Edge 模块。The IoT Hub connection string lets you use Visual Studio Code to send commands to the edge modules via Azure IoT Hub.

  5. 接下来,浏览到 src/edge 文件夹并创建一个名为 .env 的文件。Next, browse to the src/edge folder and create a file named .env.

  6. 从 ~.env 文件复制内容。Copy the contents from ~.env file. 文本应如下所示:The text should look like:

    SUBSCRIPTION_ID="<Subscription ID>"  
    RESOURCE_GROUP="<Resource Group>"  
    AMS_ACCOUNT="<AMS Account ID>"  
    IOTHUB_CONNECTION_STRING="HostName=xxx.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx"  
    AAD_TENANT_ID="<AAD Tenant ID>"  
    AAD_SERVICE_PRINCIPAL_ID="<AAD SERVICE_PRINCIPAL ID>"  
    AAD_SERVICE_PRINCIPAL_SECRET="<AAD SERVICE_PRINCIPAL ID>"  
    INPUT_VIDEO_FOLDER_ON_DEVICE="/home/lvaadmin/samples/input"  
    OUTPUT_VIDEO_FOLDER_ON_DEVICE="/home/lvaadmin/samples/output"  
    APPDATA_FOLDER_ON_DEVICE="/var/local/mediaservices"
    CONTAINER_REGISTRY_USERNAME_myacr="<your container registry username>"  
    CONTAINER_REGISTRY_PASSWORD_myacr="<your container registry username>"      
    

检查模板文件Examine the template file

在上一步中,你启动了 Visual Studio Code 并打开了包含示例代码的文件夹。In the previous step, you started Visual Studio Code and opened the folder that contains the sample code.

在 Visual Studio Code 中,浏览到 src/edge。In Visual Studio Code, browse to src/edge. 你将看到创建的 .env 文件以及一些部署模板文件。You'll see the .env file that you created and a few deployment template files. 该模板定义了要部署到边缘设备 (Azure Linux VM) 的边缘模块。This template defines which edge modules you'll deploy to the edge device (the Azure Linux VM). .env 文件包含这些模板中所用变量的值,例如媒体服务凭据。The .env file contains values for the variables used in these templates, such as the Media Services credentials.

打开 src/edge/deployment.objectCounter.template.json。Open src/edge/deployment.objectCounter.template.json. “模块”部分下有四个条目,对应于上面“概念”部分中列出的项目:There are four entries under the modules section that correspond to the items listed in the previous "Concepts" section:

  • lvaEdge:这是 IoT Edge 上的实时视频分析模块。lvaEdge: This is the Live Video Analytics on IoT Edge module.
  • yolov3:这是使用 YOLO v3 模型构建的 AI 模块。yolov3: This is the AI module built by using the YOLO v3 model.
  • rtspsim:这是 RTSP 模拟器。rtspsim: This is the RTSP simulator.
  • objectCounter:这是在来自 yolov3 的结果中查找特定对象的模块。objectCounter: This is the module that looks for specific objects in the results from yolov3.

对于 objectCounter 模块,请参阅用于“image”值的字符串 (${MODULES.objectCounter})。For the objectCounter module, see the string (${MODULES.objectCounter}) used for the "image" value. 其基础是有关开发 IoT Edge 模块的教程This is based on the tutorial on developing an IoT Edge module. Visual Studio Code 将自动发现 objectCounter 模块的代码位于 src/edge/modules/objectCounter 下。Visual Studio Code automatically recognizes that the code for the objectCounter module is under src/edge/modules/objectCounter.

阅读本部分,了解如何在 IoT Edge 部署清单中声明路由。Read this section on how to declare routes in the IoT Edge deployment manifest. 然后检查模板 JSON 文件中的路由。Then examine the routes in the template JSON file. 请注意:Note how:

  • LVAToObjectCounter 用于将特定事件发送到 objectCounter 模块中的特定终结点。LVAToObjectCounter is used to send specific events to a specific endpoint in the objectCounter module.
  • ObjectCounterToLVA 用于将触发器事件发送到 lvaEdge 模块中的特定终结点(该终结点应为 IoT 中心源节点)。ObjectCounterToLVA is used to send a trigger event to a specific endpoint (which should be the IoT Hub source node) in the lvaEdge module.
  • objectCounterToIoTHub 作为调试工具使用,在运行本教程时,可借助它查看 objectCounter 的输出。objectCounterToIoTHub is used as a debug tool to help you see the output from objectCounter when you run this tutorial.

备注

检查 objectCounter 模块的所需属性,这些属性设置为查找标记为“卡车”的对象,并且可信度至少为 50%。Check the desired properties for the objectCounter module, which are set up to look for objects that are tagged as "truck" with a confidence level of at least 50%.

生成并部署 IoT Edge 部署清单Generate and deploy the IoT Edge deployment manifest

部署清单定义要部署到边缘设备的模块以及这些模块的配置设置。The deployment manifest defines what modules are deployed to an edge device and the configuration settings for those modules. 请按照以下步骤从模板文件生成清单,然后将其部署到边缘设备。Follow these steps to generate a manifest from the template file, and then deploy it to the edge device.

使用 Visual Studio Code,按照以下说明登录到 Docker。Using Visual Studio Code, follow these instructions to sign in to Docker. 然后选择“生成并推送 IoT Edge 解决方案”。Then select Build and Push IoT Edge Solution. 在此步骤中使用 src/edge/deployment.objectCounter.template.json。Use src/edge/deployment.objectCounter.template.json for this step.

生成并推送 IoT Edge 解决方案

此操作会生成用于对象计数的 objectCounter 模块,并将图像推送到 Azure 容器注册表。This action builds the objectCounter module for object counting and pushes the image to your Azure Container Registry.

  • 检查确认已在 .env 文件中定义 CONTAINER_REGISTRY_USERNAME_myacr 和 CONTAINER_REGISTRY_PASSWORD_myacr 环境变量。Check that you have the environment variables CONTAINER_REGISTRY_USERNAME_myacr and CONTAINER_REGISTRY_PASSWORD_myacr defined in the .env file.

此步骤会在 src/edge/config/deployment.objectCounter.amd64.json 创建 IoT Edge 部署清单。This step creates the IoT Edge deployment manifest at src/edge/config/deployment.objectCounter.amd64.json. 右键单击该文件,然后选择“为单个设备创建部署”。Right-click that file, and select Create Deployment for Single Device.

为单个设备创建部署

如果这是你第一次接触有关 IoT Edge 上的实时视频分析的教程,Visual Studio Code 将提示你输入 IoT 中心连接字符串。If this is your first tutorial with Live Video Analytics on IoT Edge, Visual Studio Code prompts you to input the IoT Hub connection string. 可以从 appsettings.json 文件中复制字符串。You can copy it from the appsettings.json file.

接下来,Visual Studio Code 会要求你选择 IoT 中心设备。Next, Visual Studio Code asks you to select an IoT Hub device. 选择 IoT Edge 设备(应为 lva-sample-device)。Select your IoT Edge device, which should be lva-sample-device.

在此阶段,将启动将边缘模块部署到 IoT Edge 设备的过程。At this stage, the deployment of edge modules to your IoT Edge device has started. 大约 30 秒后,在 Visual Studio Code 的左下部分刷新 Azure IoT 中心。In about 30 seconds, refresh Azure IoT Hub in the lower-left section in Visual Studio Code. 你应该会看到已部署四个模块,它们分别名为 lvaEdge、rtspsim、yolov3 和 objectCounter。You should see that there are four modules deployed named lvaEdge, rtspsim, yolov3, and objectCounter.

部署的 4 个模块

准备监视事件Prepare for monitoring events

若要查看来自 objectCounter 模块和 IoT Edge 上的实时视频分析模块的事件,请执行以下步骤:To see the events from the objectCounter module and from the Live Video Analytics on IoT Edge module, follow these steps:

  1. 在 Visual Studio Code 中打开“资源管理器”窗格,然后在左下角查找“Azure IoT 中心”。Open the Explorer pane in Visual Studio Code, and look for Azure IoT Hub in the lower-left corner.

  2. 展开“设备”节点。Expand the Devices node.

  3. 右键单击 lva-sample-device 文件,然后选择“开始监视内置事件终结点”。Right-click the lva-sample-device file, and select Start Monitoring Built-in Event Endpoint.

    开始监视内置事件终结点

运行程序Run the program

  1. 在 Visual Studio Code 中,转到 src/cloud-to-device-console-app/operations.json。In Visual Studio Code, go to src/cloud-to-device-console-app/operations.json.

  2. 在 GraphTopologySet 节点下,编辑以下内容:Under the GraphTopologySet node, edit the following:

    "topologyUrl" : "https://raw.githubusercontent.com/Azure/live-video-analytics/master/MediaGraph/topologies/evr-hubMessage-assets/topology.json"

  3. 接下来,在 GraphInstanceSet 和 GraphTopologyDelete 节点下,编辑 :Next, under the GraphInstanceSet and GraphTopologyDelete nodes, edit:

    "topologyName" : "EVRtoAssetsOnObjDetect"

  4. 选择 F5 以启动调试会话。Start a debugging session by selecting F5. 在“终端”窗口中,你将看到一些输出的消息。You'll see some messages printed in the TERMINAL window.

  5. operations.json 文件首先调用 GraphTopologyList 和 GraphInstanceList。The operations.json file starts off with calls to GraphTopologyList and GraphInstanceList. 如果在先前的快速入门或教程后清理了资源,此操作会返回空列表,然后暂停以便你能够选择 Enter,如下所示:If you've cleaned up resources after previous quickstarts or tutorials, this action returns empty lists and pauses for you to select Enter, as shown:

    --------------------------------------------------------------------------
    Executing operation GraphTopologyList
    -----------------------  Request: GraphTopologyList  --------------------------------------------------
    {
      "@apiVersion": "1.0"
    }
    ---------------  Response: GraphTopologyList - Status: 200  ---------------
    {
      "value": []
    }
    --------------------------------------------------------------------------
    Executing operation WaitForInput
    Press Enter to continue
    
  6. 在“终端”窗口中选择 Enter 后,会执行下一组直接方法调用 :After you select Enter in the TERMINAL window, the next set of direct method calls is made:

    • 使用上述 topologyUrl 调用 GraphTopologySetA call to GraphTopologySet by using the previous topologyUrl

    • 使用以下正文调用 GraphInstanceSetA call to GraphInstanceSet by using the following body

      {
        "@apiVersion": "1.0",
        "name": "Sample-Graph-1",
        "properties": {
          "topologyName": "EVRtoAssetsOnObjDetect",
          "description": "Sample graph description",
          "parameters": [
            {
              "name": "rtspUrl",
              "value": "rtsp://rtspsim:554/media/camera-300s.mkv"
            },
            {
              "name": "rtspUserName",
              "value": "testuser"
            },
            {
              "name": "rtspPassword",
              "value": "testpassword"
            }
          ]
        }
      }
      
    • 调用 GraphInstanceActivate 以启动图形实例,并启动视频流A call to GraphInstanceActivate to start the graph instance and start the flow of video

    • 再次调用 GraphInstanceList 以显示图形实例处于运行状态A second call to GraphInstanceList to show that the graph instance is in the running state

  7. “终端”窗口中的输出现在会在出现“按 Enter 继续”提示时暂停 。The output in the TERMINAL window pauses now at a Press Enter to continue prompt. 此时请勿选择 Enter。Don't select Enter at this time. 向上滚动,查看调用的直接方法的 JSON 响应有效负载。Scroll up to see the JSON response payloads for the direct methods you invoked.

  8. 如果现在切换到 Visual Studio Code 中的“输出”窗口,则将看到 IoT Edge 上的实时视频分析模块向 IoT 中心发送消息。If you now switch over to the OUTPUT window in Visual Studio Code, you'll see messages being sent to IoT Hub by the Live Video Analytics on IoT Edge module.

    下节中讨论了这些消息。These messages are discussed in the following section.

  9. 图形实例继续运行并录制视频。The graph instance continues to run and record the video. RTSP 模拟器不断循环源视频。The RTSP simulator keeps looping the source video. 根据下一部分中的介绍审阅这些消息。Review the messages as discussed in the following section. 然后,若要停止实例,请返回“终端”窗口,并选择 Enter 。Then to stop the instance, go back to the TERMINAL window and select Enter. 接下来会使用以下方法执行一系列调用,以清理资源:The next series of calls are made to clean up resources by using:

    • 调用 GraphInstanceDeactivate 以停用图形实例。A call to GraphInstanceDeactivate to deactivate the graph instance.
    • 调用 GraphInstanceDelete 以删除实例。A call to GraphInstanceDelete to delete the instance.
    • 调用 GraphTopologyDelete 以删除拓扑。A call to GraphTopologyDelete to delete the topology.
    • 最后调用 GraphTopologyList 以显示列表现在为空。A final call to GraphTopologyList to show that the list is now empty.

解释结果Interpret the results

运行媒体图时,IoT Edge 上的实时视频分析模块会将某些诊断和操作事件发送到 IoT Edge 中心。When you run the media graph, the Live Video Analytics on IoT Edge module sends certain diagnostic and operational events to the IoT Edge hub. 这些事件即你在 Visual Studio Code 的“输出”窗口中看到的消息。These events are the messages you see in the OUTPUT window of Visual Studio Code. 这些消息包含 body 部分和 applicationProperties 部分。They contain a body section and an applicationProperties section. 要了解这些部分表示的内容,请参阅创建和读取 IoT 中心消息To understand what these sections represent, see Create and read IoT Hub messages.

在下面的消息中,实时视频分析模块定义了应用程序属性和正文内容。In the following messages, the application properties and the content of the body are defined by the Live Video Analytics module.

诊断事件Diagnostics events

MediaSessionEstablished 事件MediaSessionEstablished event

实例化媒体图后,RTSP 源节点尝试连接到在 RTSP 模拟器容器上运行的 RTSP 服务器。When a media graph is instantiated, the RTSP source node attempts to connect to the RTSP server running on the RTSP simulator container. 如果成功,它将输出此事件。If successful, it prints this event. 事件类型为 Microsoft.Media.MediaGraph.Diagnostics.MediaSessionEstablished。The event type is Microsoft.Media.MediaGraph.Diagnostics.MediaSessionEstablished.

[IoTHubMonitor] [5:53:17 PM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "sdp": "SDP:\nv=0\r\no=- 1586450538111534 1 IN IP4 XXX.XX.XX.XX\r\ns=Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server\r\ni=media/camera-300s.mkv\r\nt=0 0\r\na=tool:LIVE555 Streaming Media v2020.03.06\r\na=type:broadcast\r\na=control:*\r\na=range:npt=0-300.000\r\na=x-qt-text-nam:Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server\r\na=x-qt-text-inf:media/camera-300s.mkv\r\nm=video 0 RTP/AVP 96\r\nc=IN IP4 0.0.0.0\r\nb=AS:500\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1;profile-level-id=4D0029;sprop-parameter-sets=XXXXXXXXXXXXXXXXXXXXXX\r\na=control:track1\r\n"
  },
  "applicationProperties": {
    "topic": "/subscriptions/{subscriptionID}/resourceGroups/{resource-group-name}/providers/microsoft.media/mediaservices/{ams-account-name}",
    "subject": "/graphInstances/Sample-Graph-1/sources/rtspSource",
    "eventType": "Microsoft.Media.Graph.Diagnostics.MediaSessionEstablished",
    "eventTime": "2020-05-17T17:53:16.981Z",
    "dataVersion": "1.0"
  }
}
  • 此消息是一个诊断事件 (MediaSessionEstablished)。The message is a Diagnostics event (MediaSessionEstablished). 它指示 RTSP 源节点(使用者)建立了与 RTSP 模拟器的连接,并开始接收(模拟的)实时馈送。It indicates that the RTSP source node (the subject) established a connection with the RTSP simulator and began to receive a (simulated) live feed.
  • applicationProperties 中的 subject 部分引用生成消息的图形拓扑中的节点。The subject section in applicationProperties references the node in the graph topology from which the message was generated. 在本例中,该消息来自 RTSP 源节点。In this case, the message originates from the RTSP source node.
  • applicationProperties 中的 eventType 部分指示这是诊断事件。The eventType section in applicationProperties indicates that this is a Diagnostics event.
  • eventTime 部分指示事件发生的时间。The eventTime section indicates the time when the event occurred. 这是交通流视频(MKV 文件)以实时流的形式开始进入模块的时间。This is the time when the traffic video (MKV file) started to arrive into the module as a live stream.
  • body 部分包含有关诊断事件的数据,在本例中是 SDP 的详细信息。The body section contains data about the Diagnostics event, which in this case is the SDP details.

操作事件Operational events

媒体图运行一段时间后,最终将从 objectCounter 模块获取事件。After the media graph runs for a while, eventually you'll get an event from the objectCounter module.

[IoTHubMonitor] [5:53:44 PM] Message received from [lva-sample-device/objectCounter]:
{
  "body": {
    "count": 2
  },
  "applicationProperties": {
    "eventTime": "2020-05-17T17:53:44.062Z"
  }
}

applicationProperties 部分包含事件时间。The applicationProperties section contains the event time. 这是 objectCounter 模块观察到来自 yolov3 模块的结果包含相关对象(卡车)的时间。This is the time when the objectCounter module observed that the results from the yolov3 module contained objects of interest (trucks).

随着在视频中检测到其他卡车,你会看到显示出更多的此类事件。You might see more of these events show up as other trucks are detected in the video.

RecordingStarted 事件RecordingStarted event

对象计数器发送事件后,你几乎立即会看到一个类型为 Microsoft.Media.Graph.Operational.RecordingStarted 的事件:Almost immediately after the Object Counter sends the event, you'll see an event of type Microsoft.Media.Graph.Operational.RecordingStarted:

[IoTHubMonitor] [5:53:46 PM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "outputType": "assetName",
    "outputLocation": "sampleAssetFromEVR-LVAEdge-20200517T175346Z"
  },
  "applicationProperties": {
    "topic": "/subscriptions/{subscriptionID}/resourceGroups/{resource-group-name}/providers/microsoft.media/mediaservices/{ams-account-name}",
    "subject": "/graphInstances/Sample-Graph-1/sinks/assetSink",
    "eventType": "Microsoft.Media.Graph.Operational.RecordingStarted",
    "eventTime": " 2020-05-17T17:53:46.132Z",
    "dataVersion": "1.0"
  }
}

applicationProperties 中的 subject 部分引用图形中的资产接收器节点,该节点生成此消息。The subject section in applicationProperties references the asset sink node in the graph, which generated this message. body 部分包含有关输出位置的信息。The body section contains information about the output location. 在本例中,即要将视频录制到的 Azure 媒体服务资产的名称。In this case, it's the name of the Azure Media Services asset into which video is recorded. 记下此值。Make a note of this value.

RecordingAvailable 事件RecordingAvailable event

资产接收器节点将视频数据上传到资产后,将发出类型为 Microsoft.Media.Graph.Operational.RecordingAvailable 的此事件:When the asset sink node has uploaded video to the asset, it emits this event of type Microsoft.Media.Graph.Operational.RecordingAvailable:

[IoTHubMonitor] [5:54:15 PM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "outputType": "assetName",
    "outputLocation": "sampleAssetFromEVR-LVAEdge-20200517T175346Z"
  },
  "applicationProperties": {
    "topic": "/subscriptions/{subscriptionID}/resourceGroups/{resource-group-name}/providers/microsoft.media/mediaservices/{ams-account-name}",
    "subject": "/graphInstances/Sample-Graph-1/sinks/assetSink",
    "eventType": "Microsoft.Media.Graph.Operational.RecordingAvailable",
    "eventTime": "2020-05-17T17:54:15.808Z",
    "dataVersion": "1.0"
  }
}

此事件指示已向资产写入足够的数据,播放器或客户端可以开始播放视频。This event indicates that enough data was written to the asset for players or clients to start playback of the video. applicationProperties 中的 subject 部分引用图形中的 AssetSink 节点,该节点生成此消息。The subject section in applicationProperties references the AssetSink node in the graph, which generated this message. body 部分包含有关输出位置的信息。The body section contains information about the output location. 在本例中,即要将视频录制到的 Azure 媒体服务资产的名称。In this case, it's the name of the Azure Media Services asset into which video is recorded.

RecordingStopped 事件RecordingStopped event

如果检查拓扑中信号入口处理器节点的激活设置 (maximumActivationTime),将会看到“入口”设置为在 30 秒视频流经过后关闭入口。If you examine the activation settings (maximumActivationTime) for the signal gate processor node in the topology, you'll see that the gate is set up to close after 30 seconds of video is sent through. RecordingStarted 事件后的大约 30 秒,应会看到一个类型为 Microsoft.Media.Graph.Operational.RecordingStopped 的事件。Roughly 30 seconds after the RecordingStarted event, you should see an event of type Microsoft.Media.Graph.Operational.RecordingStopped. 该事件指示资产接收器节点已停止将视频录制到资产。This event indicates that the asset sink node has stopped recording video to the asset.

[IoTHubMonitor] [5:54:15 PM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "outputType": "assetName",
    "outputLocation": "sampleAssetFromEVR-LVAEdge-20200517T175346Z"
  },
  "applicationProperties": {
    "topic": "/subscriptions/{subscriptionID}/resourceGroups/{resource-group-name}/providers/microsoft.media/mediaservices/{ams-account-name}",
    "subject": "/graphInstances/Sample-Graph-1/sinks/assetSink",
    "eventType": "Microsoft.Media.Graph.Operational.RecordingStopped",
    "eventTime": "2020-05-17T17:54:15.040Z",
    "dataVersion": "1.0"
  }
}

此事件指示录制已停止。This event indicates that recording has stopped. applicationProperties 中的 subject 部分引用图形中的 AssetSink 节点,该节点生成此消息。The subject section in applicationProperties references the AssetSink node in the graph, which generated this message. body 部分包含有关输出位置的信息。The body section contains information about the output location. 在本例中,即要将视频录制到的 Azure 媒体服务资产的名称。In this case, it's the name of the Azure Media Services asset into which video is recorded.

媒体服务资产Media Services asset

可以通过登录到 Azure 门户并观看视频来检查图创建的媒体服务资产。You can examine the Media Services asset that was created by the graph by logging in to the Azure portal and viewing the video.

  1. 打开 Web 浏览器,并转到 Azure 门户Open your web browser, and go to the Azure portal. 输入登录到门户所需的凭据。Enter your credentials to sign in to the portal. 默认视图是服务仪表板。The default view is your service dashboard.

  2. 在订阅中的资源中找到媒体服务帐户。Locate your Media Services account among the resources you have in your subscription. 打开帐户窗格。Open the account pane.

  3. 选择“媒体服务”列表中的“资产” 。Select Assets in the Media Services list.

    资产

  4. 将找到以名称 sampleAssetFromEVR-LVAEdge-{DateTime} 列出的资产。You'll find an asset listed with the name sampleAssetFromEVR-LVAEdge-{DateTime}. 这是 RecordingStarted 事件的 outputLocation 属性中提供的名称。This is the name provided in the outputLocation property of the RecordingStarted event. 拓扑中的 assetNamePattern 决定了此名称的生成方式。The assetNamePattern in the topology determines how this name was generated.

  5. 选择资产。Select the asset.

  6. 在“资产详细信息”页上,选择“流式处理 URL”文本框下的“新建” 。On the asset details page, select Create new under the Streaming URL text box.

    新建资产

  7. 在打开的向导中,接受默认选项,然后选择“添加”。In the wizard that opens, accept the default options and select Add. 有关详细信息,请参阅视频播放For more information, see video playback.

  8. 播放器应加载视频。The player should load the video. 选择“播放”观看该视频。Select Play to view it.

备注

由于视频源是模拟相机源的容器,因此视频中的时间戳与激活图形实例的时间和停用该实例的时间有关。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 graph instance and when you deactivated it. 如果使用播放多天的录制内容教程中内置的播放控件,可以看到屏幕上显示视频中的时间戳。If you use the playback controls built into the Playback of multi-day recordings tutorial, you can see the time stamps in the video displayed onscreen.

清理资源Clean up resources

如果想学习其他教程,请保留创建的资源。If you intend to try the other tutorials, hold on to the resources you created. 如果不想,请转到 Azure 门户,浏览到资源组,选择运行本教程时所用的资源组,然后删除该资源组。Otherwise, go to the Azure portal, browse to your resource groups, select the resource group under which you ran this tutorial, and delete the resource group.

后续步骤Next steps