使用媒体服务 REST API 创建筛选器Creating filters with Media Services REST API

将内容传送到客户(直播流活动或点播视频)时,客户端所需的灵活性可能比默认资产的清单文件中描述的灵活性更高。When delivering your content to customers (streaming Live 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 enables you to define account filters and asset filters for your content.

有关此功能及其使用方案的详细说明,请参阅动态清单筛选器For detailed description of this feature and scenarios where it is used, see Dynamic Manifests and Filters.

本主题展示了如何为点播视频资产定义筛选器,以及如何使用 REST API 创建帐户筛选器资产筛选器This topic shows how to define a filter for a Video on Demand asset and use REST APIs to create Account Filters and Asset Filters.

备注

请确保查看 presentationTimeRangeMake sure to review presentationTimeRange.

必备条件Prerequisites

若要完成本主题中所述的步骤,必须:To complete the steps described in this topic, you have to:

定义筛选器Define a filter

下面是请求正文示例,其中定义了添加到清单的曲目择条件。The following is the Request body example that defines the track selection conditions that are added to the manifest. 此筛选器包括属于 EC-3 的任何音频曲目和比特率在 0-1000000 范围内的任何视频曲目。This filter includes any audio tracks that are EC-3 and any video tracks that have bitrate in the 0-1000000 range.

{
    "properties": {
        "tracks": [
          {
                "trackSelections": [
                    {
                        "property": "Type",
                        "value": "Audio",
                        "operation": "Equal"
                    },
                    {
                        "property": "FourCC",
                        "value": "EC-3",
                        "operation": "Equal"
                    }
                ]
            },
            {
                "trackSelections": [
                    {
                        "property": "Type",
                        "value": "Video",
                        "operation": "Equal"
                    },
                    {
                        "property": "Bitrate",
                        "value": "0-1000000",
                        "operation": "Equal"
                    }
                ]
            }
        ]
     }
}

创建帐户筛选器Create account filters

在你下载的 Postman 的集合中,选择“帐户筛选器”->“创建或更新帐户筛选器”。In the Postman's collection that you downloaded, select Account Filters->Create or update an Account Filter.

PUT HTTP 请求方法类似于:The PUT HTTP request method is similar to:

PUT https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/accountFilters/{filterName}?api-version=2018-07-01

选择“正文” 选项卡并粘贴你之前定义的 json 代码。Select the Body tab and paste the json code you defined earlier.

选择“发送”。 Select Send.

筛选器已创建。The filter has been created.

有关详细信息,请参阅创建或更新For more information, see Create or update. 此外,请参阅筛选器的 JSON 示例Also, see JSON examples for filters.

创建资产筛选器Create asset filters

在已下载的“媒体服务 v3”Postman 集合中,选择“资产” ->“创建或更新资产筛选器” 。In the "Media Services v3" Postman collection that you downloaded, select Assets->Create or update Asset Filter.

PUT HTTP 请求方法类似于:The PUT HTTP request method is similar to:

PUT https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/assets/{assetName}/assetFilters/{filterName}?api-version=2018-07-01

选择“正文” 选项卡并粘贴你之前定义的 json 代码。Select the Body tab and paste the json code you defined earlier.

选择“发送”。 Select Send.

资产筛选器已创建。The asset filter has been created.

有关如何创建或更新资产筛选器的详细信息,请参阅创建或更新For details on how to create or update asset filters, see Create or update. 此外,请参阅筛选器的 JSON 示例Also, see JSON examples for filters.

将筛选器与流定位器关联Associate filters with Streaming Locator

可以指定资产或帐户筛选器的列表,这些筛选器将应用于流定位器。You can specify a list of asset or account filters, which would apply to your Streaming Locator. 动态打包程序(流式处理终结点)将此筛选器列表与客户端在 URL 中指定的筛选器一起应用。The Dynamic Packager (Streaming Endpoint) 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 Streaming Locator. 如果要应用筛选器,但不希望在 URL 中公开筛选器名称,建议使用此功能。We recommend that you use this feature if you want to apply filters but do not want to expose the filter names in the URL.

若要使用 REST 创建筛选器并将其与流定位器关联,请使用流定位器 - 创建 API并在请求正文中指定 properties.filtersTo create and associate filters with a Streaming Locator using REST, use the Streaming Locators - Create API and specify properties.filters in the Request Body.

使用筛选器的流Stream using filters

定义筛选器后,客户端可以在流式 URL 中使用它们。Once you define filters, your clients could use them in the streaming URL. 筛选器可应用到自适应比特率流式处理协议:Apple HTTP Live Streaming (HLS)、MPEG-DASH 和平滑流式处理。Filters could be applied to adaptive bitrate streaming protocols: Apple HTTP Live Streaming (HLS), MPEG-DASH, and Smooth Streaming.

下表显示了一些包含筛选器的 URL 示例:The following table shows some examples of URLs with filters:

协议Protocol 示例Example
HLSHLS https://amsv3account-cne21.streaming.media.chinacloudapi.cn/fecebb23-46f6-490d-8b70-203e86b0df58/bigbuckbunny.ism/manifest(format=m3u8-aapl,filter=myAccountFilter)
MPEG DASHMPEG DASH https://amsv3account-cne21.streaming.media.chinacloudapi.cn/fecebb23-46f6-490d-8b70-203e86b0df58/bigbuckbunny.ism/manifest(format=mpd-time-csf,filter=myAssetFilter)
平滑流Smooth Streaming https://amsv3account-cne21.streaming.media.chinacloudapi.cn/fecebb23-46f6-490d-8b70-203e86b0df58/bigbuckbunny.ism/manifest(filter=myAssetFilter)

后续步骤Next steps

流视频Stream videos