使用媒体服务实时传送视频流,通过 Azure 门户创建多比特率流Perform live streaming using Media Services to create multi-bitrate streams with Azure portal

Note

不会向媒体服务 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

本教程介绍了创建通道的步骤,该通道接收单比特率实时流,并将其编码为多比特率流。This tutorial walks you through the steps of creating a Channel that receives a single-bitrate live stream and encodes it to multi-bitrate stream.

有关为实时编码启用的通道的更多相关概念信息,请参阅使用 Azure 媒体服务实时传送视频流以创建多比特率流For more conceptual information related to Channels that are enabled for live encoding, see Live streaming using Azure Media Services to create multi-bitrate streams.

常见的实时流方案Common Live Streaming Scenario

以下是创建常见的实时流应用程序时涉及的常规步骤。The following are general steps involved in creating common live streaming applications.

Note

目前,直播活动的最大建议持续时间为 8 小时。Currently, the max recommended duration of a live event is 8 hours.

  1. 将视频摄像机连接到计算机。Connect a video camera to a computer.
    有关设置建议,请查看简单且可移植的事件视频设备设置For setup ideas, check out Simple and portable event video gear setup.

    如果你无法访问摄像机,则可以使用 Telestream Wirecast 等工具从视频文件生成实时源。If you do not have access to a camera, tools such as Telestream Wirecast can be used generate a live feed from a video file.

  2. 启动并配置一个可通过以下协议之一输出单比特率流的本地实时编码器:RTMP 或平滑流式处理。Launch and configure an on-premises live encoder that can output a single bitrate stream in one of the following protocols: RTMP or Smooth Streaming. 有关详细信息,请参阅 Azure 媒体服务 RTMP 支持和实时编码器For more information, see Azure Media Services RTMP Support and Live Encoders.
    另外,请查看以下博客:采用 OBS 的实时传送视频流生产Also, check out this blog: Live streaming production with OBS.

    此步骤也可以在创建频道后执行。This step could also be performed after you create your Channel.

  3. 创建并启动通道。Create and start a Channel.

  4. 检索通道引入 URL。Retrieve the Channel ingest URL.

    实时编码器使用引入 URL 将流发送到频道。The ingest URL is used by the live encoder to send the stream to the Channel.

  5. 检索频道预览 URL。Retrieve the Channel preview URL.

    使用此 URL 来验证频道是否正常接收实时流。Use this URL to verify that your channel is properly receiving the live stream.

  6. 创建事件/节目(这也会创建资产)。Create an event/program (that will also create an asset).

  7. 发布事件(这将为关联的资产创建点播定位符)。Publish the event (that will create an OnDemand locator for the associated asset).

  8. 在准备好开始流式传输和存档时,启动事件。Start the event when you are ready to start streaming and archiving.

  9. (可选)可以向实时编码器发信号,以启动广告。Optionally, the live encoder can be signaled to start an advertisement. 将广告插入到输出流中。The advertisement is inserted in the output stream.

  10. 要停止流式传输和归档事件时,停止事件。Stop the event whenever you want to stop streaming and archiving the event.

  11. 删除事件(并选择性地删除资产)。Delete the event (and optionally delete the asset).

先决条件Prerequisites

以下是完成本教程所需具备的条件。The following are required to complete the tutorial.

  • 若要完成本教程,需要一个 Azure 帐户。To complete this tutorial, you need an Azure account. 如果没有帐户,只需花费几分钟就能创建一个免费试用帐户。If you don't have an account, you can create a free trial account in just a couple of minutes. 有关详细信息,请参阅 Azure 试用版For details, see Azure Trial.
  • 一个媒体服务帐户。A Media Services account. 若要创建媒体服务帐户,请参阅 创建帐户To create a Media Services account, see Create Account.
  • 可以发送单比特率实时流的摄像头和编码器。A webcam and an encoder that can send a single bitrate live stream.

