为基于事件的视频录制配置信号门Configure a signal gate for event-based video recording

在媒体图中,信号门处理器节点可以在事件触发信号门时将媒体从一个节点转发到另一个节点。Within a media graph, a signal gate processor node allows you to forward media from one node to another when the gate is triggered by an event. 当被触发时,信号门会打开,允许媒体在指定的持续时间内流过。When it's triggered, the gate opens and lets media flow through for a specified duration. 如果没有事件触发信号门,则信号门会关闭,媒体会停止流动。In the absence of events to trigger the gate, the gate closes, and media stops flowing. 可以使用信号门处理器进行基于事件的视频录制。You can use the signal gate processor for event-based video recording.

在本文中,你将了解如何配置信号门处理器。In this article, you'll learn how to configure a signal gate processor.

建议的预读取Suggested prereading

问题Problem

用户可能希望在信号门被事件触发之前或之后的某个特定时间开始录制。A user might want to start recording at a particular time before or after the gate is triggered by an event. 用户知道他们系统内的可接受延迟。The user knows the acceptable latency within their system. 因此,他们希望指定信号门处理器的延迟。So they want to specify the latency of the signal gate processor. 他们还希望指定其录制的最短和最长持续时间,而不管接收了多少个新事件。They also want to specify the minimum and maximum duration of their recording, no matter how many new events are received.

用例场景Use case scenario

假设你想要在每次打开大楼的前门时录制视频。Suppose you want to record video every time the front door of your building opens. 你希望该录制:You want the recording to:

  • 包括门打开之前的 X 秒。Include the X seconds before the door opens.
  • 在门未被再次打开的情况下,包括最后的至少 Y 秒。Last at least Y seconds if the door isn't opened again.
  • 在门重复打开的情况下,包括最后的至多 Z 秒。Last at most Z seconds if the door is repeatedly opened.

你知道你的门传感器的延迟为 K 秒。You know that your door sensor has a latency of K seconds. 为了减少事件被视为迟到而被忽略的几率,你希望等待至少 K 秒,以便事件到达。To reduce the chance of events being disregarded as late arrivals, you want to allow at least K seconds for the events to arrive.

解决方案Solution

若要解决此问题,请修改信号门处理器参数。To address the problem, modify your signal gate processor parameters.

若要配置信号门处理器,请使用以下四个参数:To configure a signal gate processor, use these four parameters:

  • 激活评估窗口Activation evaluation window
  • 激活信号偏移量Activation signal offset
  • 最小激活窗口Minimum activation window
  • 最大激活窗口Maximum activation window

信号门处理器被触发后,它会在最短激活时间内保持打开状态。When the signal gate processor is triggered, it stays open for the minimum activation time. 激活事件从最早事件的时间戳加上激活信号偏移量后的那个时间点开始。The activation event begins at the time stamp for the earliest event, plus the activation signal offset.

如果信号门处理器在打开时再次触发,则计时器会重置,信号门至少会在最小激活时间内保持打开状态。If the signal gate processor is triggered again while it's open, the timer resets and the gate stays open for at least the minimum activation time. 信号门处理器保持打开状态的时间从不会超过最大激活时间。The signal gate processor never stays open longer than the maximum activation time.

如果一个事件(事件 1)在另一个事件(事件 2)之前发生,但系统滞后,导致事件 1 在事件 2 之后到达信号门处理器,则事件 1 可能会被忽略,具体取决于媒体时间戳。An event (event 1) that occurs before another event (event 2), based on media time stamps, could be disregarded if the system lags and event 1 arrives at the signal gate processor after event 2. 事件 2 到达后,如果事件 1 没有在激活评估窗口关闭之前到达,则会忽略事件 1。If event 1 doesn't arrive between the arrival of event 2 and the activation evaluation window, event 1 is disregarded. 系统不会让其通过信号门处理器。It isn't passed through the signal gate processor.

将为每个事件设置相关 ID。Correlation IDs are set for every event. 这些 ID 是从初始事件设置的。These IDs are set from the initial event. 对于每个后续事件,它们会按顺序编号。They're sequential for each following event.

重要

