连续视频录制Continuous video recording

建议的读前准备Suggested pre-reading

概述Overview

连续视频录制 (CVR) 是指从视频源连续录制视频的过程。Continuous video recording (CVR) refers to the process of continuously recording the video from a video source. IoT Edge 上的实时视频分析通过包含 RTSP 源节点和资产接收器节点的媒体图从 CCTV 相机全天候连续录制视频。Live Video Analytics on IoT Edge supports recording video continuously, on a 24x7 basis, from a CCTV camera via a media graph consisting of an RTSP source node and an asset sink node. 下图显示了该媒体图的图形表示形式。The diagram below shows a graphical representation of such a media graph. 可在此处找到此类媒体图的图形拓扑的 JSON 表示形式。The JSON representation of the graph topology of such a media graph can be found here.

连续视频录制

上面所示的媒体图可以在边缘设备上运行,资产接收器将视频录制到 Azure 媒体服务资产The media graph depicted above can be run on an edge device, with the asset sink recording video to an Azure Media Services asset. 只要媒体图保持激活状态,视频就会被录制。The video will be recorded for as long as the media graph stays in the activated state. 由于视频被录制为资产,因此可以使用媒体服务的现有流式传输功能播放视频。Since video is being recorded as an asset, it can be played back using the existing streaming capabilities of Media Services. 有关更多详细信息,请参阅播放录制的内容See Playback of recorded content for more details.

可复原的录制Resilient recording

IoT Edge 上的实时视频分析支持在不太理想的网络情况下操作,在这种情况下,边缘设备偶尔可能会与云断开连接,或者可能会出现可用带宽下降的情况。Live Video Analytics on IoT Edge supports operating under less-than-perfect network conditions, where the edge device may occasionally lose connectivity with the cloud or experience a drop in available bandwidth. 为此,将源中的视频录制到本地缓存中,并定期自动与资产同步。To account for this, the video from the source is recorded locally into a cache and is automatically synced with the asset on a periodic basis. 如果检查图形拓扑 JSON,将看到定义了以下属性:If you examine the graph topology JSON, you will see it has the following properties defined:

"segmentLength": "PT30S",
"localMediaCacheMaximumSizeMiB": "2048",
"localMediaCachePath": "/var/lib/azuremediaservices/tmp/",

后两个属性与可复原的录制相关(两者也都是资产接收器节点的必需属性)。The latter two properties are relevant to resilient recording (both are also required properties for an asset sink node). localMediaCachePath 属性告知资产接收器在上传到资产之前,使用该文件夹路径来缓存媒体数据。The localMediaCachePath property tells the asset sink to use that folder path to cache media data before uploading to the asset. 可以在文章中了解边缘模块如何利用设备的本地存储。You can see this article to understand how the edge module can make use of your device's local storage. localMediaCacheMaximumSizeMiB 属性定义资产接收器可用作缓存的磁盘空间(1 MiB = 1024 * 1024 个字节)。The localMediaCacheMaximumSizeMiB property defines how much disk space the asset sink can use as a cache (1 MiB = 1024 * 1024 bytes).

如果边缘模块长时间断开连接,并且缓存文件夹中存储的内容达到 localMediaCacheMaximumSizeMiB 值,则资产接收器将开始从缓存中丢弃数据,从最早的数据开始。If your edge module loses connectivity for a very long time and the content stored in the cache folder reaches the localMediaCacheMaximumSizeMiB value, the asset sink will start discarding data from the cache, starting from the oldest data. 例如,如果设备在上午 10 点断开连接,而缓存在下午 6 点达到最大限制,则资产接收器将开始删除在上午 10 点录制的数据。For example, if the device lost connectivity at 10AM and the cache hits the maximum limit at 6PM, then the asset sink starts to delete data recorded at 10AM.

当恢复网络连接时,资产接收器将从缓存开始上传,也是从最早的数据开始。When network connectivity is restored, the asset sink will begin uploading from the cache, again starting from the oldest data. 在上面的示例中,假设在恢复连接前(例如在下午 6:02)必须从缓存中丢弃 5 分钟的视频,则资产接收器将从上午 10:05 标记开始上传。In the above example, suppose 5 minutes worth of video had to be discarded from cache by the time connectivity was restored (say at 6:02PM), then the asset sink will start uploading from the 10:05AM mark.

如果以后使用这些 API 来检查资产,将看到资产中大约从上午 10 点到上午 10:05 之间存在间隙。If you later examine the asset using these APIs, you will see that there is a gap in the asset from approximately 10AM to 10:05AM.

分段录制Segmented recording

如上所述,资产接收器节点会将视频录制到本地缓存中,并定期将视频上传到云。As discussed above, the asset sink node will record video to a local cache, and periodically upload the video to the cloud. segmentLength 属性(如上一节所示)有助于控制与将数据写入到正在录制资产的存储帐户相关的写入事务成本。The segmentLength property (shown in the above section) will help you control the write transactions cost associated with writing data to your storage account where the asset is being recorded. 例如,如果将上传时间从 30 秒增加到 5 分钟,那么存储事务的数量将下降 10 倍 (5*60/30)。For example, if you increase the upload period from 30 seconds to 5 minutes, then the number of storage transactions will drop by a factor of 10 (5*60/30).

segmentLength 属性确保边缘模块每 segmentLength 秒最多上传一次视频。The segmentLength property ensures that the edge module will upload video at most once per segmentLength seconds. 此属性的最小值为 30 秒(也是默认值),可以 30 秒递增,最大值为 5 分钟。This property has a minimum value of 30 seconds (also the default), and can be increased by 30 second increments to a maximum of 5 minutes.

备注

请参阅播放录制内容一文,了解 segmentLength 对播放的影响。See the playback recordings article for the effect that segmentLength has on playback.

另请参阅See also

后续步骤Next steps

教程:连续视频录制Tutorial: continuous video recording