使用 Azure 门户按需传送内容入门Get started with delivering content on demand by using the Azure portal

备注

不会向媒体服务 v2 添加任何新特性或新功能。No new features or functionality are being added to Media Services v2.
查看最新版本:媒体服务 v3Check out the latest version, Media Services v3. 另请参阅从 v2 到 v3 的迁移指南Also, see migration guidance from v2 to v3

本教程介绍了在 Azure 门户中使用 Azure 媒体服务应用程序实施基本的视频点播内容传送服务的步骤。This tutorial walks you through the steps of implementing a basic video-on-demand content delivery service with an Azure Media Services application in the Azure portal.

先决条件Prerequisites

以下项目是完成本教程所需具备的条件:The following items are required to complete the tutorial:

本教程包括以下任务:This tutorial includes the following tasks:

  1. 启动流式处理终结点。Start the streaming endpoint.
  2. 上传视频文件。Upload a video file.
  3. 将源文件编码为一组自适应比特率 MP4 文件。Encode the source file into a set of adaptive bitrate MP4 files.
  4. 发布资产并获取流式处理和渐进式下载 URL。Publish the asset, and get streaming and progressive download URLs.
  5. 播放内容。Play your content.

启动流式处理终结点Start the streaming endpoint

使用 Azure 媒体服务时,最常见的场景之一是通过自适应比特率流式处理传送视频。One of the most common scenarios when working with Azure Media Services is delivering video via adaptive bitrate streaming. 可以通过媒体服务进行动态打包。Media Services gives you dynamic packaging. 使用动态打包时,可以按媒体服务所支持的实时流式处理格式传送自适应比特率 MP4 编码内容。With dynamic packaging, you can deliver your adaptive bitrate MP4 encoded content in just-in-time streaming formats that are supported by Media Services. 示例包括 Apple HTTP Live Streaming (HLS)、Microsoft 平滑流式处理,以及经 HTTP 的动态自适应流式处理(DASH,也称 MPEG-DASH)。Examples include Apple HTTP Live Streaming (HLS), Microsoft Smooth Streaming, and Dynamic Adaptive Streaming over HTTP (DASH, also called MPEG-DASH). 使用媒体服务自适应比特率流式处理,不需存储每个此类流式处理格式的预打包版本即可传送视频。By using Media Services adaptive bitrate streaming, you can deliver your videos without storing prepackaged versions of each of these streaming formats.

备注

创建媒体服务帐户后,会将一个处于“已停止”状态的 默认流式处理终结点添加到帐户。When you create your Media Services account, a default streaming endpoint is added to your account in the Stopped state. 若要开始流式传输内容并利用动态打包和动态加密,要从中流式传输内容的流式处理终结点必须处于“正在运行”状态。 To start streaming your content, and to take advantage of dynamic packaging and dynamic encryption, the streaming endpoint from which you want to stream content has to be in the Running state.

若要启动流式处理终结点,请执行以下操作:To start the streaming endpoint:

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 选择“设置” > “流式处理终结点”。Select Settings > Streaming endpoints.
  3. 选择默认的流式处理终结点。Select the default streaming endpoint. 此时会显示“默认流式处理终结点详细信息” 窗口。The DEFAULT STREAMING ENDPOINT DETAILS window appears.
  4. 选择“启动”图标。 Select the Start icon.
  5. 选择“保存”按钮。 Select the Save button.

上传文件Upload files

若要使用媒体服务来流式传输视频,请先上传源视频、将其编码成多个比特率,然后发布结果。To stream videos by using Media Services, you upload the source videos, encode them into multiple bitrates, and then publish the result. 第一步在本部分介绍。The first step is covered in this section.

  1. Azure 门户中,选择 Azure 媒体服务帐户。In the Azure portal, select your Azure Media Services account.

  2. 选择“设置” > “资产” 。Select Settings > Assets. 然后选择“上传”按钮 。Then, select the Upload button.

    上传文件

    此时会显示“上传视频资产” 窗口。The Upload a video asset window appears.

    备注

    媒体服务不会限制上传视频的文件大小。Media Services doesn't limit the file size for uploading videos.

  3. 在计算机上,转到要上传的视频。On your computer, go to the video that you want to upload. 选择视频,然后选择“确定” 。Select the video, and then select OK.

    上传开始。The upload begins. 可以在文件名下看到进度。You can see the progress under the file name.

上传完成后,新资产列在“资产” 窗格中。When the upload is finished, the new asset is listed in the Assets pane.

对资产进行编码Encode assets

要利用动态打包,必须将源文件编码为一组多比特率 MP4 文件。To take advantage of dynamic packaging, you must encode your source file into a set of multi-bitrate MP4 files. 本部分演示编码步骤。The encoding steps are demonstrated in this section.

在门户中对资产进行编码Encode assets in the portal

