使用 CLI 创建筛选器Creating filters with CLI

媒体服务徽标 v3media services logo v3


将内容传送到客户(直播流活动或点播视频)时,客户端所需的灵活性可能比默认资产的清单文件中描述的灵活性更高。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.

本主题说明如何为点播视频资产配置筛选器,并使用适用于媒体服务 v3 的 CLI 创建帐户筛选器资产筛选器This topic shows how to configure a filter for a Video on-Demand asset and use CLI for Media Services v3 to create Account Filters and Asset Filters.

备注

请确保查看 presentationTimeRangeMake sure to review presentationTimeRange.

必备条件Prerequisites

定义筛选器Define a filter

以下示例定义添加到最终清单的曲目择条件。The following example defines the track selection conditions that are added to the final 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.

提示

如果计划在 REST 中定义 筛选器,请注意需要包括“Properties”包装器 JSON 对象。If you plan to define Filters in REST, notice that you need to include the "Properties" wrapper JSON object.

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

创建帐户筛选器Create account filters

以下 az ams account-filter 命令创建帐户筛选器,其中包含之前定义的筛选器曲目选项。The following az ams account-filter command creates an account filter with filter track selections that were defined earlier.

该命令允许你传递一个可选 --tracks 参数,该参数包含表示曲目选择的 JSON。The command allows you to pass an optional --tracks parameter that contains JSON representing the track selections. 使用 @{file} 从文件加载 JSON,请指定整个文件路径:Use @{file} to load JSON from a file, specify the whole file path:

az ams account-filter create -a amsAccount -g resourceGroup -n filterName --tracks @tracks.json

此外,请参阅筛选器的 JSON 示例Also, see JSON examples for filters.

创建资产筛选器Create asset filters

以下 az ams asset-filter 命令创建资产筛选器,其中包含之前定义的筛选器曲目选项。The following az ams asset-filter command creates an asset filter with filter track selections that were defined earlier.

az ams asset-filter create -a amsAccount -g resourceGroup -n filterName --asset-name assetName --tracks @tracks.json

此外,请参阅筛选器的 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.

以下 CLI 代码显示了如何创建流定位器并指定 filtersThe following CLI code shows how to create a Streaming Locator and specify filters. 这是一个可选属性,它采用以空格分隔的资产筛选器名称和/或帐户筛选器名称的列表。This is an optional property that takes a space-separated list of asset filter names and/or account filter names.

az ams streaming-locator create -a amsAccount -g resourceGroup -n streamingLocatorName \
                                --asset-name assetName \                               
                                --streaming-policy-name policyName \
                                --filters filterName1 filterName2
                                

使用筛选器的流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 step

流视频Stream videos

另请参阅See also

Azure CLIAzure CLI