管理资产Manage assets

在 Azure 媒体服务的资产中可执行以下操作:In Azure Media Services, an Asset is where you

  • 将媒体文件上传到资产;upload media files into an asset,
  • 将实时传送流引入和存档到资产;ingest and archive live streams into an asset,
  • 将编码作业的结果输出到资产;output the results of an encoding job to an asset,
  • 发布媒体以进行流式处理;publish media for streaming,
  • 从资产中下载文件。download files from an asset.

本主题概述如何将文件上传到资产,以及如何执行其他一些常见操作。This topic gives an overview of how to upload files into an asset and perform some other common operations. 此外,提供了代码示例和相关主题的链接。It also provides links to code samples and related topics.

先决条件Prerequisite

在开始开发之前,请查看:Before you start developing, review:

将媒体文件上传到资产Upload media files into an asset

将数字文件上传到存储中并与资产关联后,即可将其用于媒体服务编码、流式传输内容工作流。After the digital files are uploaded into storage and associated with an Asset, they can be used in the Media Services encoding, streaming content workflows. 一个常见的媒体服务工作流是上传、编码和流式传输文件。One of the common Media Services workflows is to upload, encode, and stream a file. 本部分概述常规步骤。This section outlines the general steps.

  1. 使用媒体服务 v3 API 创建新的“输入”资产。Use the Media Services v3 API to create a new "input" Asset. 此操作在与媒体服务帐户关联的存储帐户中创建一个容器。This operation creates a container in the storage account associated with your Media Services account. API 返回容器名称(例如 "container": "asset-b8d8b68a-2d7f-4d8c-81bb-8c7bbbe67ee4")。The API returns the container name (for example, "container": "asset-b8d8b68a-2d7f-4d8c-81bb-8c7bbbe67ee4").

    如果已有一个要与资产关联的 Blob 容器,则可以在创建资产时指定容器名称。If you already have a blob container that you want to associate with an Asset, you can specify the container name when you create the Asset. 媒体服务目前仅支持容器根中的 Blob,而不支持在文件名中输入路径。Media Services currently only supports blobs in the container root and not with paths in the file name. 因此,使用文件名“input.mp4”的容器是有效的。Thus, a container with the "input.mp4" file name will work. 但是,使用文件名“videos/inputs/input.mp4”的容器是无效的。However, a container with the "videos/inputs/input.mp4" file name won't work.

    可以使用 Azure CLI 直接上传到订阅中你有权访问的任何存储帐户和容器。You can use the Azure CLI to upload directly to any storage account and container that you have rights to in your subscription.

    容器名称必须唯一,并遵循存储命名准则。The container name must be unique and follow storage naming guidelines. 该名称不一定要遵循媒体服务资产容器名称(资产 GUID)的格式。The name doesn't have to follow the Media Services Asset container name (Asset-GUID) formatting.

    az storage blob upload -f /path/to/file -c MyContainer -n MyBlob
    
  2. 获取具有读写权限的 SAS URL,用于将数字文件上传到资产容器。Get a SAS URL with read-write permissions that will be used to upload digital files into the Asset container.

    可以使用媒体服务 API 列出资产容器 URLYou can use the Media Services API to list the asset container URLs.

    AssetContainerSas.listContainerSas 采用 ListContainerSasInput 参数,在此参数中可以设置 expiryTimeAssetContainerSas.listContainerSas takes a ListContainerSasInput parameter on which you set expiryTime. 时间应设置为小于 24 小时。The time should be set to < 24 hours.

    ListContainerSasInput 返回多个 SAS URL,因为每个存储帐户有两个存储帐户密钥。ListContainerSasInput returns multiple SAS URLs as there are two storage account keys for each storage account. 存储帐户具有两个密钥,因为这样有助于进行故障转移和无缝轮换存储帐户密钥。A storage account has two keys because it helps with failover and seamless rotation of storage account keys. 第一个 SAS URL 表示第一个存储帐户密钥,第二个 SAS URL 表示第二个密钥。The first SAS URL represents the first storage account key and the second SAS URL represents the second key.

  3. 使用 Azure 存储 API 或 SDK(例如,存储 REST API.NET SDK)将文件上传到资产容器。Use the Azure Storage APIs or SDKs (for example, the Storage REST API or .NET SDK) to upload files into the Asset container.

  4. 使用媒体服务 v3 API 创建用于处理“输入”资产的转换和作业。Use Media Services v3 APIs to create a Transform and a Job to process your "input" Asset. 有关详细信息,请参阅转换和作业For more information, see Transforms and Jobs.

  5. 从“输出”资产流式传输内容。Stream the content from the "output" asset.

创建新资产Create a new asset

备注

属于日期/时间类型的资产的属性始终采用 UTC 格式。An Asset's properties of the Datetime type are always in UTC format.

RESTREST

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

有关 REST 示例,请参阅使用 REST 创建资产示例。For a REST example, see the Create an Asset with REST example.

该示例演示如何创建请求正文,在该正文中可以指定说明、容器名称、存储帐户和其他有用信息。The example shows how to create the Request Body where you can specify description, container name, storage account, and other useful info.

cURLcURL

curl -X PUT \
  'https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-000000000000/resourceGroups/resourceGroupName/providers/Microsoft.Media/mediaServices/amsAccountName/assets/myOutputAsset?api-version=2018-07-01' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "properties": {
    "description": "",
  }
}'

.NET.NET

 Asset asset = await client.Assets.CreateOrUpdateAsync(resourceGroupName, accountName, assetName, new Asset());

另请参阅See also

将实时传送流引入和存档到资产Ingest and archive live streams into an asset

在媒体服务中,实时输出对象类似于数字视频录制器,它会捕获实时流并将其记录到媒体服务帐户中的某个资产内。In Media Services, a Live Output object is like a digital video recorder that will catch and record your live stream into an asset in your Media Services account. 记录的内容保存在资产资源定义的容器中。The recorded content is persisted into the container defined by the Asset resource.

有关详细信息,请参阅:For more information, see:

将作业结果输出到资产Output the results of a job to an asset

在媒体服务中,处理视频(例如编码)时,需要创建一个输出资产来存储作业结果。In Media Services, when processing your videos (for example, encoding) you need to create an output asset to store the result of your job.

有关详细信息,请参阅:For more information, see:

发布资产以进行流式处理Publish an asset for streaming

若要发布资产以进行流式处理,需要创建一个流定位符To publish an asset for streaming, you need to create a Streaming Locator. 流定位符需要知道所要发布的资产名称。The streaming locator needs to know the asset name that you want to publish.

有关详细信息,请参阅:For more information, see:

教程:使用媒体服务 v3 上传、编码和流式传输视频Tutorial: Upload, encode, and stream videos with Media Services v3

从输出资产中下载作业结果Download results of a job from an output asset

然后,可以使用媒体服务和存储 API 将作业结果下载到本地文件夹。You can then download these results of your job to a local folder using Media Service and Storage APIs.

请参阅下载文件示例。See the download files example.

筛选、排序、分页Filtering, ordering, paging

请参阅媒体服务实体的筛选、排序、分页See Filtering, ordering, paging of Media Services entities.

后续步骤Next steps

查看演示如何上传、编码、流式传输实时流和点播流的完整代码示例:See the full code examples that demonstrate how to upload, encode, stream live and on-demand: