筛选器Filters

将内容传送到客户(实时传送视频流事件或点播视频)时,客户端所需的灵活性可能比默认资产的清单文件中描述的灵活性更高。When delivering your content to customers (Live Streaming events or Video on Demand) your client might need more flexibility than what's described in the default asset's manifest file. Azure 媒体服务根据预定义的筛选器提供动态清单Azure Media Services offers Dynamic Manifests based on pre-defined filters.

筛选器是服务器端的规则,可让客户执行以下操作:Filters are server-side rules that allow your customers to do things like:

  • 仅播放视频的某个部分(而不是整个视频)。Play back only a section of a video (instead of playing the whole video). 例如:For example:
    • 缩小清单以显示直播活动的子剪辑(“子剪辑筛选”),或Reduce the manifest to show a sub-clip of a live event ("sub-clip filtering"), or
    • 修剪视频开头(“修剪视频”)。Trim the start of a video ("trimming a video").
  • 只传送内容播放设备所支持的指定再现内容和/或指定的语言轨道(“再现内容筛选”)。Deliver only the specified renditions and/or specified language tracks that are supported by the device that is used to play back the content ("rendition filtering").
  • 调整演播窗口,以便在播放器中提供长度有限的 DVR 窗口(“调整演播窗口”)。Adjust Presentation Window (DVR) in order to provide a limited length of the DVR window in the player ("adjusting presentation window").

使用媒体服务可为内容创建帐户筛选器资产筛选器Media Services enables you to create Account filters and Asset filters for your content. 此外,可将预先创建的筛选器关联到流定位符In addition, you can associate your pre-created filters with a Streaming Locator.

定义筛选器Defining filters

有两种类型的筛选器:There are two types of filters:

  • 帐户筛选器(全局)- 可应用到 Azure 媒体服务帐户中所有的资产,生存期与帐户相同。Account Filters (global) - can be applied to any asset in the Azure Media Services account, have a lifetime of the account.
  • 资产筛选器(本地)- 在创建后只能应用到与筛选器关联的资产,生存期与资产相同。Asset Filters (local) - can only be applied to an asset with which the filter was associated upon creation, have a lifetime of the asset.

帐户筛选器资产筛选器类型的用于定义/描述筛选器的属性完全相同。Account Filters and Asset Filters types have exactly the same properties for defining/describing the filter. 需要指定要与筛选器关联的资产名称,但创建资产筛选器时除外。Except when creating the Asset Filter, you need to specify the asset name with which you want to associate the filter.

根据具体的方案确定哪种类型的筛选器更合适(资产筛选器或帐户筛选器)。Depending on your scenario, you decide what type of a filter is more suitable (Asset Filter or Account Filter). 帐户筛选器适用于设备配置文件(再现内容筛选),而资产筛选器可用于修剪特定的资产。Account Filters are suitable for device profiles (rendition filtering) where Asset Filters could be used to trim a specific asset.

使用以下属性来描述筛选器。You use the following properties to describe the filters.

名称Name 说明Description
firstQualityfirstQuality 筛选器的第一个质量比特率。The first quality bitrate of the filter.
presentationTimeRangepresentationTimeRange 呈现时间范围。The presentation time range. 此属性用于筛选清单起点/终点、呈现窗口长度和直播起始位置。This property is used for filtering manifest start/end points, presentation window length, and the live start position.
有关详细信息,请参阅 PresentationTimeRangeFor more information, see PresentationTimeRange.
trackstracks 轨迹选择条件。The tracks selection conditions. 有关详细信息,请参阅轨迹For more information, see tracks

presentationTimeRangepresentationTimeRange

请将此属性用于资产筛选器Use this property with Asset Filters. 不建议对帐户筛选器设置该属性。It is not recommended to set the property with Account Filters.

名称Name 说明Description
endTimestampendTimestamp 适用于点播视频 (VoD)。Applies to Video on Demand (VoD).
对于实时传送视频流演播,将以静默方式忽略该属性;当呈现内容结束并且流变为 VoD 时,将应用该属性。For the Live Streaming presentation, it is silently ignored and applied when the presentation ends and the stream becomes VoD.
这是一个长值,表示演播的绝对终点,舍入为最接近的下一个 GOP 起点。This is a long value that represents an absolute end point of the presentation, rounded to the closest next GOP start. 单位是时间刻度,endTimestamp 1800000000 表示 3 分钟。The unit is the timescale, so an endTimestamp of 1800000000 would be for 3 minutes.
使用 startTimestamp 和 endTimestamp 来修剪将播放列表(清单)中的片段。Use startTimestamp and endTimestamp to trim the fragments that will be in the playlist (manifest).
例如,在使用默认时间刻度的情况下指定 startTimestamp=40000000 和 endTimestamp=100000000 会生成一个播放列表,其中包含 VoD 演播内容第 4 秒到第 10 秒的片段。For example, startTimestamp=40000000 and endTimestamp=100000000 using the default timescale will generate a playlist that contains fragments from between 4 seconds and 10 seconds of the VoD presentation. 如果某个段跨越边界,则整个段将包含在清单中。If a fragment straddles the boundary, the entire fragment will be included in the manifest.
forceEndTimestampforceEndTimestamp 仅适用于实时传送视频流。Applies to Live Streaming only.
指示 endTimestamp 属性是否必须存在。Indicates whether the endTimestamp property must be present. 如果为 true,则必须指定 endTimestamp,否则会返回“错误的请求”代码。If true, endTimestamp must be specified or a bad request code is returned.
允许的值:false、true。Allowed values: false, true.
liveBackoffDurationliveBackoffDuration 仅适用于实时传送视频流。Applies to Live Streaming only.
此值定义客户端可以搜寻的最新实时位置。This value defines the latest live position that a client can seek to.
使用此属性可以延迟直播播放位置,并为播放器创建服务器端缓冲区。Using this property, you can delay live playback position and create a server-side buffer for players.
此属性的单位为时间刻度(参阅下文)。The unit for this property is timescale (see below).
最大直播回退持续时间为 300 秒 (3000000000)。The maximum live back off duration is 300 seconds (3000000000).
例如,值 2000000000 表示最新可用内容从实际实时边缘延迟 20 秒。For example, a value of 2000000000 means that the latest available content is 20 seconds delayed from the real live edge.
presentationWindowDurationpresentationWindowDuration 仅适用于实时传送视频流。Applies to Live Streaming only.
使用 presentationWindowDuration 对要包含在播放列表中的片段应用滑动窗口。Use presentationWindowDuration to apply a sliding window of fragments to include in a playlist.
此属性的单位为时间刻度(参阅下文)。The unit for this property is timescale (see below).
例如,设置 presentationWindowDuration=1200000000 会应用 2 分钟的滑动窗口。For example, set presentationWindowDuration=1200000000 to apply a two-minute sliding window. 直播边缘 2 分钟内的媒体将包含在播放列表中。Media within 2 minutes of the live edge will be included in the playlist. 如果某个段跨越边界,则整个段将包含在播放列表中。If a fragment straddles the boundary, the entire fragment will be included in the playlist. 最小呈现窗口持续时间为 60 秒。The minimum presentation window duration is 60 seconds.
startTimestampstartTimestamp 适用于点播视频 (VoD) 或实时传送视频流。Applies to Video on Demand (VoD) or Live Streaming.
这是一个长值,表示流的绝对起点。This is a long value that represents an absolute start point of the stream. 该值将舍入为最接近的下一个 GOP 起点。The value gets rounded to the closest next GOP start. 单位是时间刻度,startTimestamp 150000000 表示 15 秒。The unit is the timescale, so a startTimestamp of 150000000 would be for 15 seconds.
使用 startTimestamp 和 endTimestampp 来修剪将播放列表(清单)中的片段。Use startTimestamp and endTimestampp to trim the fragments that will be in the playlist (manifest).
例如,在使用默认时间刻度的情况下指定 startTimestamp=40000000 和 endTimestamp=100000000 会生成一个播放列表,其中包含 VoD 演播内容第 4 秒到第 10 秒的片段。For example, startTimestamp=40000000 and endTimestamp=100000000 using the default timescale will generate a playlist that contains fragments from between 4 seconds and 10 seconds of the VoD presentation. 如果某个段跨越边界,则整个段将包含在清单中。If a fragment straddles the boundary, the entire fragment will be included in the manifest.
timescaletimescale 适用于演播时间范围内的所有时间戳和持续时间,指定为一秒中的增量数。Applies to all timestamps and durations in a Presentation Time Range, specified as the number of increments in one second.
默认值为 10000000 - 一秒中有 1000 万个增量,每个增量的长度为 100 纳秒。Default is 10000000 - ten million increments in one second, where each increment would be 100 nanoseconds long.
例如,若要将 startTimestamp 设置为 30 秒,则在使用默认时间刻度时,需使用值 300000000。For example, if you want to set a startTimestamp at 30 seconds, you would use a value of 300000000 when using the default timescale.

轨迹Tracks

指定筛选器轨迹属性条件 (FilterTrackPropertyConditions) 的列表,应该根据该列表将流(实时传送视频流或点播视频)的轨迹包含到动态创建的清单中。You specify a list of filter track property conditions (FilterTrackPropertyConditions) based on which the tracks of your stream (Live Streaming or Video on Demand) should be included into dynamically created manifest. 使用逻辑 ANDOR 运算来组合筛选器。The filters are combined using a logical AND and OR operation.

