透過 RTMPS 提交 YouTube 直播內容
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本文說明如何使用 RTMPS,從編碼器將即時資料串流至 YouTube。RTMPS 是透過 SSL 連線傳輸的標準 RTMP (即時訊息傳遞通訊協定) 影片串流。本文件適用於想在已支援 RTMP 的編碼器中新增 RTMPS 支援功能的編碼器供應商。
RTMPS 是大多數一般使用者內容的合適選擇,特別是需要低延遲的內容。如要瞭解 YouTube 直播支援的各種內容攝入通訊協定,請參閱內容攝入通訊協定比較。
需求條件
如要透過 RTMPS 將內容傳送至 YouTube 直播,請務必留意以下事項:
- 連線網址 (
<protocol>://<server>/<path>
) 的每個部分都必須正確:
- 通訊協定必須是
rtmps
。
- 伺服器必須是有效的 YouTube RTMPS 擷取端點。
- 路徑必須是有效的 YouTube 直播 RTMP 應用程式名稱。
- 連線必須連至擷取伺服器上的通訊埠 443。
- 多媒體串流必須透過 RTMPS 傳送,也就是透過 SSL 連線使用 RTMP。
取得連線網址
如果編碼器已使用 YouTube Live API,取得 RTMPS 擷取網址的程序與 RTMP 類似。傳送 LiveStreams insert (POST) 要求,建立新的擷取串流。在回應中,cdn.ingestionInfo.rtmpsIngestionAddress
欄位會指定 RTMPS 網址。如果您支援雙重擷取,備份地址為 cdn.ingestionInfo.rtmpsBackupIngestionAddress
。
建立連線
使用偏好的通訊端程式庫,在擷取網址指定的伺服器上,建立通訊埠 443 的 SSL/TLS 連線。由於 TLS 僅適用於傳輸層,因此啟動連線時不一定需要伺服器主機名稱,但與我們伺服器進行驗證時則必須提供。因此請務必在 SSL 交握中新增 SNI 擴充功能 (伺服器名稱指示),並將伺服器名稱設為您要連線的伺服器主機名稱。
建立 SSL 連線後,請將其做為 RTMP 用戶端程式庫的連線。初始化的 SSL 連線與標準 TCP 連線具有相同的 API,因此 RTMP 程式庫應能以相同方式處理這兩種連線。
疑難排解
安全資料傳輸層 (SSL) 錯誤
如果嘗試建立 SSL 連線時收到無效憑證,可能是因為你連線至預期使用 RTMP 的 YouTube 伺服器。請確認使用的伺服器名稱含有「rtmps」(請注意「s」)。
如果網址正確,但仍然出現 SSL 錯誤,可能是連線至錯誤的通訊埠。確認連線至通訊埠 443。
如果網址和連接埠正確無誤,可能是 SSL 程式庫無法正確處理憑證。尋找有關 SSL 失敗的低階診斷訊息,並仔細檢查您是否在交握中使用 SNI。
連線逾時
如果可以連線至伺服器,但 RTMP 程式庫逾時,且未收到任何有意義的回應,可能是因為你設定了連線至 YouTube 伺服器的明文 RTMP 連線,但該伺服器預期會收到 RTMPS。請務必建立 SSL 連線,而非純 TCP 連線。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eRTMPS is a secure method for streaming live data to YouTube, using RTMP through an SSL connection.\u003c/p\u003e\n"],["\u003cp\u003eTo use RTMPS, ensure the connection URL is correct, including the \u003ccode\u003ertmps\u003c/code\u003e protocol, a valid YouTube ingestion endpoint, and a valid application name.\u003c/p\u003e\n"],["\u003cp\u003eConnections must be made to port 443, and the server hostname is required for authentication via the SNI extension in the SSL handshake.\u003c/p\u003e\n"],["\u003cp\u003eEncoder vendors can retrieve the RTMPS ingestion URL from the \u003ccode\u003ecdn.ingestionInfo.rtmpsIngestionAddress\u003c/code\u003e field in the response of a LiveStreams insert request, similar to RTMP.\u003c/p\u003e\n"],["\u003cp\u003eCommon issues like SSL errors and connection timeouts often arise from incorrect server names, ports, or improper SSL setup, and usually indicate a cleartext RTMP connection is being attempted instead of RTMPS.\u003c/p\u003e\n"]]],["To stream live on YouTube using RTMPS, ensure the URL protocol is `rtmps`, the server is a valid YouTube RTMPS endpoint, and the path is a valid application name. Connect to port 443 with an SSL/TLS connection, including the SNI extension with the server hostname for authentication. Obtain the RTMPS URL via a `LiveStreams insert` request from the YouTube Live API. After establishing the SSL connection, use it with your RTMP library to send the multimedia stream.\n"],null,["# Delivering Live YouTube Content via RTMPS\n\nThis document explains how to use RTMPS to stream live data on YouTube from an\nencoder. RTMPS is a regular RTMP (RealTime Messaging Protocol) video stream\ntunneled through an SSL connection. This document is intended for encoder\nvendors who want to add support for RTMPS to encoders that already support RTMP.\n\nRTMPS is a good choice for most ordinary user content, especially if it requires\nlow latency. See the\n[Ingestion Protocol Comparison](/youtube/v3/live/guides/ingestion-protocol-comparison)\nfor an overview of the different ingestion protocols that YouTube Live Streaming\nsupports.\n\nRequirements\n------------\n\nSending RTMPS to YouTube Live has a few prerequisites:\n\n- Each part of the connection URL (`\u003cprotocol\u003e://\u003cserver\u003e/\u003cpath\u003e`) must be correct:\n - The protocol must be `rtmps`.\n - The server must be a valid YouTube RTMPS ingestion endpoint.\n - The path must be a valid YouTube Live RTMP application name.\n- The connection must be made to port 443 on the ingestion server.\n- The multimedia stream must be sent with RTMPS; that is, using RTMP over an SSL connection.\n\nGetting the connection URL\n--------------------------\n\nIf your encoder already uses the YouTube Live API, then the process for getting\nan RTMPS ingestion URL is similar to the one for RTMP. Send a\n[LiveStreams insert (POST)](/youtube/v3/live/docs/liveStreams/insert) request to\ncreate a new ingestion stream. In the response, the\n[`cdn.ingestionInfo.rtmpsIngestionAddress`](/youtube/v3/live/docs/liveStreams#cdn.ingestionInfo.rtmpsIngestionAddress)\nfield specifies the RTMPS URL. If you support dual ingestion, the backup address\nis [`cdn.ingestionInfo.rtmpsBackupIngestionAddress`](/youtube/v3/live/docs/liveStreams#cdn.ingestionInfo.rtmpsBackupIngestionAddress).\n\nCreating the connection\n-----------------------\n\nUse your preferred socket library to create an SSL/TLS connection to port 443 at\nthe server that the ingestion URL specifies. Since TLS works only with the\ntransport layer, the server hostname is not strictly required to initiate the\nconnection; however, it is required for authentication with our servers. So make\nsure you add the SNI extension (Server Name Indication) to your SSL handshake,\nand set the server name to the server hostname you're connecting to.\n\nOnce the SSL connection is established, use it as the connection for your RTMP\nclient library. An initialized SSL connection has the same API as a standard TCP\nconnection, and so the RTMP library should be able to work with both of them\nidentically.\n\nTroubleshooting\n---------------\n\n### SSL errors\n\nIf you attempt to create an SSL connection but get an invalid certificate, then\nyou are probably connecting to a YouTube server that expects RTMP. Make sure\nthat the server name you use has \"rtmps\" in it --- note the \"s\".\n\nIf the URL looks correct but you still get an SSL error, you might be connecting\nto the wrong port. Confirm that you're connecting to port 443.\n\nIf the URL and port are correct, your SSL library might not be handling the\ncertificate correctly. Look for low-level diagnostic messages about SSL\nfailures, and double-check that you're using SNI in the handshake.\n\n### Connection timed out\n\nIf you can connect to the server, but your RTMP library times out without\ngetting a sensible response, you might have set up a cleartext RTMP connection\nto a YouTube server that expects RTMPS. Make sure that you're creating an SSL\nconnection, not a plain TCP connection."]]