使用 REST 发布 Azure 媒体服务内容Publish Azure Media Services content using REST

可以通过创建 OnDemand 流式处理定位符并生成流 URL 来流式传输自适应比特率 MP4 集。You can stream an adaptive bitrate MP4 set by creating an OnDemand streaming locator and building a streaming URL. 对资产进行编码一文说明了如何编码成自适应比特率 MP4 集。The encoding an asset article shows how to encode into an adaptive bitrate MP4 set. 如果内容已加密,则在创建定位符之前配置资产传送策略(如此文中所述)。If your content is encrypted, configure asset delivery policy (as described in this article) before creating a locator.

也可以使用 OnDemand 流式处理定位符生成指向可渐进式下载的 MP4 文件的 URL。You can also use an OnDemand streaming locator to build URLs that point to MP4 files that can be progressively downloaded.

本文说明如何创建 OnDemand 流式处理定位符,以发布资产及生成平滑流、MPEG DASH 和 HLS 流式处理 URL。This article shows how to create an OnDemand streaming locator in order to publish your asset and build a Smooth, MPEG DASH, and HLS streaming URLs. 此外,还会演示如何生成渐进式下载 URL。It also shows how to build progressive download URLs.

以下部分显示了其值会在 REST 调用中使用的枚举类型。The following section shows the enum types whose values are used in the REST calls.

备注

访问媒体服务中的实体时,必须在 HTTP 请求中设置特定标头字段和值。When accessing entities in Media Services, you must set specific header fields and values in your HTTP requests. 有关详细信息,请参阅媒体服务 REST API 开发的设置For more information, see Setup for Media Services REST API Development.

连接到媒体服务Connect to Media Services

若要了解如何连接到 AMS API,请参阅通过 Azure AD 身份验证访问 Azure 媒体服务 APIFor information on how to connect to the AMS API, see Access the Azure Media Services API with Azure AD authentication.

备注

成功连接到 https://media.chinacloudapi.cn 后,将收到指定另一个媒体服务 URI 的 301 重定向。After successfully connecting to https://media.chinacloudapi.cn, you will receive a 301 redirect specifying another Media Services URI. 必须对这个新 URI 进行后续调用。You must make subsequent calls to the new URI.

创建 OnDemand 流式处理定位符Create an OnDemand streaming locator

要创建 OnDemand 流式处理定位符并获取 URL,需要执行以下操作:To create the OnDemand streaming locator and get URLs, you need to do the following:

  1. 如果内容已加密,则定义访问策略。If the content is encrypted, define an access policy.

  2. 创建 OnDemand 流式处理定位符。Create an OnDemand streaming locator.

  3. 如果想要流式处理,请获取资产中的流式处理清单文件 (.ism)。If you plan to stream, get the streaming manifest file (.ism) in the asset.

    如果想要渐进式下载,请获取资产中的 MP4 文件名。If you plan to progressively download, get the names of MP4 files in the asset.

  4. 生成清单文件或 MP4 文件的 URL。Build URLs to the manifest file or MP4 files.

  5. 无法使用包含写入或删除权限的 AccessPolicy 创建流式处理定位符。You cannot create a streaming locator using an AccessPolicy that includes write or delete permissions.

创建访问策略Create an access policy

备注

不同 AMS 策略的策略限制为 1,000,000 个(例如,对于定位器策略或 ContentKeyAuthorizationPolicy)。There is a limit of 1,000,000 policies for different AMS policies (for example, for Locator policy or ContentKeyAuthorizationPolicy). 如果始终使用相同的日期/访问权限,请使用相同的策略 ID,例如,用于要长期就地保留的定位符的策略(非上传策略)。Use the same policy ID if you are always using the same days / access permissions, for example, policies for locators that are intended to remain in place for a long time (non-upload policies). 有关详细信息,请参阅文章。For more information, see this article.

请求:Request:

POST https://media.chinacloudapi.cn/api/AccessPolicies HTTP/1.1
Content-Type: application/json
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json
Accept-Charset: UTF-8
Authorization: Bearer <ENCODED JWT TOKEN> 
x-ms-version: 2.19
x-ms-client-request-id: 6bcfd511-a561-448d-a022-a319a89ecffa
Host: media.chinacloudapi.cn
Content-Length: 68

{"Name":"access policy","DurationInMinutes":43200.0,"Permissions":1}

响应:Response:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 311
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Location: https:/media.chinacloudapi.cn/api/AccessPolicies('nb%3Apid%3AUUID%3A69c80d98-7830-407f-a9af-e25f4b0d3e5f')
Server: Microsoft-IIS/8.5
request-id: a877528a-bdb4-4414-9862-273f8e64f882
x-ms-request-id: a877528a-bdb4-4414-9862-273f8e64f882
x-ms-client-request-id: 6bcfd511-a561-448d-a022-a319a89ecffa
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Wed, 18 Feb 2015 06:52:09 GMT