创建通道Create a channel

  1. Azure 门户中,选择“媒体服务”,并单击媒体服务帐户名。In the Azure portal, select Media Services and then click on your Media Services account name.

  2. 选择“实时传送视频流” 。Select Live Streaming.

  3. 选择“自定义创建” 。Select Custom create. 此选项可创建启用了实时编码的通道。This option will let you create a channel that is enabled for live encoding.

    创建频道

  4. 单击“设置” 。Click on Settings.

    1. 选择“实时编码” 通道类型。Choose the Live Encoding channel type. 此类型指定创建能够进行实时编码的通道。This type specifies that you want to create a Channel that is enabled for live encoding. 这意味着传入单比特率流将发送到通道,并使用指定的实时编码器设置编码为多比特率流。That means the incoming single bitrate stream is sent to the Channel and encoded into a multi-bitrate stream using specified live encoder settings. 有关详细信息,请参阅 使用 Azure 媒体服务执行实时流式处理以创建多比特率流For more information, see Live streaming using Azure Media Services to create multi-bitrate streams. 单击“确定”。Click OK.
    2. 指定通道名称。Specify a channel's name.
    3. 单击屏幕底部的“确定”。Click OK at the bottom of the screen.
  5. 选择“引入” 选项卡。Select the Ingest tab.

    1. 可在本页上选择流协议。On this page, you can select a streaming protocol. 对于“实时编码” 通道类型,有效的协议选项为:For the Live Encoding channel type, valid protocol options are:

      • 单比特率分片 MP4(平滑流式处理)Single bitrate Fragmented MP4 (Smooth Streaming)

      • 单比特率 RTMPSingle bitrate RTMP

        有关每个协议的详细说明,请参阅 使用 Azure 媒体服务执行实时流式处理以创建多比特率流For detailed explanation about each protocol, see Live streaming using Azure Media Services to create multi-bitrate streams.

        通道或其关联的事件/节目正在运行时,无法更改协议选项。You cannot change the protocol option while the Channel or its associated events/programs are running. 如需其他协议,应针对各个流协议创建单独的通道。If you require different protocols, you should create separate channels for each streaming protocol.

    2. 可在引入时应用 IP 限制。You can apply IP restriction on the ingest.

      可定义允许向此通道引入视频的 IP 地址。You can define the IP addresses that are allowed to ingest a video to this channel. 允许的 IP 地址可以指定为单个 IP 地址(例如“10.0.0.1”)、使用一个 IP 地址和 CIDR 子网掩码的 IP 范围(例如'10.0.0.1/22'),或使用一个 IP 地址和点分十进制子网掩码的 IP 范围(例如'10.0.0.1(255.255.252.0)').Allowed IP addresses can be specified as either a single IP address (e.g. '10.0.0.1'), an IP range using an IP address and a CIDR subnet mask (e.g. '10.0.0.1/22'), or an IP range using an IP address and a dotted decimal subnet mask (e.g. '10.0.0.1(255.255.252.0)').

      如果未指定 IP 地址并且没有规则定义,则不会允许任何 IP 地址。If no IP addresses are specified and there is no rule definition then no IP address will be allowed. 若要允许任何 IP 地址,请创建规则并设置 0.0.0.0/0。To allow any IP address, create a rule and set 0.0.0.0/0.

  6. 在“预览” 选项卡上,应用针对预览的 IP 限制。On the Preview tab, apply IP restriction on the preview.

  7. 在“编码” 选项卡上,指定编码预设。On the Encoding tab, specify the encoding preset.

    目前,唯一可以选择的系统预设是“默认 720p” 。Currently, the only system preset you can select is Default 720p. 若要指定自定义预设,请开具 Microsoft 支持票证。To specify a custom preset, open a Microsoft support ticket. 然后,输入为用户创建的预设的名称。Then, enter the name of the preset created for you.

Note

目前,通道启动可能最多需要 30 分钟。Currently, the Channel start can take up to 30 minutes. 通道重置可能最多需要 5 分钟。Channel reset can take up to 5 minutes.

创建通道后,可单击该通道,并选择含有通道配置的“设置” 。Once you created the Channel, you can click on the channel and select Settings where you can view your channels configurations.

