教程:将视频连续录制到云中并从云中播放Tutorial: Continuous video recording to the cloud and playback from the cloud

在本教程中,你将了解如何使用 Azure IoT Edge 上的 Azure 实时视频分析对云执行连续视频录制 (CVR) 并使用 Azure 媒体服务流式传输该视频的任何部分。In this tutorial, you'll learn how to use Azure Live Video Analytics on Azure IoT Edge to perform continuous video recording (CVR) to the cloud and stream any portion of that video by using Azure Media Services. 此功能对于诸如安全性和合规性等方案很有用,因为这些方案需要将相机中的素材存档保存数天或数周。This capability is useful for scenarios such as safety and compliance where there's a need to maintain an archive of the footage from a camera for days or weeks.

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

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

如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅If you don't have an Azure trail subscription, create a trial subscription 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

提示

如果在创建 Azure 资源时遇到问题,请查看故障排除指南来解决一些常见问题。If you run into issues with Azure resources that get created, please view our troubleshooting guide to resolve some commonly encountered issues.

概念Concepts

媒体图概念一文中所述,使用媒体图可以定义:As explained in the media graph concept article, a media graph lets you define:

  • 应从何处捕获媒体。Where media should be captured from.
  • 应如何处理媒体。How it should be processed.
  • 应将结果交付到何处。Where the results should be delivered.

若要完成 CVR,需要从支持 RTSP 的相机中捕获视频,并将其连续记录到 Azure 媒体服务资产To accomplish CVR, you need to capture the video from an RTSP-capable camera and continuously record it to an Azure Media Services asset. 下图显示了该媒体图的图形表示形式。This diagram shows a graphical representation of that media graph.

媒体图

在本教程中,你将通过使用 Live555 Media Server 生成的一个 Edge 模块来模拟 RTSP 相机。In this tutorial, you'll use one edge module built by using the Live555 Media Server to simulate an RTSP camera. 在媒体图中,你将使用 RTSP 源节点获取实时源,并将该视频发送到资产接收器节点,后者会将视频记录到资产中。Inside the media graph, you'll use an RTSP source node to get the live feed and send that video to the asset sink node, which records the video to an asset. 本教程中将使用的视频是公路交叉口示例视频The video that will be used in this tutorial is a highway intersection sample video.

