使用 Azure 媒体服务 v3 实时传送视频流Live streaming with Azure Media Services v3

Note

Google Widevine 目前在中国地区不可用。Google Widevine is not avaliable in China regions now.

使用 Azure 媒体服务可将直播活动传送到 Azure 云中的客户。Azure Media Services enables you to deliver live events to your customers on the Azure cloud. 若要使用媒体服务流式传输直播活动,需要以下组件:To stream your live events with Media Services, you need the following:

  • 一个相机,用于捕获直播活动。A camera that is used to capture the live event.
    有关设置建议,请查看简单且可移植的事件视频设备设置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 to generate a live feed from a video file.

  • 一个实时视频编码器,用于将相机(或其他设备,例如便携式计算机)的信号转换为可发送到媒体服务的贡献源。A live video encoder that converts signals from a camera (or another device, like a laptop) into a contribution feed that is sent to Media Services. 贡献源可包括与广告相关的信号,例如 SCTE-35 标记。The contribution feed can include signals related to advertising, such as SCTE-35 markers.
    有关推荐的实时传送视频流编码器的列表,请参阅实时传送视频流编码器For a list of recommended live streaming encoders, see live streaming encoders. 另外,请查看以下博客:采用 OBS 的实时传送视频流生产Also, check out this blog: Live streaming production with OBS.

  • 媒体服务中的组件,用于引入、预览、打包、记录、加密实时事件并将其广播给客户。Components in Media Services, which enable you to ingest, preview, package, record, encrypt, and broadcast the live event to your customers.

本文提供有关使用媒体服务实时传送视频流的概述和指导,并提供其他相关文章的链接。This article gives an overview and guidance of live streaming with Media Services and links to other relevant articles.

Note

目前,无法使用 Azure 门户来管理 v3 资源。Currently, you cannot use the Azure portal to manage v3 resources. 请使用 REST APICLI 或受支持的 SDK 之一。Use the REST API, CLI, or one of the supported SDKs.

动态打包Dynamic Packaging

借助媒体服务,可以利用动态打包,以便预览和广播正在发送到服务的贡献源中采用 MPEG DASH、HLS 和平滑流式处理格式的实时传送流。With Media Services, you can take advantage of Dynamic Packaging, which allows you to preview and broadcast your live streams in MPEG DASH, HLS, and Smooth Streaming formats from the contribution feed that is being sent to the service. 观看者可以使用任何与 HLS、DASH 或平滑流式处理兼容的播放器播放实时流。Your viewers can play back the live stream with any HLS, DASH, or Smooth Streaming compatible players. 可以使用 Web 应用程序或移动应用程序中的 Azure Media Player 传送采用上述任何协议的流。You can use Azure Media Player in your web or mobile applications to deliver your stream in any of these protocols.

动态加密Dynamic Encryption

使用动态加密可以借助 AES-128 或两种主要数字版权管理 (DRM) 系统中的任何一种对直播或点播内容进行动态加密:Microsoft PlayReady 和 Apple FairPlay。Dynamic encryption enables you to dynamically encrypt your live or on-demand content with AES-128 or any of the two major digital rights management (DRM) systems: Microsoft PlayReady, and Apple FairPlay. 媒体服务还提供了用于向已授权客户端传送 AES 密钥和 DRM(PlayReady 和 FairPlay)许可证的服务。Media Services also provides a service for delivering AES keys and DRM (PlayReady and FairPlay) licenses to authorized clients. 有关详细信息,请参阅动态加密For more information, see Dynamic encryption.

动态清单Dynamic Manifest

动态筛选用于控制发送到播放器的轨迹数目、格式、比特率和演播时间窗口。Dynamic filtering is used to control the number of tracks, formats, bitrates, and presentation time windows that are sent out to the players. 有关详细信息,请参阅筛选器和动态清单For more information, see filters and dynamic manifests.

实时事件类型Live Event types

直播活动负责引入和处理实时视频源。Live Events are responsible for ingesting and processing the live video feeds. 实时事件可以是下述两种类型之一:直通和实时编码。A Live Event can be one of two types: pass-through and live encoding. 有关媒体服务 v3 中的实时传送视频流的详细信息,请参阅实时事件和实时输出For details about live streaming in Media Services v3, see Live Events and Live Outputs.

直通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 input protocol). 实时事件随后会通过传入视频流进入动态打包器(流式处理终结点),而无需经过进一步的转码。The Live Event then carries through the incoming video streams to the dynamic packager (Streaming Endpoint) without any further transcoding. 此类直通实时事件已针对长时间运行的实时事件或 24x365 线性实时传送视频流进行优化。Such a pass-through Live Event is optimized for long-running live events or 24x365 linear live streaming.

实时编码Live encoding

实时编码

