YouTube Live Streaming API - 了解直播和直播
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南简要介绍了广播和数据流。此外,本文还将讨论一些用例,展示了广播公司如何使用 YouTube Live Streaming API 创建和管理这些资源。
其余部分介绍了三个用例,说明了 API 用户通常如何使用广播和流式传输。
配置单个编码器
在最常见的 API 用例中,您的 YouTube 频道有一系列已安排或周期性的直播活动。作为频道所有者,您只有一个编码器,并且只想配置一次该编码器。因此,您需要执行以下步骤:
- 在 API 中创建一个
liveStream
资源。
- 使用该资源中的内容传送设置来为频道配置编码器。
请注意,如果您有多个频道,则必须为每个频道创建不同的直播。
- 在 API 中创建
liveBroadcast
资源,并将这些资源绑定到 liveStream
资源。在这种情况下,您为频道安排的每项直播活动都使用相同的直播设置。不过,任何时候都只能有一项直播活动进行,而且每次直播活动的视频内容都是唯一的。
- 每次有活动发生时,请将直播状态更新为
testing
或 live
,然后继续在 YouTube 上播放该活动。
为每次直播创建一个直播
另一种常见方法是为每个直播创建一个单独的视频流。在这种情况下,您需要为每个 liveBroadcast
资源创建不同的 liveStream
资源,然后将流式编码器配置为针对每次直播使用适当的设置。
如果您的频道有多个周期性广播,以致于两个广播可能同时进行,那么这种方法就很实用,因为两个广播不能使用相同的在线播放设置。事实上,您的频道可能会将每个周期性广播视为一个节目,并为每个节目仅创建一个 liveStream
资源。然后,同一节目的每一集都代表一次广播,并且同一节目的所有广播都可以绑定到同一个视频流。
使用一个视频流创建多个同步直播
在这种情况下,您需要将一个直播视频流拆分为多个同时进行的直播。因此,您有一个 liveStream
资源绑定到两个(或更多)同时具有 live
状态的 liveBroadcast
资源。
例如,假设您的频道广播了一个全天候的实时 Feed,但您还想为此次广播期间发生的采访制作单独的视频。在这种情况下,采访内容是全天候广播内容的子集。
为了处理这种情况,您需要创建两个 liveBroadcast
资源,并将两个广播绑定到同一个流。全天候广播正在进行,在面试开始之前,其资源就处于 live
状态。访谈开始时,您可以将与访谈关联的资源的状态更新为 live
,而无需更改全天候广播的资源。因此,您将相同的内容同时流式传输到两个单独的视频。
访谈结束后,您可以再次更新访谈广播的资源,这次将其状态设为 complete
。但是,您不会停止流式传输视频,因为全天候直播仍在继续。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-15。
[null,null,["最后更新时间 (UTC):2024-08-15。"],[[["\u003cp\u003eA broadcast represents a live event on YouTube, functioning as a distinct video, and it must be linked to one stream.\u003c/p\u003e\n"],["\u003cp\u003eA stream is used to send audio-video content to YouTube, defining the settings for that stream, and one stream can be connected to up to three live broadcasts.\u003c/p\u003e\n"],["\u003cp\u003eBroadcasters often use the same stream for numerous broadcasts that occur at different times, reusing stream settings and reducing redundant setup.\u003c/p\u003e\n"],["\u003cp\u003eThe API can be used in multiple ways, whether it be one stream for multiple broadcasts, one stream per broadcast, or a single stream being split into multiple simultaneous broadcasts.\u003c/p\u003e\n"],["\u003cp\u003eChannels can use the API to schedule recurring live events with a single encoder, configuring it just once for multiple broadcasts.\u003c/p\u003e\n"]]],["Broadcasts represent distinct YouTube live events, each bound to one stream. Streams transmit audio-video content to YouTube and define streaming settings. Broadcasters often reuse streams for multiple broadcasts at different times. Common use cases include: configuring one stream for multiple scheduled broadcasts, creating a unique stream per broadcast, or using a single stream for simultaneous broadcasts. For the last case, one stream can be used to have up to 3 simultaneous live broadcasts. API users create and bind these resources.\n"],null,["# YouTube Live Streaming API - Understanding Broadcasts and Streams\n\nThis guide provides a brief overview of **broadcasts** and **streams**. It also discusses use cases that show how broadcasters use the YouTube Live Streaming API to create and manage those resources.\n\n- A **broadcast** represents an event that can be watched on YouTube as it happens. Each broadcast is a distinct YouTube video. A broadcast can be and needs to be bound to exactly one stream.\n\n- A **stream** enables you to transmit audio-video content to YouTube, and it defines the settings for how you stream your content to YouTube. The same stream can be bound to up to three live broadcasts. It is also common for broadcasters to reuse the same stream for many different broadcasts if those broadcasts occur at different times.\n\nThe remaining sections present three use cases that explain how API users typically use broadcasts and streams.\n\nConfigure a single encoder\n--------------------------\n\nIn the most common API use case, your YouTube channel has a series of scheduled or recurring live events. As the channel owner, you have a single encoder and only want to configure the encoder one time. So, you perform the following steps:\n\n1. Create one [liveStream](/youtube/v3/live/docs/liveStreams) resource in the API.\n2. Use the content delivery settings from that resource to configure the encoder for the channel.\n3. Note that, if you have multiple channels, you must create a different stream for each channel.\n4. Create [liveBroadcast](/youtube/v3/live/docs/liveBroadcasts) resources in the API and [bind](/youtube/v3/live/docs/liveBroadcasts/bind) all of those resources to the [liveStream](/youtube/v3/live/docs/liveStreams) resource. In this scenario, every live event that you schedule for your channel uses the same streaming settings. However, only one event is live at any given time, and the video content for each broadcast is unique.\n5. Any time an event occurs, update the broadcast's status to either `testing` or `live` and proceed to broadcast that event on YouTube.\n\nCreate one stream per broadcast\n-------------------------------\n\nAnother common approach is to create a separate stream for each broadcast. In this scenario, you would create a distinct [liveStream](/youtube/v3/live/docs/liveStreams) resource for each [liveBroadcast](/youtube/v3/live/docs/liveBroadcasts) resource and then configure your streaming encoder to use the appropriate settings for each broadcast.\n\nThis approach might make sense if your channel has multiple recurring broadcasts such that two broadcasts might occur simultaneously, making it infeasible for both broadcasts to use the same streaming settings. In fact, your channel might treat each recurring broadcast as a show and just create one [liveStream](/youtube/v3/live/docs/liveStreams) resource per show. Then, each episode of the same show would represent a broadcast, and all broadcasts of the same show could be bound to the same stream.\n\nUse one stream to create simultaneous broadcasts\n------------------------------------------------\n\nIn this scenario, you want to split a live stream into multiple, simultaneous broadcasts. As such, you have one [liveStream](/youtube/v3/live/docs/liveStreams) resource that is bound to two (or more) [liveBroadcast](/youtube/v3/live/docs/liveBroadcasts) resources that have a `live` status at the same time.\n\nFor example, suppose your channel broadcasts a 24/7 live feed, but you also want to create a separate video for an interview that occurs during that broadcast. In this case, the interview content is a subset of the 24/7 broadcast's content.\n\nTo handle this case, you create two `liveBroadcast` resources and bind both broadcasts to the same stream. The 24/7 broadcast is ongoing and its resource has a `live` status long before the interview begins. When the interview begins, you update the status of the resource associated with the interview to `live` without changing the 24/7 broadcast's resource. Thus, you are streaming the same content to two separate videos at the same time.\n\nWhen the interview ends, you update the interview broadcast's resource again, this time setting its status to `complete`. However, you don't stop streaming video since the 24/7 broadcast continues."]]