通过 RTMPS 提交 YouTube 直播内容
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档介绍了如何使用 RTMPS 从编码器将实时数据流式传输到 YouTube。RTMPS 是通过 SSL 连接建立隧道的常规 RTMP(实时消息传递协议)视频流。本文档面向希望为已支持 RTMP 的编码器添加 RTMPS 支持的编码器供应商。
RTMPS 是大多数普通用户内容的理想选择,尤其是在需要低延迟的情况下。如需大致了解 YouTube 直播支持的不同推流协议,请参阅推流协议比较。
要求
向 YouTube 直播发送 RTMPS 需满足以下几项前提条件:
- 连接网址 (
<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 仅适用于传输层,因此严格来说,启动连接不需要服务器主机名;不过,使用我们的服务器进行身份验证时需要服务器主机名。因此,请务必将 SNI 扩展程序(服务器名称指示)添加到 SSL 握手中,并将服务器名称设置为您要连接的服务器主机名。
SSL 连接建立后,将其用作 RTMP 客户端库的连接。初始化的 SSL 连接与标准 TCP 连接具有相同的 API,因此 RTMP 库应该能够以相同的方式处理这两种连接。
问题排查
SSL 错误
如果您尝试创建 SSL 连接,但收到无效证书,则可能是因为您连接的 YouTube 服务器需要 RTMP。确保您使用的服务器名称中包含“rtmps”(请注意“s”)。
如果网址正确,但您仍收到 SSL 错误消息,则可能是连接的端口有误。确认您正在连接到端口 443。
如果网址和端口正确无误,则可能是 SSL 库无法正确处理证书。查找有关 SSL 失败的低级别诊断消息,并仔细检查您是否在握手中使用了 SNI。
连接超时
如果您可以连接到服务器,但 RTMP 库在没有获得合理响应的情况下超时,则可能是因为您设置了与需要 RTMPS 的 YouTube 服务器的明文 RTMP 连接。确保您创建的是 SSL 连接,而不是纯 TCP 连接。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):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."]]