媒体时间基于媒体中发生事件时的媒体时间戳。Media time is based on the media time stamp of when an event occurs in the media. 事件到达信号门的顺序可能没有反映事件按媒体时间到达的顺序。The sequence of events that arrive at the signal gate might not reflect the sequence of events that arrive in media time.

基于事件到达信号门的物理时间的参数Parameters, based on the physical time that events arrive at the signal gate

  • minimumActivationTime(录制的最短可能持续时间) :信号门处理器被触发以接收新事件后,在不被 maximumActivationTime 中断的情况下保持打开状态的最小秒数。minimumActivationTime (shortest possible duration of a recording): The minimum number of seconds that the signal gate processor remains open after it's triggered to receive new events, unless it's interrupted by the maximumActivationTime.
  • maximumActivationTime(录制的最长可能持续时间) :从初始事件起,信号门处理器在被触发以接收新事件(无论接收什么事件)后保持打开状态的最大秒数。maximumActivationTime (longest possible duration of a recording): The maximum number of seconds from the initial event that the signal gate processor remains open after being triggered to receive new events, regardless of what events are received.
  • activationSignalOffset:从激活信号门处理器到开始录制视频之间的秒数。activationSignalOffset: The number of seconds between the activation of the signal gate processor and the start of the video recording. 通常此值为负,因为是在触发事件之前开始录制。Typically, this value is negative because it starts the recording before the triggering event.
  • activationEvaluationWindow:从初始触发事件开始,在初始事件之前发生的事件必须在该秒数内(以媒体时间计)到达信号门处理器,才不会被忽略并被视为延迟到达。activationEvaluationWindow: Starting from the initial triggering event, the number of seconds in which an event that occurred before the initial event, in media time, must arrive at the signal gate processor before it's disregarded and considered a late arrival.

备注

“延迟到达”是指在激活评估窗口过去之后但在初始事件之前到达的任何事件(以媒体时间计)。A late arrival is any event that arrives after the activation evaluation window has passed but that arrives before the initial event in media time.

参数限制Limits of parameters

  • activationEvaluationWindow:0 秒到 10 秒activationEvaluationWindow: 0 seconds to 10 seconds
  • activationSignalOffset:-1 分钟到 1 分钟activationSignalOffset: -1 minute to 1 minute
  • minimumActivationTime:1 秒到 1 小时minimumActivationTime: 1 second to 1 hour
  • maximumActivationTime:1 秒到 1 小时maximumActivationTime: 1 second to 1 hour

在用例中,你将按以下要求设置参数:In the use case, you would set the parameters as follows:

  • activationEvaluationWindow:K 秒activationEvaluationWindow: K seconds
  • activationSignalOffset:-X 秒activationSignalOffset: -X seconds
  • minimumActivationWindow:Y 秒minimumActivationWindow: Y seconds
  • maximumActivationWindow:Z 秒maximumActivationWindow: Z seconds

下面是一个示例,说明了 信号门处理器 节点部分在媒体图拓扑中查找以下参数值的方式:Here's an example of how the Signal Gate Processor node section would look in a media graph topology for the following parameter values:

  • activationEvaluationWindow:1 秒activationEvaluationWindow: 1 second
  • activationSignalOffset:-5 秒activationSignalOffset: -5 seconds
  • minimumActivationTime:20 秒minimumActivationTime: 20 seconds
  • maximumActivationTime:40 秒maximumActivationTime: 40 seconds

重要

每个参数值都应使用 ISO 8601 持续时间格式ISO 8601 duration format is expected for each parameter value. 例如,PT1S = 1 秒。For example, PT1S = 1 second.

"processors":              
[
          {
            "@type": "#Microsoft.Media.MediaGraphSignalGateProcessor",
            "name": "signalGateProcessor",
            "inputs": [
              {
                "nodeName": "iotMessageSource"
              },
              {
                "nodeName": "rtspSource"
              }
            ],
            "activationEvaluationWindow": "PT1S",
            "activationSignalOffset": "-PT5S",
            "minimumActivationTime": "PT20S",
            "maximumActivationTime": "PT40S"
          }
]