有关详细信息,请参阅 使用 Azure 媒体服务实时传送视频流以创建多比特率流For more information, see Live streaming using Azure Media Services to create multi-bitrate streams.

获取引入 URLGet ingest URLs

创建通道后,可以获得要提供给实时编码器的引入 URL。Once the channel is created, you can get ingest URLs that you will provide to the live encoder. 编码器使用这些 URL 来输入实时流。The encoder uses these URLs to input a live stream.

引入 url

创建并管理事件Create and manage events

概述Overview

通道与事件/节目相关联,使用事件/节目,可控制实时流中的段的发布和存储。A channel is associated with events/programs that enable you to control the publishing and storage of segments in a live stream. 通道管理事件/节目。Channels manage events/programs. 通道和节目的关系非常类似于传统媒体,通道具有恒定的内容流,而节目的范围限定为该通道上的一些定时事件。The Channel and Program relationship is very similar to traditional media where a channel has a constant stream of content and a program is scoped to some timed event on that channel.

可设置“存档时段” 的长度,指定希望保留事件录制内容的小时数。You can specify the number of hours you want to retain the recorded content for the event by setting the Archive Window length. 此值的设置范围是最短 5 分钟,最长 25 小时。This value can be set from a minimum of 5 minutes to a maximum of 25 hours. 存储时间窗口长度还决定了客户端能够从当前实时位置按时间向后搜索的最长时间。Archive window length also dictates the maximum amount of time clients can seek back in time from the current live position. 超出指定时间长度后,事件也能够运行,但落在时间窗口长度后面的内容将不断被丢弃。Events can run over the specified amount of time, but content that falls behind the window length is continuously discarded. 此属性的这个值还决定了客户端清单能够增加多长时间。This value of this property also determines how long the client manifests can grow.

每个事件均与资产关联。Each event is associated with an Asset. 若要发布事件,必须为关联的资产创建按需定位符。To publish the event you must create an OnDemand locator for the associated asset. 创建此定位符后,可以生成提供给客户端的流式处理 URL。Having this locator will enable you to build a streaming URL that you can provide to your clients.

一个通道最多支持三个并发运行的事件,因此可为同一传入流创建多个存档。A channel supports up to three concurrently running events so you can create multiple archives of the same incoming stream. 这样,便可以根据需要发布和存档事件的不同部分。This allows you to publish and archive different parts of an event as needed. 例如,业务需求是存档 6 小时的节目,但只播放过去 10 分钟的内容。For example, your business requirement is to archive 6 hours of an event, but to broadcast only last 10 minutes. 为此,需创建两个同时运行的事件。To accomplish this, you need to create two concurrently running event. 一个事件设为存档 6 小时但不发布该节目。One event is set to archive 6 hours of the event but the program is not published. 另一个事件设置为存档 10 分钟且要发布该节目。The other event is set to archive for 10 minutes and this program is published.

不应当将现有节目重用于新事件。You should not reuse existing programs for new events. 与之相反,应针对每个事件创建并启动新节目。Instead, create and start a new program for each event.

可开始流式传输和存档后,启动事件/节目。Start an event/program when you are ready to start streaming and archiving. 要停止流式传输和归档事件时,停止事件。Stop the event whenever you want to stop streaming and archiving the event.

如果要删除存档的内容,请停止并删除事件,并删除关联的资产。To delete archived content, stop and delete the event and then delete the associated asset. 资产由某事件使用时不可删除;必须先删除该事件。An asset cannot be deleted if it is used by the event; the event must be deleted first.

即使你停止并删除了事件,只要没有删除资产,用户也能够按需将已存档内容作为视频进行流式传输。Even after you stop and delete the event, the users would be able to stream your archived content as a video on demand, for as long as you do not delete the asset.

如果希望保留已存档的内容但不希望其可供流式传输,请删除流式传输定位符。If you do want to retain the archived content, but not have it available for streaming, delete the streaming locator.

创建/启动/停止事件Create/start/stop events

