媒体服务中的实时事件和实时输出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.

请参阅 .NET 代码示例,了解如何在 DVR 直播活动中创建直通直播活动。See the .NET code example for creating a pass-through Live Event in Live Event with DVR.

实时编码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:

  • 可以为实时事件指定名称和说明。You can give the live event a name and a description.
  • 云编码包括直通(无云编码)、标准(最高 720p)或高级(最高 1080p)。Cloud encoding includes Pass-through (no cloud encoding), Standard (up to 720p), or Premium (up to 1080p). 对于标准和高级编码,你可以选择已编码视频的拉伸模式。For Standard and Premium encoding, you can choose the stretch mode of the encoded video.
    • 无:严格遵循编码预设中指定的输出分辨率,而不考虑输入视频的像素纵横比或显示纵横比。None: Strictly respects the output resolution specified in the encoding preset without considering the pixel aspect ratio or display aspect ratio of the input video.
    • AutoSize:替代输出分辨率,并对其进行更改以匹配输入的显示纵横比,无需填充。AutoSize: Overrides the output resolution and changes it to match the display aspect ratio of the input, without padding. 例如,如果输入为 1920x1080,而编码预设要求提供 1280x1280,则会重写预设中的值,输出将是 1280x720,这样可以保持 16:9 的输入纵横比。For example, if the input is 1920x1080 and the encoding preset asks for 1280x1280, then the value in the preset is overridden, and the output will be at 1280x720, which maintains the input aspect ratio of 16:9.
    • AutoFit:根据输出分辨率填充输出(使用上下黑边或左右黑边),同时确保输出中活动视频区域的纵横比与输入相同。AutoFit: Pads the output (with either letterbox or pillar box) to honor the output resolution, while ensuring that the active video region in the output has the same aspect ratio as the input. 例如,如果输入为 1920x1080,并且编码预设要求提供 1280x1280,则输出将是 1280x1280,其中包含纵横比为 16:9 的 1280x720 内部矩形,并在左侧和右侧包含宽度为 280 像素的左右黑边区域。For example, if the input is 1920x1080 and the encoding preset asks for 1280x1280, then the output will be at 1280x1280, which contains an inner rectangle of 1280x720 at aspect ratio of 16:9, with pillar box regions 280 pixels wide at the left and right.
  • 流式处理协议(目前支持 RTMP 和平滑流式处理协议)。Streaming protocol (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.
  • 输入 ID,它是实时事件输入流的全局独一无二的标识符。Input ID which is a globally unique identifier for the live event input stream.
  • 包含 None 的静态主机名前缀(在本例中,将使用随机的 128 位十六进制字符串),使用实时事件名称,或使用自定义名称。Static hostname prefix which includes none (in which case a random 128 bit hex string will be used), Use live event name, or Use custom name. 选择使用自定义名称时,此值为自定义主机名前缀。When you choose to use a customer name, this value is the Custom hostname prefix.
  • 你可以通过设置 HLS 输出中每个媒体段的输入关键帧间隔(以秒为单位的持续时间)来减少实时广播与播放之间的端到端延迟。You can reduce end-to-end latency between the live broadcast and the playback by setting the input key frame interval, which is the duration (in seconds), of each media segment in the HLS output. 该值应当为 0.5 秒到 20 秒范围内的非零整数。The value should be a non-zero integer in the range of 0.5 to 20 seconds. 如果输入或输出关键帧间隔均未设置,则该值默认为 2 秒。The value defaults to 2 seconds if neither of the input or output key frame intervals are set. 只有直通事件中允许设置关键帧间隔。The key frame interval is only allowed on pass-through events.
  • 创建事件时,可以将其设置为自动启动。When creating the event, you can set it to autostart. 如果将 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.

备注

对于标准和高级编码,最大帧速率为 30 fps。The max framerate is 30 fps for both Standard and Premium encoding.

备用模式StandBy mode

创建实时事件时,可以将其设置为备用模式。When you create a live event, you can set it to StandBy mode. 当事件处于备用模式时,你可以编辑“说明”、“静态主机名前缀”并限制输入和预览访问设置。While the event is in StandBy mode, you can edit the Description, the Static hostname prefix and restrict input and preview access settings. 备用模式仍为可计费模式,但价格不同于启动实时传送流时的价格。StandBy mode is still a billable mode, but is priced differently than when you start a live stream.

有关详细信息,请参阅实时事件状态和计费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.

备注

从 2020-05-01 API 版本开始,虚 URL 称为静态主机名As of the 2020-05-01 API release, vanity URLs are known as Static Host Names

可以使用非虚 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 auto-generate 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 称为“静态主机名前缀”。In the Azure portal, the vanity URL is named "Static hostname prefix".

    若要在 API 中指定此模式,请在创建时将 useStaticHostName 设为 true(默认值为 false)。To specify this mode in the API, set useStaticHostName to true at creation time (default is false). 如果 useStaticHostname 设置为 true,则 hostnamePrefix 指定分配给实时事件预览和引入终结点的主机名的第一部分。When useStaticHostname is set to true, the hostnamePrefix specifies the first part of the hostname assigned to the live event preview and ingest endpoints. 最终主机名将是此前缀、媒体服务帐户名称和 Azure 媒体服务数据中心的短代码的组合。The final hostname would be a combination of this prefix, the media service account name and a short code for the Azure Media Services data center.

    为了避免 URL 中出现随机令牌,在创建时还需要传递你自己的访问令牌 (LiveEventInput.accessToken)。To avoid a random token in the URL, you also need to pass your own access token (LiveEventInput.accessToken) at creation time. 访问令牌必须是有效的 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

在以下路径中,<live-event-name> 表示为事件指定的名称或在创建实时事件时使用的自定义名称。In the following paths, <live-event-name> means either the name given to the event or the custom name used in the creation of the live event.

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