将云编码与媒体服务配合使用时,需配置本地实时编码器,以便将单比特率视频作为贡献源(最大聚合比特率为 32Mbps)发送到实时事件(使用 RTMP 或分段 MP4 输入协议)。When using cloud encoding with Media Services, you would configure your on-premises live encoder to send a single bitrate video as the contribution feed (up to 32Mbps aggregate) to the Live Event (using RTMP or fragmented-MP4 input protocol). 实时事件会将传入的单比特率流转码为不同分辨率的多比特率视频流,以改善传输性能,并使其可通过 MPEG-DASH、Apple HTTP Live Streaming (HLS) 和 Microsoft 平滑流式处理等行业标准协议传送到播放设备。The Live Event transcodes the incoming single bitrate stream into multiple bitrate video streams at varying resolutions to improve delivery and makes it available for delivery to playback devices via industry standard protocols like MPEG-DASH, Apple HTTP Live Streaming (HLS), and Microsoft Smooth Streaming.

实时传送视频流工作流Live streaming workflow

若要了解媒体服务 v3 中的实时传送视频流工作流,首先需要查看并理解以下概念:To understand the live streaming workflow in Media Services v3, you have to first review and understand the following concepts:

常规步骤General steps

  1. 在媒体服务帐户中,确保流式处理终结点(来源)正在运行。In your Media Services account, make sure the Streaming Endpoint (Origin) is running.

  2. 创建直播活动Create a Live Event.
    创建事件时,可以将其启动方式指定为自动启动。When creating the event, you can specify to autostart it. 或者,可以在准备好开始流式传输后,启动事件。Alternatively, you can start the event when you are ready to start streaming.
    如果将 autostart 设置为 true,则直播活动会在创建后立即启动。When autostart is set to true, the Live Event will be started right 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. 有关详细信息,请参阅直播活动状态和计费For more information, see Live Event states and billing.

  3. 获取引入 URL 并配置本地编码器以使用 URL 发送贡献源。Get the ingest URL(s) and configure your on-premises encoder to use the URL to send the contribution feed.
    请参阅推荐的实时编码器See recommended live encoders.

  4. 获取预览 URL 并使用它验证来自编码器的输入是否实际接收。Get the preview URL and use it to verify that the input from the encoder is actually being received.

  5. 创建新的资产对象。Create a new Asset object.

    每个实时输出与一个资产相关联,用于将视频记录到关联的 Azure Blob 存储容器。Each Live Output is associated with an asset, which it uses to record the video into the associated Azure blob storage container.

  6. 创建实时输出并使用创建的资产名称,使流能够存档到资产中。Create a Live Output and use the asset name that you created so that the stream can be archived into the asset.

    实时输出在创建时启动,在删除后停止。Live Outputs start on creation and stop when deleted. 删除实时输出不会删除基础资产和该资产中的内容。When you delete the Live Output, you are not deleting the underlying asset and content in the asset.

  7. 使用内置的流式处理策略类型创建流定位符Create a Streaming Locator with the built-in Streaming Policy types.

    若要发布实时输出,必须为关联的资产创建流定位符。To publish the Live Output, you must create a Streaming Locator for the associated asset.

  8. 列出流式处理定位器的路径,以取回要使用的 URL(这些是确定性的) 。List the paths on the Streaming Locator to get back the URLs to use (these are deterministic).

  9. 获取要从中流式传输的流式处理终结点(来源)的主机名。Get the hostname for the Streaming Endpoint (Origin) you wish to stream from.

  10. 将步骤 8 中的 URL 与步骤 9 中的主机名合并,获取完整的 URL。Combine the URL from step 8 with the hostname in step 9 to get the full URL.

  11. 如果希望停止查看直播活动,则需要停止流式处理活动并删除流式处理定位符If you wish to stop making your Live Event viewable, you need to stop streaming the event and delete the Streaming Locator.

  12. 如果已完成流式处理事件,并想要清理先前设置的资源,请遵循以下过程。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 Live Event. 直播活动在停止后,不会产生任何费用。Once the Live Event 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 Live Event is in stopped state, it will not incur any charges.

实时输出要存档到的资产,在删除实时输出时,会自动成为点播资产。The asset that the live output is archiving to, automatically becomes an on-demand asset when the live output is deleted. 必须先删除所有实时输出,然后才能停止实时事件。You must delete all live outputs before a live event can be stopped. 在停止时,可以使用可选标志 removeOutputsOnStop 自动删除实时输出。You can use an optional flag removeOutputsOnStop to automatically remove live outputs on stop.

Tip

请参阅实时传送视频流教程,其中介绍了实现上述步骤的代码。See Live streaming tutorial, the article examines the code that implements the steps described above.

其他重要文章Other important articles

后续步骤Next steps