将流传输到通道后,可以通过创建资产、节目和流定位符来启动流式传输事件。Once you have the stream flowing into the Channel you can begin the streaming event by creating an Asset, Program, and Streaming Locator. 这会存档流,并使观看者可通过流式处理终结点使用该流。This will archive the stream and make it available to viewers through the Streaming Endpoint.

Note

创建 AMS 帐户后,会将一个处于“已停止”状态的默认流式处理终结点添加到帐户。 When your AMS account is created a default streaming endpoint is added to your account in the Stopped state. 若要开始对内容进行流式处理并利用动态打包和动态加密功能,必须确保要从其流式获取内容的流式处理终结点处于“正在运行”状态。To start streaming your content and 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.

可通过两种方式启动该事件:There are two ways to start event:

  1. 在“频道”页上,按“直播活动”添加新活动 。From the Channel page, press Live Event to add a new event.

    指定:事件名称、资产名称、归档时段和加密选项。Specify: event name, asset name, archive window, and encryption option.

    创建程序

    如果保留选中“立即发布此现场活动” ,会创建事件 PUBLISHING URL。If you left Publish this live event now checked, the event the PUBLISHING URLs will get created.

    可流式传输事件时,按“启动” 。You can press Start, whenever you are ready to stream the event.

    启动事件后,可按“观看” 开始播放内容。Once you start the event, you can press Watch to start playing the content.

  2. 或者,可使用快捷方式并按“通道”页上的“开始播放”按钮 。Alternatively, you can use a shortcut and press Go Live button on the Channel page. 这会创建默认资产、节目和流定位符。This will create a default Asset, Program, and Streaming Locator.

    事件命名为 default ,归档时段设置为 8 小时。The event is named default and the archive window is set to 8 hours.

可从“直播活动” 页面上观看已发布的活动。You can watch the published event from the Live event page.

如果单击“停播” ,将停止所有直播活动。If you click Off Air, it will stop all live events.

观看事件Watch the event

如果要观看事件,请在 Azure 门户中单击“观看” ,或者先复制流式处理 URL,然后使用所选播放器进行播放。To watch the event, click Watch in the Azure portal or copy the streaming URL and use a player of your choice.

已创建

直播活动在停止后会自动转换为点播内容。Live event automatically converts events to on-demand content when stopped.

清理Clean up

如果已完成流式处理事件,并想要清理先前设置的资源,请遵循以下过程。If you are done streaming events and want to clean up the resources provisioned earlier, follow the following procedure.

  • 停止从编码器推送流。Stop pushing the stream from the encoder.
  • 停止通道。Stop the channel. 停止通道后,不会产生任何费用。Once the Channel is stopped, it will not incur any charges. 需要重新启动它时,它会采用相同的引入 URL,因此无需重新配置编码器。When you need to start it again, it will have the same ingest URL so you won't need to reconfigure your encoder.
  • 除非想要继续以点播流形式提供直播活动的存档,否则可以停止流式处理终结点。You can stop your Streaming Endpoint, unless you want to continue to provide the archive of your live event as an on-demand stream. 如果通道处于停止状态,则不会产生任何费用。If the channel is in stopped state, it will not incur any charges.

查看存档的内容View archived content

即使你停止并删除了事件,只要没有删除资产,用户也能够按需将已存档内容作为视频进行流式传输。Even after you stop and delete the event, the users would be able to stream your archived content as a video on demand, for as long as you do not delete the asset. 如果资产被某个事件使用,则无法将其删除,必须先删除该事件。An asset cannot be deleted if it is used by an event; the event must be deleted first.

若要管理资产,请选择“设置”,再单击“资产” 。To manage your assets, select Setting and click Assets.

资产

注意事项Considerations

  • 目前,直播活动的最大建议持续时间为 8 小时。Currently, the max recommended duration of a live event is 8 hours.
  • 确保要从中流式传输内容的流式处理终结点处于“正在运行”状态 。Make sure the streaming endpoint from which you want to stream your content is in the Running state.

后续步骤Next step

查看媒体服务学习路径。Review Media Services learning paths.

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

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

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