ממשק API של סטרימינג בשידור חי ב-YouTube – הבנת שידורים וסטרימינג
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מדריך זה מספק סקירה כללית קצרה של שידורים ושידורים. נסביר גם על תרחישים לדוגמה שמראים איך שדרנים משתמשים ב-YouTube Live Streaming API כדי ליצור ולנהל את המשאבים האלה.
-
שידור מייצג אירוע שאפשר לצפות בו ב-YouTube בזמן שהוא מתרחש. כל שידור הוא סרטון YouTube נפרד. שידור יכול להיות מקושר לשידור אחד בלבד.
-
סטרימינג מאפשר לכם לשדר תוכן אודיו-וידאו ל-YouTube, וקובע את ההגדרות לשידור של התוכן ב-YouTube. אפשר לקשר את אותו שידור לשלושה שידורים חיים לכל היותר. בנוסף, רשתות שידור משתמשות שוב באותו שידור לשידורים שונים, אם השידורים האלה מתרחשים בזמנים שונים.
בקטעים הנותרים מוצגים שלושה תרחישים לדוגמה שמסבירים איך משתמשי API משתמשים בדרך כלל בשידורים ובסטרימינג.
הגדרת מקודד יחיד
בתרחיש לדוגמה הנפוץ ביותר לשימוש ב-API, ערוץ YouTube שלכם כולל סדרה של אירועים בשידור חי מתוזמנים או חוזרים. כבעלים של הערוץ, יש לכם מקודד אחד ואתם רוצים להגדיר את המקודד רק פעם אחת. בהתאם לכך, מבצעים את השלבים הבאים:
- יצירת משאב אחד מסוג
liveStream
ב-API.
- משתמשים בהגדרות של העברת התוכן מהמשאב הזה כדי להגדיר את המקודד של הערוץ.
שימו לב: אם יש לכם מספר ערוצים, תצטרכו ליצור שידור שונה לכל ערוץ.
- צריך ליצור משאבים מסוג
liveBroadcast
ב-API ולקשר את כל המשאבים האלה למשאב liveStream
. בתרחיש הזה, כל אירוע בשידור חי שתתזמנו לערוץ שלכם ישתמש באותן הגדרות סטרימינג. עם זאת, רק אירוע אחד פעיל בכל רגע נתון, ותוכן הווידאו בכל שידור הוא ייחודי.
- בכל פעם שמתרחש אירוע, עליך לעדכן את סטטוס השידור ל
testing
או ל-live
ולהמשיך לשדר את האירוע ב-YouTube.
יצירת שידור אחד לכל שידור
גישה נפוצה נוספת היא ליצור שידור נפרד לכל שידור. בתרחיש הזה, יוצרים משאב liveStream
ייחודי לכל משאב liveBroadcast
, ולאחר מכן מגדירים את מקודד הסטרימינג כך שישתמש בהגדרות המתאימות לכל שידור.
גישה זו עשויה להיות הגיונית אם הערוץ שלך כולל שידורים חוזרים מרובים, כך ששני שידורים עשויים להתרחש בו-זמנית, כך ששני השידורים לא יכולים להשתמש באותן הגדרות סטרימינג. למעשה, הערוץ שלך יכול להתייחס לכל שידור חוזר כאל תוכנית וליצור משאב liveStream
אחד לכל תוכנית. לאחר מכן, כל פרק של אותה תוכנית ייצג שידור, וכל השידורים של אותה תוכנית יכולים להיות מקושרים לאותו שידור.
להשתמש בשידור חי כדי ליצור שידורים בו-זמנית
בתרחיש הזה, רוצים לפצל שידור חי לכמה שידורים בו-זמנית. לכן יש לך משאב אחד מסוג liveStream
שמקושר לשני משאבים (או יותר) מסוג liveBroadcast
בסטטוס live
בו-זמנית.
לדוגמה, נניח שהערוץ שלכם משדר פיד בשידור חי שפתוח 24/7, אבל אתם רוצים גם ליצור סרטון נפרד לריאיון שמתבצע במהלך אותו שידור. במקרה זה, תוכן הראיון הוא חלק מתוכן השידור מסביב לשעון.
כדי לטפל במקרה הזה, צריך ליצור שני משאבים של liveBroadcast
ולחבר את שני השידורים לאותו שידור. השידור מתבצע 24/7 באופן קבוע, והמשאב שלו נמצא בסטטוס live
זמן רב לפני תחילת הריאיון. כשהריאיון מתחיל, מעדכנים את סטטוס המשאב המשויך לריאיון ל-live
בלי לשנות את משאב השידור 24/7. לכן, אתם משדרים את אותו תוכן לשני סרטונים נפרדים בו-זמנית.
כשהריאיון יסתיים, מעדכנים שוב את מקור המידע של שידור הריאיון, והפעם הסטטוס שלו הוא complete
. עם זאת, לא תפסיקו לצפות בווידאו כי השידור החי 24/7 נמשך.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2024-08-15 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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."]]