若要在 Azure 门户中使用 Media Encoder Standard 对内容进行编码,请执行以下操作:To encode your content by using Media Encoder Standard in the Azure portal:

  1. Azure 门户中,选择 Azure 媒体服务帐户。In the Azure portal, select your Azure Media Services account.

  2. 选择“设置” > “资产” 。Select Settings > Assets. 选择要编码的资产。Select the asset that you want to encode.

  3. 选择“编码”按钮 。Select the Encode button.

  4. 在“对资产进行编码”窗格中,选择“Media Encoder Standard”处理器和预设 。In the Encode an asset pane, select the Media Encoder Standard processor and a preset. 有关预设的信息,请参阅自动生成比特率阶梯Media Encoder Standard 的任务预设For information about presets, see Auto-generate a bitrate ladder and Task presets for Media Encoder Standard. 请务必选择最适合输入视频的预设。It's important to choose the preset that will work best for your input video. 例如,如果知道输入视频的分辨率为 1920 × 1080 像素,则可选择“H264 多比特率 1080p”预设 。For example, if you know your input video has a resolution of 1920 × 1080 pixels, you might choose the H264 Multiple Bitrate 1080p preset. 如果视频的分辨率低 (640 × 360),则不应使用“H264 多比特率 1080p”预设 。If you have a low-resolution (640 × 360) video, you shouldn't use the H264 Multiple Bitrate 1080p preset.

    可以编辑输出资产名称和作业名称,以便管理资源。To help you manage your resources, you can edit the name of the output asset and the name of the job.

    对资产进行编码

  5. 选择“创建” 。Select Create.

监视编码作业进度Monitor encoding job progress

若要监视编码作业的进度,请先选择“设置” (位于页面顶部),然后选择“作业” 。To monitor the progress of the encoding job, at the top of the page, select Settings, and then select Jobs.

作业

发布内容Publish content

若要为用户提供一个可用来流式传输内容或下载内容的 URL,首先必须通过创建定位符来发布资产。To provide your user with a URL that they can use to stream or download your content, first you must publish your asset by creating a locator. 定位符提供对资产中文件的访问权限。Locators provide access to files that are in the asset. Azure 媒体服务支持两种类型的定位符:Azure Media Services supports two types of locators:

  • 流式处理 (OnDemandOrigin) 定位符Streaming (OnDemandOrigin) locators. 流式处理定位符用于自适应流式处理。Streaming locators are used for adaptive streaming. 自适应流式处理示例包括:HLS、平滑流式处理和 MPEG-DASH。Examples of adaptive streaming include HLS, Smooth Streaming, and MPEG-DASH. 若要创建流式处理定位符,资产必须包括一个 .ism 文件。To create a streaming locator, your asset must include an .ism file.
  • 渐进式(共享访问签名)定位符Progressive (shared access signature) locators. 渐进式定位符用于通过渐进式下载来传输视频。Progressive locators are used to deliver video via progressive download.

要生成 HLS 流 URL,请将 (format=m3u8-aapl) 附加到 URL: To build an HLS streaming URL, append (format=m3u8-aapl) to the URL:

{streaming endpoint name-media services account name}.streaming.mediaservices.chinacloudapi.cn/{locator ID}/{filename}.ism/Manifest(format=m3u8-aapl)

要生成流式处理 URL 来播放平滑流资产,请使用以下 URL 格式:To build a streaming URL to play Smooth Streaming assets, use the following URL format:

{streaming endpoint name-media services account name}.streaming.mediaservices.chinacloudapi.cn/{locator ID}/{filename}.ism/Manifest

要生成 MPEG DASH 流式处理 URL,请将 (format=mpd-time-csf) 附加到 URL: To build an MPEG-DASH streaming URL, append (format=mpd-time-csf) to the URL:

{streaming endpoint name-media services account name}.streaming.mediaservices.chinacloudapi.cn/{locator ID}/{filename}.ism/Manifest(format=mpd-time-csf)

共享访问签名 URL 格式如下:A shared access signature URL has the following format:

{blob container name}/{asset name}/{file name}/{shared access signature}

备注

2015 年 3 月之前在 Azure 门户中创建的定位符的过期日期为两年后。Locators that were created in the Azure portal before March 2015 have a two-year expiration date.

可以使用 REST API.NET API 来更新定位符的过期日期。To update an expiration date on a locator, you can use a REST API or a .NET API.

备注

更新共享访问签名定位符的过期日期时,URL 会发生变化。When you update the expiration date of a shared access signature locator, the URL changes.

使用门户发布资产To use the portal to publish an asset

  1. Azure 门户中,选择 Azure 媒体服务帐户。In the Azure portal, select your Azure Media Services account.

  2. 选择“设置” > “资产” 。Select Settings > Assets. 选择想要发布的资产。Select the asset that you want to publish.

  3. 选择“发布”按钮 。Select the Publish button.

  4. 选择定位符类型。Select the locator type.

  5. 选择“设置” (应用程序对象和服务主体对象)。Select Add.

    发布视频

URL 会添加到“已发布的 URL” 列表。The URL is added to the list of Published URLs.

从门户播放内容Play content from the portal

可以在 Azure 门户中的内容播放器上测试视频。You can test your video on a content player in the Azure portal.

选择视频,然后选择“播放”按钮 。Select the video, and then select the Play button.

在 Azure 门户中播放视频

请注意以下事项:Some considerations apply:

  • 若要启动流式处理,请开始运行“默认”流式处理终结点。To begin streaming, start running the default streaming endpoint.
  • 确保视频已发布。Make sure that the video has been published.
  • Azure 门户媒体播放器从默认的流式处理终结点播放。The Azure portal media player plays from the default streaming endpoint. 若要从非默认流式处理终结点播放,请选择并复制该 URL,然后将其粘贴到其他播放器中。If you want to play from a non-default streaming endpoint, select and copy the URL, and then paste it into another player. 例如,可以在 Azure Media Player 上测试视频。For example, you can test your video on the Azure Media Player.

后续步骤Next steps

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

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

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