> [!VIDEO https://www.microsoft.com/en-us/videoplayer/embed/RE4LTY4]

设置开发环境Set up your development environment

在开始之前,请检查是否满足先决条件中的第三条。Before you begin, check that you've 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.
  • appsettings.json:由 Visual Studio Code 用于运行示例代码。appsettings.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 the .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>"  
    VIDEO_INPUT_FOLDER_ON_DEVICE="/home/lvaedgeuser/samples/input"  
    VIDEO_OUTPUT_FOLDER_ON_DEVICE="/var/media"  
    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 sample files

在 Visual Studio Code 打开“src/edge/deployment.template.json”。In Visual Studio Code, open src/edge/deployment.template.json. 该模板定义了要部署到边缘设备 (Azure Linux VM) 的边缘模块。This template defines which edge modules you'll deploy to the edge device (the Azure Linux VM). “模块”部分下有两个条目,其名称如下:There are two entries under the modules section with the following names:

  • lvaEdge:这是 IoT Edge 上的实时视频分析模块。lvaEdge: This is the Live Video Analytics on IoT Edge module.
  • rtspsim:这是 RTSP 模拟器。rtspsim: This is the RTSP simulator.

接下来,浏览到 src/cloud-to-device-console-app 文件夹。Next, browse to the src/cloud-to-device-console-app folder. 在这里,你将看到创建的 appsettings.json 文件以及其他一些文件:Here you'll see the appsettings.json file that you created along with a few other files:

  • c2d-console-app.csproj:Visual Studio Code 的项目文件。c2d-console-app.csproj: The project file for Visual Studio Code.
  • operations.json:该文件列出了你将运行的不同操作。operations.json: This file lists the different operations that you would run.
  • Program.cs:执行以下操作的示例程序代码:Program.cs: The sample program code, which:
    • 加载应用设置。Loads the app settings.
    • 在 IoT Edge 模块上调用实时视频分析公开的直接方法。Invokes direct methods exposed by the Live Video Analytics on IoT Edge module. 可以通过调用模块的直接方法来使用该模块分析实时视频流。You can use the module to analyze live video streams by invoking its direct methods.
    • 暂停以检查“终端”窗口中程序的输出以及 OUTPUT 窗口中模块生成的事件 。Pauses for you to examine the output from the program in the TERMINAL window and the events generated by the module in the OUTPUT window.
    • 调用直接方法以清理资源。Invokes direct methods to clean up resources.

生成并部署 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.

  1. 启动 Visual Studio Code。Start Visual Studio Code.

  2. 选择左下角“AZURE IOT 中心”窗格旁边的“更多操作”图标,设置 IoT 中心连接字符串 。Set the IoT Hub connection string by selecting the More actions icon next to the AZURE IOT HUB pane in the lower-left corner. 从 src/cloud-to-device-console-app/appsettings.json 文件复制该字符串。Copy the string from the src/cloud-to-device-console-app/appsettings.json file.

    设置 IoT 中心连接字符串

    备注

    系统可能会要求你提供 IoT 中心的内置终结点信息。You might be asked to provide Built-in endpoint information for the IoT Hub. 若要获取此信息,请在 Azure 门户中导航到 IoT 中心,然后在左侧导航窗格中查找“内置终结点”选项。To get that information, in Azure portal, navigate to your IoT Hub and look for Built-in endpoints option in the left navigation pane. 单击此处,在“与事件中心兼容的终结点”部分下查找“与事件中心兼容的终结点” 。Click there and look for the Event Hub-compatible endpoint under Event Hub compatible endpoint section. 复制并使用框中的文本。Copy and use the text in the box. 终结点将如下所示:The endpoint will look something like this:
    Endpoint=sb://iothub-ns-xxx.servicebus.chinacloudapi.cn/;SharedAccessKeyName=iothubowner;SharedAccessKey=XXX;EntityPath=<IoT Hub name>

  3. 右键单击“src/edge/deployment.template.json”文件,然后选择“生成 IoT Edge 部署清单”。Right-click the src/edge/deployment.template.json file, and select Generate IoT Edge Deployment Manifest. Visual Studio Code 使用 .env 文件中的值来替换在部署模板文件中找到的变量。Visual Studio Code uses the values from the .env file to replace the variables found in the deployment template file. 此操作在 src/edge/config 文件夹中创建一个名为 deployment.amd64.json 的清单文件。This action creates a manifest file in the src/edge/config folder named deployment.amd64.json.

    生成 IoT Edge 部署清单

  4. 右键单击“src/edge/config/deployment.amd64.json”文件,,然后选择“为单个设备创建部署”。Right-click the src/edge/config/deployment.amd64.json file, and select Create Deployment for Single Device.

    为单个设备创建部署

  5. 然后,系统会要求你“选择 IoT 中心设备”。You're then asked to Select an IoT Hub device. 从下拉列表中选择 lva-sample-device。Select lva-sample-device from the drop-down list.

  6. 大约 30 秒后,在左下部分刷新 Azure IoT 中心。In about 30 seconds, refresh Azure IoT Hub in the lower-left section. 应会看到边缘设备已部署以下模块:You should see the edge device has the following modules deployed:

    • IoT Edge 上的实时视频分析(模块名称为“lvaEdge”)Live Video Analytics on IoT Edge (module name lvaEdge)
    • RTSP 模拟器(模块名称为“rtspsim”)RTSP simulator (module name rtspsim)

    IoT 中心

准备监视模块Prepare to monitor the modules

使用 IoT Edge 模块上的实时视频分析来记录实时视频流时,它会将事件发送到 IoT 中心。When you use the Live Video Analytics on IoT Edge module to record the live video stream, it sends events to IoT Hub. 若要查看这些事件,请执行以下步骤:To see these events, 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.

    开始监视内置事件终结点

    备注

    系统可能会要求你提供 IoT 中心的内置终结点信息。You might be asked to provide Built-in endpoint information for the IoT Hub. 若要获取此信息,请在 Azure 门户中导航到 IoT 中心,然后在左侧导航窗格中查找“内置终结点”选项。To get that information, in Azure portal, navigate to your IoT Hub and look for Built-in endpoints option in the left navigation pane. 单击此处,在“与事件中心兼容的终结点”部分下查找“与事件中心兼容的终结点” 。Click there and look for the Event Hub-compatible endpoint under Event Hub compatible endpoint section. 复制并使用框中的文本。Copy and use the text in the box. 终结点将如下所示:The endpoint will look something like this:
    Endpoint=sb://iothub-ns-xxx.servicebus.chinacloudapi.cn/;SharedAccessKeyName=iothubowner;SharedAccessKey=XXX;EntityPath=<IoT Hub name>

运行程序Run the program

  1. 在 Visual Studio Code 中,打开“扩展”选项卡(或按 Ctrl+Shift+X),然后搜索“Azure IoT 中心”。In Visual Studio Code, open the Extensions tab (or press Ctrl+Shift+X) and search for Azure IoT Hub.

  2. 右键单击并选择“扩展设置”。Right click and select Extension Settings.

    扩展设置

  3. 搜索并启用“显示详细消息”。Search and enable "Show Verbose Message".

    显示详细消息

  4. 转到 src/cloud-to-device-console-app/operations.json。Go to src/cloud-to-device-console-app/operations.json.

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

    "topologyUrl" : "https://raw.githubusercontent.com/Azure/live-video-analytics/master/MediaGraph/topologies/cvr-asset/2.0/topology.json"

  6. 接下来,在 GraphInstanceSet 和 GraphTopologyDelete 节点下,确保 topologyName 的值与前面图形拓扑中的 name 属性的值匹配 :Next, under the GraphInstanceSet and GraphTopologyDelete nodes, ensure that the value of topologyName matches the value of the name property in the previous graph topology:

    "topologyName" : "CVRToAMSAsset"

  7. 在浏览器中打开拓扑,并查看 assetNamePattern。Open the topology in a browser, and look at assetNamePattern. 为了确保资产具有唯一名称,可能需要在 operations.json 文件中更改图形实例的名称(默认值为 Sample-Graph-1)。To make sure you have an asset with a unique name, you might want to change the graph instance name in the operations.json file (from the default value of Sample-Graph-1).

    "assetNamePattern": "sampleAsset-${System.GraphTopologyName}-${System.GraphInstanceName}"

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

  9. 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 then pauses for you to select Enter, as shown:

    --------------------------------------------------------------------------
    Executing operation GraphTopologyList
    -----------------------  Request: GraphTopologyList  --------------------------------------------------
    {
      "@apiVersion": "2.0"
    }
    ---------------  Response: GraphTopologyList - Status: 200  ---------------
    {
      "value": []
    }
    --------------------------------------------------------------------------
    Executing operation WaitForInput
    Press Enter to continue
    
  10. 在“终端”窗口中选择 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": "2.0",
        "name": "Sample-Graph-1",
        "properties": {
          "topologyName": "CVRToAMSAsset",
          "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 to start the flow of video

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

  11. “终端”窗口中的输出现在会在出现“按 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.

  12. 如果现在切换到 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.

  13. 图形实例继续运行并录制视频。The graph instance continues to run and record the video. RTSP 模拟器不断循环源视频。The RTSP simulator keeps looping the source video. 若要停止录制,请返回到“终端”窗口并选择 Enter 。To stop recording, 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

MediaSession 建立的事件MediaSession Established event

激活图形实例后,RTSP 源节点会尝试连接到在 rtspsim 模块中运行的 RTSP 服务器。When the graph instance is activated, the RTSP source node attempts to connect to the RTSP server running in the rtspsim module. 如果成功,它将输出此事件:If successful, it prints this event:

[IoTHubMonitor] [9:42:18 AM] Message received from [lvaedgesample/lvaEdge]:
{
  "body": {
    "sdp&quot;: &quot;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": {
    "dataVersion": "1.0",
    "topic": "/subscriptions/{subscriptionID}/resourceGroups/{name}/providers/microsoft.media/mediaservices/hubname",
    "subject": "/graphInstances/Sample-Graph-1/sources/rtspSource",
    "eventType": "Microsoft.Media.MediaGraph.Diagnostics.MediaSessionEstablished",
    "eventTime": "2020-04-09T09:42:18.1280000Z"
  }
}
  • 此消息是一个诊断事件 (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.
  • body 部分包含有关诊断事件的数据,在本例中是 SDP 的详细信息。The body section contains data about the Diagnostics event, which in this case is the SDP details.

操作事件Operational events

RecordingStarted 事件RecordingStarted event

当资产接收器节点开始录制视频时,将发出此事件,其类型为 Microsoft.Media.Graph.Operational.RecordingStarted:When the asset sink node starts to record video, it emits this event of type Microsoft.Media.Graph.Operational.RecordingStarted:

[IoTHubMonitor] [9:42:38 AM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "outputType": "assetName",
    "outputLocation&quot;: &quot;sampleAsset-CVRToAMSAsset-Sample-Graph-1"
  },
  "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-04-09T09:42:38.1280000Z",
    "dataVersion&quot;: &quot;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

顾名思义,RecordingStarted 事件在录制开始时发送,但视频数据可能尚未上传到资产。As the name suggests, the RecordingStarted event is sent when recording has started, but video data might not have been uploaded to the asset yet. 资产接收器节点将视频数据上传到资产后,将发出类型为 Microsoft.Media.Graph.Operational.RecordingAvailable 的此事件:When the asset sink node has uploaded video data to the asset, it emits this event of type Microsoft.Media.Graph.Operational.RecordingAvailable:

[IoTHubMonitor] [[9:43:38 AM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "outputType": "assetName",
    "outputLocation&quot;: &quot;sampleAsset-CVRToAMSAsset-Sample-Graph-1"
  },
  "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-04-09T09:43:38.1280000Z",
    "dataVersion&quot;: &quot;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

停用 Graph 实例后,资产接收器节点会停止将视频录制到资产。When you deactivate the Graph Instance, the asset sink node stops recording video to the asset. 它发出类型为 Microsoft.Media.Graph.Operational.RecordingStopped 的此事件:It emits this event of type Microsoft.Media.Graph.Operational.RecordingStopped:

[IoTHubMonitor] [11:33:31 PM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "outputType": "assetName",
    "outputLocation&quot;: &quot;sampleAsset-CVRToAMSAsset-Sample-Graph-1"
  },
  "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-04-10T11:33:31.051Z",
    "dataVersion&quot;: &quot;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.

正文部分包含有关输出位置的信息,在本例中是用于录制视频的 Azure 媒体服务资产的名称。The body section contains information about the output location, which in this case is 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 media 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, and open the account pane.

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

    媒体服务资产

  4. 将找到以名称 sampleAsset-CVRToAMSAsset-Sample-Graph-1 列出的资产。You'll find an asset listed with the name sampleAsset-CVRToAMSAsset-Sample-Graph-1. 这是在图形拓扑文件中选择的命名模式。This is the naming pattern chosen in your graph topology file.

  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. 若有了解如何浏览多天的录制并查看该存档的部分内容,请参阅播放多天录制的内容教程。To see how to browse a multiday recording and view portions of that archive, see the Playback of multi-day recordings tutorial. 在该教程中,还可以在屏幕上显示的视频中看到时间戳。In that tutorial, you also 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