{"odata.metadata":"https://media.chinacloudapi.cn/api/$metadata#AccessPolicies/@Element","Id":"nb:pid:UUID:69c80d98-7830-407f-a9af-e25f4b0d3e5f","Created":"2015-02-18T06:52:09.8862191Z","LastModified":"2015-02-18T06:52:09.8862191Z","Name":"access policy","DurationInMinutes":43200.0,"Permissions":1}

创建 OnDemand 流式处理定位符Create an OnDemand streaming locator

创建指定资产和资产策略的定位符。Create the locator for the specified asset and asset policy.

请求:Request:

POST https://media.chinacloudapi.cn/api/Locators HTTP/1.1
Content-Type: application/json
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json
Accept-Charset: UTF-8
Authorization: Bearer <ENCODED JWT TOKEN> 
x-ms-version: 2.19
x-ms-client-request-id: ac159492-9a0c-40c3-aacc-551b1b4c5f62
Host: media.chinacloudapi.cn
Content-Length: 181

{"AccessPolicyId":"nb:pid:UUID:1480030d-c481-430a-9687-535c6a5cb272","AssetId":"nb:cid:UUID:cc1e445d-1500-80bd-538e-f1e4b71b465e","StartTime":"2015-02-18T06:34:47.267872Z","Type":2}

响应:Response:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 637
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Location: https://media.chinacloudapi.cn/api/Locators('nb%3Alid%3AUUID%3Abe245661-2bbd-4fc6-b14f-9cf9a1492e5e')
Server: Microsoft-IIS/8.5
request-id: 5bd5864a-0afd-44c0-a67a-4044a2c9043b
x-ms-request-id: 5bd5864a-0afd-44c0-a67a-4044a2c9043b
x-ms-client-request-id: ac159492-9a0c-40c3-aacc-551b1b4c5f62
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Wed, 18 Feb 2015 06:58:37 GMT

{"odata.metadata":"https://media.chinacloudapi.cn/api/$metadata#Locators/@Element","Id":"nb:lid:UUID:be245661-2bbd-4fc6-b14f-9cf9a1492e5e","ExpirationDateTime":"2015-03-20T06:34:47.267872+00:00","Type":2,"Path":"https://amstest1.streaming.mediaservices.chinacloudapi.cn/be245661-2bbd-4fc6-b14f-9cf9a1492e5e/","BaseUri":"https://amstest1.streaming.mediaservices.chinacloudapi.cn","ContentAccessComponent":"be245661-2bbd-4fc6-b14f-9cf9a1492e5e","AccessPolicyId":"nb:pid:UUID:1480030d-c481-430a-9687-535c6a5cb272","AssetId":"nb:cid:UUID:cc1e445d-1500-80bd-538e-f1e4b71b465e","StartTime":"2015-02-18T06:34:47.267872+00:00","Name":null}

生成流 URLBuild streaming URLs

使用创建定位符后返回的路径值生成平滑流式处理、HLS 和 MPEG DASH URL。Use the Path value returned after the creation of the locator to build the Smooth, HLS, and MPEG DASH URLs.

平滑流式处理:路径 + 清单文件名 +“/manifest”Smooth Streaming: Path + manifest file name + "/manifest"

示例:example:

https://amstest1.streaming.mediaservices.chinacloudapi.cn/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest

HLS:路径 + 清单文件名 +“/manifest(format=m3u8-aapl)”HLS: Path + manifest file name + "/manifest(format=m3u8-aapl)"

示例:example:

https://amstest1.streaming.mediaservices.chinacloudapi.cn/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=m3u8-aapl)

DASH:路径 + 清单文件名 +“/manifest(format=mpd-time-csf)”DASH: Path + manifest file name + "/manifest(format=mpd-time-csf)"

示例:example:

https://amstest1.streaming.mediaservices.chinacloudapi.cn/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=mpd-time-csf)

生成渐进式下载 URLBuild progressive download URLs

使用创建定位符后返回的路径值生成渐进式下载 URL。Use the Path value returned after the creation of the locator to build the progressive download URL.

URL:路径 + 资产文件 mp4 名称URL: Path + asset file mp4 name

示例:example:

https://amstest1.streaming.mediaservices.chinacloudapi.cn/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_650kbps_AAC_und_ch2_96kbps.mp4

枚举类型Enum types

[Flags]
public enum AccessPermissions
{
    None = 0,
    Read = 1,
    Write = 2,
    Delete = 4,
    List = 8,
}

public enum LocatorType
{
    None = 0,
    Sas = 1,
    OnDemandOrigin = 2,
}

媒体服务学习路径Media Services learning paths

媒体服务 v3(最新版本)Media Services v3 (latest)

查看最新版本的 Azure 媒体服务!Check out the latest version of Azure Media Services!

媒体服务 v2(旧版)Media Services v2 (legacy)

另请参阅See also

媒体服务操作 REST API 概述Media Services operations REST API overview

配置资产传送策略Configure asset delivery policy