API สตรีมมิงแบบสดของ YouTube - ทำความเข้าใจการออกอากาศและสตรีม
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คู่มือนี้จะให้ภาพรวมคร่าวๆ เกี่ยวกับการออกอากาศและสตรีม นอกจากนี้ยังพูดถึงกรณีการใช้งานที่แสดงให้เห็นว่าผู้ออกอากาศใช้ YouTube Live Streaming API ในการสร้างและจัดการทรัพยากรเหล่านั้นอย่างไร
-
การออกอากาศแสดงถึงกิจกรรมที่ผู้ชมรับชมได้บน YouTube แบบเรียลไทม์ การออกอากาศแต่ละครั้งคือวิดีโอ YouTube ที่แตกต่างกัน การออกอากาศสามารถเป็นได้และต้องเชื่อมโยงกับสตรีมเพียงสตรีมเดียว
-
สตรีมช่วยให้คุณสามารถส่งเนื้อหาเสียงและวิดีโอไปยัง YouTube รวมถึงกำหนดการตั้งค่าสำหรับวิธีสตรีมเนื้อหาของคุณไปยัง YouTube สตรีมเดียวกันสามารถออกอากาศสดได้สูงสุด 3 รายการ นอกจากนี้ผู้ออกอากาศยังมักนำสตรีมเดียวกันไปใช้ซ้ำสำหรับการถ่ายทอดสดหลายรายการ หากการออกอากาศเหล่านั้นเกิดขึ้นในเวลาที่ต่างกัน
ส่วนที่เหลือจะแสดงกรณีการใช้งาน 3 กรณีซึ่งอธิบายวิธีที่โดยทั่วไปแล้วผู้ใช้ API ใช้การออกอากาศและสตรีม
กำหนดค่าโปรแกรมเปลี่ยนไฟล์เดียว
ในกรณีการใช้งาน API ที่พบบ่อยที่สุด ช่อง YouTube ของคุณมีซีรีส์การถ่ายทอดสดที่กำหนดเวลาไว้หรือเกิดซ้ำ ในฐานะเจ้าของช่อง คุณมีโปรแกรมเปลี่ยนไฟล์เดียวและต้องการกำหนดค่าโปรแกรมเปลี่ยนไฟล์เพียงครั้งเดียวเท่านั้น ให้คุณทำตามขั้นตอนต่อไปนี้
- สร้างทรัพยากร
liveStream
1 รายการใน API
- ใช้การตั้งค่าการส่งเนื้อหาจากทรัพยากรนั้นเพื่อกำหนดค่าโปรแกรมเปลี่ยนไฟล์สำหรับช่อง
โปรดทราบว่าหากมีหลายช่อง คุณต้องสร้างสตรีมที่แตกต่างกันสำหรับแต่ละช่อง
- สร้างทรัพยากร
liveBroadcast
ใน API แล้วเชื่อมโยงทรัพยากรเหล่านั้นทั้งหมดกับทรัพยากร liveStream
ในสถานการณ์นี้ การถ่ายทอดสดทุกรายการที่คุณกำหนดเวลาให้ช่องจะใช้การตั้งค่าสตรีมมิงแบบเดียวกัน อย่างไรก็ตาม จะมีการถ่ายทอดสดเพียงหนึ่งรายการเท่านั้นในช่วงเวลาหนึ่งๆ และเนื้อหาวิดีโอสำหรับการออกอากาศแต่ละครั้งจะไม่ซ้ำกัน
- เมื่อใดก็ตามที่มีกิจกรรมเกิดขึ้น ให้อัปเดตสถานะของการออกอากาศเป็น
testing
หรือ live
และดำเนินการออกอากาศกิจกรรมดังกล่าวบน YouTube
สร้าง 1 สตรีมต่อการออกอากาศ
วิธีการที่ใช้กันทั่วไปอีกอย่างคือการสร้างสตรีมแยกสำหรับการออกอากาศแต่ละครั้ง ในสถานการณ์นี้ คุณจะต้องสร้างทรัพยากร liveStream
ที่แตกต่างกันสำหรับทรัพยากร liveBroadcast
แต่ละรายการ แล้วกำหนดค่าโปรแกรมเปลี่ยนไฟล์สตรีมมิงเพื่อใช้การตั้งค่าที่เหมาะสมสำหรับการออกอากาศแต่ละครั้ง
วิธีนี้อาจเหมาะสมหากช่องของคุณมีการออกอากาศที่เกิดซ้ำหลายรายการจนอาจมีการออกอากาศ 2 ครั้งพร้อมกัน ทำให้ไม่สามารถใช้การตั้งค่าการสตรีมเดียวกัน อันที่จริงแล้ว ช่องของคุณอาจพิจารณาการออกอากาศที่เกิดซ้ำแต่ละรายการเป็นโชว์ และสร้างทรัพยากร liveStream
เพียง 1 รายการต่อรายการ จากนั้น แต่ละตอนของรายการเดียวกันจะแสดงถึงการออกอากาศ และการออกอากาศทุกรายการของรายการเดียวกันอาจผูกกับสตรีมเดียวกันได้
ใช้สตรีมเดียวเพื่อสร้างการออกอากาศพร้อมกัน
ในกรณีนี้ คุณต้องแยกสตรีมแบบสดออกเป็นหลายๆ รายการที่ออกอากาศพร้อมกัน ด้วยเหตุนี้ คุณจึงมีทรัพยากร liveStream
จำนวน 1 รายการที่เชื่อมโยงกับทรัพยากร liveBroadcast
2 รายการ (ขึ้นไป) ที่มีสถานะ live
ในเวลาเดียวกัน
ตัวอย่างเช่น สมมติว่าช่องของคุณออกอากาศฟีดสดทุกวันตลอด 24 ชั่วโมง แต่คุณต้องการสร้างวิดีโอแยกต่างหากสำหรับการสัมภาษณ์ที่เกิดขึ้นระหว่างการออกอากาศนั้นด้วย ในกรณีนี้ เนื้อหาบทสัมภาษณ์เป็นส่วนหนึ่งของเนื้อหาที่ออกอากาศทุกวันตลอด 24 ชั่วโมง
ในการจัดการกรณีนี้ คุณต้องสร้างทรัพยากร liveBroadcast
2 รายการ แล้วเชื่อมโยงการออกอากาศทั้ง 2 รายการกับสตรีมเดียวกัน การออกอากาศทุกวันตลอด 24 ชั่วโมงกำลังดำเนินอยู่ และแหล่งข้อมูลจะมีสถานะ live
ก่อนที่การสัมภาษณ์จะเริ่มต้น เมื่อการสัมภาษณ์เริ่มต้นขึ้น คุณจะอัปเดตสถานะของทรัพยากรที่เกี่ยวข้องกับการสัมภาษณ์เป็น live
โดยไม่เปลี่ยนแหล่งข้อมูลของการออกอากาศทุกวันตลอด 24 ชั่วโมง คุณจึงสตรีมเนื้อหาเดียวกันไปยัง 2 วิดีโอแยกกันในเวลาเดียวกัน
เมื่อการสัมภาษณ์สิ้นสุดลง คุณจะอัปเดตแหล่งข้อมูลของการออกอากาศการสัมภาษณ์อีกครั้ง โดยตั้งสถานะเป็น complete
แต่จะไม่หยุดสตรีมวิดีโอเนื่องจากจะมีการออกอากาศทุกวันตลอด 24 ชั่วโมงต่อไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-08-15 UTC
[null,null,["อัปเดตล่าสุด 2024-08-15 UTC"],[[["\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."]]