媒体服务中的实时事件和实时输出Live Events and Live Outputs in Media Services

媒体服务徽标 v3media services logo v3


使用 Azure 媒体服务可将实时事件传送到 Azure 云中的客户。Azure Media Services lets you deliver live events to your customers on the Azure cloud. 若要在媒体服务 v3 中设置实时传送视频流事件,需了解本文中所述的概念。To set up your live streaming events in Media Services v3, you need to understand the concepts discussed in this article.

提示

对于从媒体服务 v2 API 迁移的客户,“实时事件”实体取代了 v2 中的“频道”,“实时输出”取代了“节目”。 For customers migrating from Media Services v2 APIs, the Live Event entity replaces Channel in v2 and Live Output replaces Program.

直播活动Live Events

直播活动负责引入和处理实时视频源。Live Events are responsible for ingesting and processing the live video feeds. 创建实时事件时,会创建一个主要和辅助输入终结点,可以使用它来从远程编码器发送实时信号。When you create a Live Event, a primary and secondary input endpoint is created that you can use to send a live signal from a remote encoder. 远程实时编码器使用 RTMP平滑流式处理(分段 MP4)输入协议将贡献源发送到该输入终结点。The remote live encoder sends the contribution feed to that input endpoint using either the RTMP or Smooth Streaming (fragmented-MP4) input protocol. 对于 RTMP 引入协议,内容可以通过明文 (rtmp://) 或网络安全加密 (rtmps://) 的方式发送。For the RTMP ingest protocol, the content can be sent in the clear (rtmp://) or securely encrypted on the wire(rtmps://). 对于平滑流式处理引入协议,支持的 URL 方案为 http://https://For the Smooth Streaming ingest protocol, the supported URL schemes are http:// or https://.

实时事件类型Live Event types

直播活动可以设置为“直通” (本地实时编码器发送多比特率流)或“实时编码” (本地实时编码器发送单比特率流)。A Live Event can be set to either a pass-through (an on-premises live encoder sends a multiple bitrate stream) or live encoding (an on-premises live encoder sends a single bitrate stream). 这些类型是在创建期间使用 LiveEventEncodingType 设置的:The types are set during creation using LiveEventEncodingType:

  • LiveEventEncodingType.None:本地实时编码器发送多比特率流。LiveEventEncodingType.None: An on-premises live encoder sends a multiple bitrate stream. 引入的流通过直播活动传递,而不会经过任何进一步的处理。The ingested stream passes through the Live Event without any further processing. 也称为“直通模式”。Also called the pass-through mode.
  • LiveEventEncodingType.Standard:本地实时编码器将单比特率流发送到实时事件,媒体服务创建多比特率流。LiveEventEncodingType.Standard: An on-premises live encoder sends a single bitrate stream to the Live Event and Media Services creates multiple bitrate streams. 如果贡献源的分辨率为 720p 或更高,则 Default720p 预设将编码一组 6 分辨率/比特率对。If the contribution feed is of 720p or higher resolution, the Default720p preset will encode a set of 6 resolution/bitrates pairs.
  • LiveEventEncodingType.Premium1080p:本地实时编码器将单比特率流发送到实时事件,媒体服务创建多比特率流。LiveEventEncodingType.Premium1080p: An on-premises live encoder sends a single bitrate stream to the Live Event and Media Services creates multiple bitrate streams. Default1080p 预设指定分辨率/比特率对的输出集。The Default1080p preset specifies the output set of resolution/bitrates pairs.

直通Pass-through

使用媒体服务的直通实时事件示例图

使用直通直播活动,可以依赖本地实时编码器生成多比特率视频流,并将其作为贡献源发送到直播活动(使用 RTMP 或分段 MP4 协议)。When using the pass-through Live Event, you rely on your on-premises live encoder to generate a multiple bitrate video stream and send that as the contribution feed to the Live Event (using RTMP or fragmented-MP4 protocol). 然后,直播活动会接受无需进一步处理的传入视频流。The Live Event then carries through the incoming video streams without any further processing. 此类直通实时事件已针对长时间运行的实时事件或 24x365 线性实时传送视频流进行优化。Such a pass-through Live Event is optimized for long-running live events or 24x365 linear live streaming. 创建此类实时事件时,请指定 None (LiveEventEncodingType.None)。When creating this type of Live Event, specify None (LiveEventEncodingType.None).

发送的贡献源的最高分辨率可为 4K,帧速率可为 60 帧/秒,采用 H.264/AVC 或 H.265/HEVC 视频编解码器,以及 AAC(AAC-LC、HE-AACv1 或 HE-AACv2)音频编解码器。You can send the contribution feed at resolutions up to 4K and at a frame rate of 60 frames/second, with either H.264/AVC or H.265/HEVC video codecs, and AAC (AAC-LC, HE-AACv1, or HE-AACv2) audio codec. 有关详细信息,请参阅实时事件类型的比较For more information, see Live Event types comparison.

备注

当你要在很长一段时间内进行多个活动,并且已在本地编码器上进行投入时,使用直通方法是进行实时传送视频流的最经济方式。Using a pass-through method is the most economical way to do live streaming when you're doing multiple events over a long period of time, and you have already invested in on-premises encoders. 请参阅定价详细信息。See pricing details.

请参阅 MediaV3LiveApp 中的 .NET 代码示例。See a .NET code example in MediaV3LiveApp.

实时编码Live encoding

使用媒体服务的实时编码示例图

将实时编码与媒体服务配合使用时,需配置本地实时编码器,以便将单比特率视频作为贡献源发送到实时事件(使用 RTMP 或分段 MP4 协议)。When using live encoding with Media Services, you configure your on-premises live encoder to send a single bitrate video as the contribution feed to the Live Event (using RTMP or Fragmented-Mp4 protocol). 然后设置实时事件,以将该传入的单比特率流编码为多比特率视频流,并使输出可通过 MPEG-DASH、HLS 和平滑流式处理等协议传送到播放设备。You then set up a Live Event so that it encodes that incoming single bitrate stream to a multiple bitrate video stream, and makes the output available for delivery to play back devices via protocols like MPEG-DASH, HLS, and Smooth Streaming.

使用实时编码时,可发送的贡献源最高分辨率只能是 1080p,帧速率是 30 帧/秒,采用 H.264/AVC 视频编解码器,以及 AAC(AAC-LC、HE-AACv1 或 HE-AACv2)音频编解码器。When you use live encoding, you can send the contribution feed only at resolutions up to 1080p resolution at a frame rate of 30 frames/second, with H.264/AVC video codec and AAC (AAC-LC, HE-AACv1, or HE-AACv2) audio codec. 请注意,直通实时事件支持的最大分辨率为 4K(60 帧/秒)。Note that pass-through Live Events can support resolutions up to 4K at 60 frames/second. 有关详细信息,请参阅实时事件类型的比较For more information, see Live Event types comparison.

实时编码器的输出中包含的分辨率和比特率由预设确定。The resolutions and bitrates contained in the output from the live encoder is determined by the preset. 如果使用 Standard 实时编码器 (LiveEventEncodingType.Standard),Default720p 预设将指定一组 6 分辨率/比特率对,其最高分辨率为 720p,最高比特率为 3.5 Mbps,最低分辨率为 192p,最低比特率为 200 kbps。If using a Standard live encoder (LiveEventEncodingType.Standard), then the Default720p preset specifies a set of six resolution/bit rate pairs, going from 720p at 3.5 Mbps down to 192p at 200 kbps. 否则,如果使用 Premium1080p 实时编码器 (LiveEventEncodingType.Premium1080p),Default1080p 预设将指定一组 6 分辨率/比特率对,其最高分辨率为 1080p,最高比特率为 3.5 Mbps,最低分辨率为 180p,最低比特率为 200 kbps。Otherwise, if using a Premium1080p live encoder (LiveEventEncodingType.Premium1080p), then the Default1080p preset specifies a set of six resolution/bit rate pairs, going from 1080p at 3.5 Mbps down to 180p at 200 kbps. 有关信息,请参阅系统预设For information, see System presets.

备注

如果需要自定义实时编码预设,请通过 Azure 门户开具支持票证。If you need to customize the live encoding preset, open a support ticket via Azure portal. 指定所需的分辨率和比特率的表。Specify the desired table of resolution and bitrates. 确认只有一个层的分辨率为 720p(如果请求 Standard 实时编码器的预设)或 1080p(如果请求 Premium1080p 实时编码器的预设),且最多有 6 个层。Verify that there's only one layer at 720p (if requesting a preset for a Standard live encoder) or at 1080p (if requesting a preset for a Premium1080p live encoder), and 6 layers at most.

创建直播活动Creating Live Events

选项Options

创建直播活动时,可以指定以下选项:When creating a Live Event, you can specify the following options:

  • 直播活动的流式处理协议(目前支持 RTMP 和平滑流式处理协议)。The streaming protocol for the Live Event (currently, the RTMP and Smooth Streaming protocols are supported).
    运行直播活动或其关联的实时输出时,无法更改协议选项。You can't change the protocol option while the Live Event or its associated Live Outputs are running. 如果需要其他协议,请为每个流式处理协议创建单独的实时事件。If you require different protocols, create a separate Live Event for each streaming protocol.

  • 创建事件时,可以将其启动方式指定为自动启动。When creating the event, you can specify to autostart it.
    如果将 autostart 设置为 true,则直播活动会在创建后启动。When autostart is set to true, the Live Event will be started after creation. 只要直播活动开始运行,就会开始计费。The billing starts as soon as the Live Event starts running. 必须显式对直播活动资源调用停止操作才能停止进一步计费。You must explicitly call Stop on the Live Event resource to halt further billing. 或者,可以在准备好开始流式传输后,启动事件。Alternatively, you can start the event when you're ready to start streaming.

    有关详细信息,请参阅直播活动状态和计费For more information, see Live Event states and billing.

  • 对引入和预览的 IP 限制。IP restrictions on the ingest and preview. 可定义允许向该直播活动引入视频的 IP 地址。You can define the IP addresses that are allowed to ingest a video to this Live Event. 允许的 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 (for example '10.0.0.1'), an IP range using an IP address and a CIDR subnet mask (for example, '10.0.0.1/22'), or an IP range using an IP address and a dotted decimal subnet mask (for example, '10.0.0.1(255.255.252.0)').
    如果未指定 IP 地址并且没有规则定义,则不会允许任何 IP 地址。If no IP addresses are specified and there's 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.
    IP 地址必须采用以下格式之一:具有四个数字或 CIDR 地址范围的 IpV4 地址。The IP addresses have to be in one of the following formats: IpV4 address with four numbers or CIDR address range.

    如果要在自己的防火墙上启用某些 IP,或者要将直播活动的输入约束到 Azure IP 地址,请从 Azure 数据中心 IP 地址范围下载 JSON 文件。If you want to enable certain IPs on your own firewalls or want to constrain inputs to your live events to Azure IP addresses, download a JSON file from Azure Datacenter IP address ranges. 有关此文件的详细信息,请选择页面上的“详细信息”部分。 For details about this file, select the Details section on the page.

命名规则Naming rules

  • 最大直播活动名称为 32 个字符。Max live event name is 32 characters.
  • 该名称应遵循此正则表达式模式:^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$The name should follow this regex pattern: ^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$.

另请参阅流式处理终结点命名约定Also see Streaming Endpoints naming conventions.

提示

为了保证直播活动名称的唯一性,可以生成 GUID,并删除所有连字符和大括号(如果有)。To guarantee uniqueness of your live event name, you can generate a GUID then remove all the hyphens and curly brackets (if any). 该字符串在所有直播活动中都是唯一的,并且其长度保证为 32。The string will be unique across all live events and its length is guaranteed to be 32.

直播活动引入 URLLive Event ingest URLs

创建实时事件后,可以获得要提供给实时本地编码器的引入 URL。Once the Live Event is created, you can get ingest URLs that you'll provide to the live on-premises encoder. 实时编码器使用这些 URL 来输入实时流。The live encoder uses these URLs to input a live stream. 有关详细信息,请参阅建议的本地实时编码器For more information, see Recommended on-premises live encoders.

可以使用非虚 URL 或虚 URL。You can either use non-vanity URLs or vanity URLs.

备注

要使引入 URL 具有预测性,请设置“vanity”模式。For an ingest URL to be predictive, set the "vanity" mode.

  • 非虚 URLNon-vanity URL

    在媒体服务 v3 中,非虚 URL 是默认模式。Non-vanity URL is the default mode in Media Services v3. 可以快速获取直播活动,但只有在直播活动启动后,才会知道引入 URL。You potentially get the Live Event quickly but ingest URL is known only when the live event is started. 如果停止/启动直播活动,此 URL 会更改。The URL will change if you do stop/start the Live Event.
    非虚 URL 适用于这样的情况:最终用户希望使用应用进行流式处理,而应用希望尽快获取实时事件,并且可以使用动态引入 URL。Non-Vanity is useful in scenarios when an end user wants to stream using an app where the app wants to get a live event ASAP and having a dynamic ingest URL isn't a problem.

    如果客户端应用在创建直播活动之前不需要预生成引入 URL,请让媒体服务自动生成直播活动的访问令牌。If a client app doesn't need to pre-generate an ingest URL before the Live Event is created, let Media Services autogenerate the Access Token for the live event.

  • 虚 URLVanity URL

    对于使用硬件广播编码器且不希望在启动实时事件时重新配置其编码器的大型媒体广播者来说,虚模式是首选。Vanity mode is preferred by large media broadcasters who use hardware broadcast encoders and don't want to reconfigure their encoders when they start the Live Event. 这些广播公司需要一个不随时间变化的预测性引入 URL。These broadcasters want a predictive ingest URL which doesn't change over time.

    备注

    在 Azure 门户中,虚 URL 名为“持久性输入 URL” 。In the Azure portal, the vanity URL is named "Persistent input URL".

    若要在 API 中指定此模式,请在创建时将 vanityUrl 设为 true(默认值为 false)。To specify this mode in the API, set vanityUrl to true at creation time (default is false). 还需要在创建时传递自己的访问令牌 (LiveEventInput.accessToken)。You also need to pass your own access token (LiveEventInput.accessToken) at creation time. 指定令牌值可避免 URL 中出现随机令牌。You specify the token value to avoid a random token in the URL. 访问令牌必须是有效的 GUID 字符串(带或不带连字符)。The access token has to be a valid GUID string (with or without the hyphens). 一旦设置模式,就无法将其更新。Once the mode is set, it can't be updated.

    访问令牌在数据中心内必须是唯一的。The access token needs to be unique in your data center. 如果应用需要使用虚 URL,我们建议始终为访问令牌创建新的 GUID 实例(而不要重复使用任何现有的 GUID)。If your app needs to use a vanity URL, it's recommended to always create a new GUID instance for your access token (instead of reusing any existing GUID).

    使用以下 API 启用虚 URL,并将访问令牌设置为有效的 GUID(例如 "accessToken": "1fce2e4b-fb15-4718-8adc-68c6eb4c26a7")。Use the following APIs to enable the Vanity URL and set the access token to a valid GUID (for example, "accessToken": "1fce2e4b-fb15-4718-8adc-68c6eb4c26a7").

    语言Language 启用虚 URLEnable vanity URL 设置访问令牌Set access token
    RESTREST properties.vanityUrlproperties.vanityUrl LiveEventInput.accessTokenLiveEventInput.accessToken
    CLICLI --vanity-url--vanity-url --access-token--access-token
    .NET.NET LiveEvent.VanityUrlLiveEvent.VanityUrl LiveEventInput.AccessTokenLiveEventInput.AccessToken

实时引入 URL 命名规则Live ingest URL naming rules

  • 下面的随机 字符串是一个 128 位的十六进制数字(由 32 个 0-9 a-f 字符组成)。The random string below is a 128-bit hex number (which is composed of 32 characters of 0-9 a-f).
  • 访问令牌:使用虚模式时设置的有效 GUID 字符串。your access token: The valid GUID string you set when using the vanity mode. 例如,"1fce2e4b-fb15-4718-8adc-68c6eb4c26a7"For example, "1fce2e4b-fb15-4718-8adc-68c6eb4c26a7".
  • 流名称:指示特定连接的流名称。stream name: Indicates the stream name for a specific connection. 流名称值通常由使用的实时编码器添加。The stream name value is usually added by the live encoder you use. 可将实时编码器配置为使用任何名称来描述连接,例如:“video1_audio1”、“video2_audio1”、“stream”。You can configure the live encoder to use any name to describe the connection, for example: "video1_audio1", "video2_audio1", "stream".

非虚 URLNon-vanity URL

RTMPRTMP

rtmp://<random 128bit hex string>.channel.media.chinacloudapi.cn:1935/live/<auto-generated access token>/<stream name>
rtmp://<random 128bit hex string>.channel.media.chinacloudapi.cn:1936/live/<auto-generated access token>/<stream name>
rtmps://<random 128bit hex string>.channel.media.chinacloudapi.cn:2935/live/<auto-generated access token>/<stream name>
rtmps://<random 128bit hex string>.channel.media.chinacloudapi.cn:2936/live/<auto-generated access token>/<stream name>

平滑流Smooth Streaming

http://<random 128bit hex string>.channel.media.chinacloudapi.cn/<auto-generated access token>/ingest.isml/streams(<stream name>)
https://<random 128bit hex string>.channel.media.chinacloudapi.cn/<auto-generated access token>/ingest.isml/streams(<stream name>)

虚 URLVanity URL

RTMPRTMP

rtmp://<live event name>-<ams account name>-<region abbrev name>.channel.media.chinacloudapi.cn:1935/live/<your access token>/<stream name>
rtmp://<live event name>-<ams account name>-<region abbrev name>.channel.media.chinacloudapi.cn:1936/live/<your access token>/<stream name>
rtmps://<live event name>-<ams account name>-<region abbrev name>.channel.media.chinacloudapi.cn:2935/live/<your access token>/<stream name>
rtmps://<live event name>-<ams account name>-<region abbrev name>.channel.media.chinacloudapi.cn:2936/live/<your access token>/<stream name>

平滑流Smooth Streaming

http://<live event name>-<ams account name>-<region abbrev name>.channel.media.chinacloudapi.cn/<your access token>/ingest.isml/streams(<stream name>)
https://<live event name>-<ams account name>-<region abbrev name>.channel.media.chinacloudapi.cn/<your access token>/ingest.isml/streams(<stream name>)

直播活动预览 URLLive Event preview URL

一旦实时事件开始接收贡献源,你就可以使用其预览终结点进行预览,并在进一步发布之前验证是否可以收到实时流。Once the Live Event starts receiving the contribution feed, you can use its preview endpoint to preview and validate that you're receiving the live stream before further publishing. 确认预览流正常后,可以使用实时事件来确保可以通过一个或多个(预先创建的)流式处理终结点传送实时流。After you've checked that the preview stream is good, you can use the Live Event to make the live stream available for delivery through one or more (pre-created) Streaming Endpoints. 为此,请针对实时事件创建新的实时输出To accomplish this, create a new Live Output on the Live Event.

重要

确保视频流向预览 URL,然后再继续操作!Make sure that the video is flowing to the preview URL before continuing!

实时事件的长时间运行的操作Live Event long-running operations

有关详细信息,请参阅长时间运行的操作For details, see long-running operations.

实时输出Live Outputs

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

有关实时输出的详细信息,请参阅使用云 DVRFor detailed information about Live Outputs, see Using a cloud DVR.

常见问题Frequently asked questions

请参阅常见问题解答一文。See the Frequently asked questions article.

后续步骤Next steps

实时传送视频流教程Live streaming tutorial