现在,请考虑此信号门处理器配置在不同录制场景中的表现情况。Now consider how this signal gate processor configuration will behave in different recording scenarios.

录制场景Recording scenarios

一个事件来自一个源(正常激活)One event from one source (normal activation)

如果信号门处理器接收一个事件,则会在事件到达信号门之前提前 5 秒(激活信号 = 5秒)开始录制。A signal gate processor that receives one event results in a recording that starts 5 seconds (activation signal = 5 seconds) before the event arrives at the gate. 剩余的录制为 20 秒(最小激活时间 = 20 秒),因为在最小激活时间结束之前没有其他事件到达来重新触发信号门。The rest of the recording is 20 seconds (minimum activation time = 20 seconds) because no other events arrive before the end of the minimum activation time to retrigger the gate.

示例示意图:Example diagram:

示意图显示了正常激活,即一个事件来自一个源。

  • 录制持续时间 = -偏移量 + minimumActivationTime = [E1+偏移量, E1+minimumActivationTime]Duration of recording = -offset + minimumActivationTime = [E1+offset, E1+minimumActivationTime]

两个事件来自一个源(重新触发的激活)Two events from one source (retriggered activation)

如果信号门处理器接收两个事件,则会在事件到达信号门之前提前 5 秒(激活信号偏移量 = 5秒)开始录制。A signal gate processor that receives two events results in a recording that starts 5 seconds (activation signal offset = 5 seconds) before the event arrives at the gate. 另外,事件 2 在事件 1 之后 5 秒到达。Also, event 2 arrives 5 seconds after event 1. 因为事件 2 在事件 1 的最小激活时间(20 秒)结束之前到达,所以信号门会重新触发。Because event 2 arrives before the end of event 1's minimum activation time (20 seconds), the gate is retriggered. 剩余的录制为 20 秒(最小激活时间 = 20 秒),因为在事件 2 的最小激活时间结束之前没有其他事件到达来重新触发信号门。The rest of the recording is 20 seconds (minimum activation time = 20 seconds) because no other events arrive before the end of the minimum activation time from event 2 to retrigger the gate.

示例示意图:Example diagram:

示意图显示了重新触发的激活,即两个事件来自一个源。

  • 录制持续时间 = -偏移量 +(事件 2 到达时间 - 事件 1 到达时间)+ minimumActivationTimeDuration of recording = -offset + (arrival of event 2 - arrival of event 1) + minimumActivationTime

N 个事件来自一个源(最大激活)N events from one source (maximum activation)

如果信号门处理器接收 N 个事件,则会在第一个事件到达信号门之前提前 5 秒(激活信号偏移量 = 5秒)开始录制。A signal gate processor that receives N events results in a recording that starts 5 seconds (activation signal offset = 5 seconds) before the first event arrives at the gate. 当每个事件在上一个事件 20 秒的最小激活时间结束之前到达时,信号门会被连续重新触发。As each event arrives before the end of the minimum activation time of 20 seconds from the previous event, the gate is continuously retriggered. 它会保持打开状态,直到第一个事件后经过 40 秒的最大激活时间。It remains open until the maximum activation time of 40 seconds after the first event. 然后,信号门会关闭,不再接受任何新事件。Then the gate closes and no longer accepts any new events.

示例示意图:Example diagram:

示意图显示了最大激活,即 N 个事件来自一个源。

  • 录制持续时间 = -偏移量 + maximumActivationTimeDuration of recording = -offset + maximumActivationTime

重要

前面的示意图假定每个事件到达的物理时间和媒体时间相同。The preceding diagrams assume that every event arrives at the same instant in physical time and media time. 也就是说,假设它们没有延迟到达。That is, they assume that there are no late arrivals.

后续步骤Next steps

尝试使用基于事件的视频录制教程Try out the Event-based video recording tutorial. 从编辑 topology.json 开始。Start by editing the topology.json. 修改 signalgateProcessor 节点的参数,然后按照本教程其余部分的说明进行操作。Modify the parameters for the signalgateProcessor node, and then follow the rest of the tutorial. 查看视频录制,分析参数的效果。Review the video recordings to analyze the effect of the parameters.