筛选器轨迹属性条件描述轨迹类型、值(如下表所述)和运算(Equal、NotEqual)。Filter track property conditions describe track types, values (described in the following table), and operations (Equal, NotEqual).

名称Name 说明Description
BitrateBitrate 使用轨迹的比特率进行筛选。Use the bitrate of the track for filtering.

建议的值为一系列比特率,以比特/秒为单位。The recommended value is a range of bitrates, in bits per second. 例如“0-2427000”。For example, "0-2427000".

注意:尽管可以使用特定的比特率值(例如 250000 比特/秒),但不建议使用此方法,因为确切的比特率可能根据资产的不同而波动。Note: while you can use a specific bitrate value, like 250000 (bits per second), this approach is not recommended, as the exact bitrates can fluctuate from one Asset to another.
FourCCFourCC 使用轨迹的 FourCC 值进行筛选。Use the FourCC value of the track for filtering.

该值是 RFC 6381 中指定的编解码器格式的第一个元素。The value is the first element of codecs format, as specified in RFC 6381. 目前支持以下编解码器:Currently, the following codecs are supported:
视频:“avc1”、“hev1”、“hvc1”For Video: "avc1", "hev1", "hvc1"
音频:“mp4a”、“ec-3”For Audio: "mp4a", "ec-3"

若要确定资产中轨迹的 FourCC 值,请获取并检查清单文件。To determine the FourCC values for tracks in an Asset, get and examine the manifest file.
语言Language 使用轨迹的语言进行筛选。Use the language of the track for filtering.

该值是 RFC 5646 中指定的、要包含的语言的标记。The value is the tag of a language you want to include, as specified in RFC 5646. 例如,“en”。For example, "en".
名称Name 使用轨迹的名称进行筛选。Use the name of the track for filtering.
类型 Type 使用轨迹的类型进行筛选。Use the type of the track for filtering.

允许以下值:“video”、“audio”或“text”。The following values are allowed: "video", "audio", or "text".

示例Example

以下示例定义实时传送视频流筛选器:The following example defines a Live Streaming filter:

{
  "properties": {
    "presentationTimeRange": {
      "startTimestamp": 0,
      "endTimestamp": 170000000,
      "presentationWindowDuration": 9223372036854776000,
      "liveBackoffDuration": 0,
      "timescale": 10000000,
      "forceEndTimestamp": false
    },
    "firstQuality": {
      "bitrate": 128000
    },
    "tracks": [
      {
        "trackSelections": [
          {
            "property": "Type",
            "operation": "Equal",
            "value": "Audio"
          },
          {
            "property": "Language",
            "operation": "NotEqual",
            "value": "en"
          },
          {
            "property": "FourCC",
            "operation": "NotEqual",
            "value": "EC-3"
          }
        ]
      },
      {
        "trackSelections": [
          {
            "property": "Type",
            "operation": "Equal",
            "value": "Video"
          },
          {
            "property": "Bitrate",
            "operation": "Equal",
            "value": "3000000-5000000"
          }
        ]
      }
    ]
  }
}

将筛选器与流定位符相关联Associating filters with Streaming Locator

可以在流定位符中指定资产或帐户筛选器列表。You can specify a list of asset or account filters on your Streaming Locator. 动态打包器将此筛选器列表与客户端在 URL 中指定的筛选器一起应用。The Dynamic Packager applies this list of filters together with those your client specifies in the URL. 此组合将生成动态清单,该清单基于你在流定位符上指定的“URL + 筛选器”中的筛选器。This combination generates a Dynamic Manifest, which is based on filters in the URL + filters you specify on the Streaming Locator.

请看以下示例:See the following examples:

更新筛选器Updating filters

尽管筛选器可更新,但流定位符不可更新。Streaming Locators are not updatable while filters can be updated.

不建议更新与实际发布的流定位符关联的筛选器的定义。It is not recommended to update the definition of filters associated with an actively published Streaming Locator. 流式处理服务器可能有内部缓存,这可能会导致返回过时的缓存数据。Streaming servers can have internal caches that may result in stale cached data to be returned.

如果需要更改筛选器定义,请考虑创建一个新的筛选器,并将其添加到流定位符 URL,或发布直接引用筛选器的新流定位符If the filter definition needs to be changed consider creating a new filter and adding it to the Streaming Locator URL or publishing a new Streaming Locator that references the filter directly.

后续步骤Next steps

以下文章介绍了如何以编程方式创建筛选器。The following articles show how to create filters programmatically.