การส่งเนื้อหา YouTube แบบสดผ่าน RTMPS
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เอกสารนี้อธิบายวิธีใช้ RTMPS เพื่อสตรีมข้อมูลสดบน YouTube จากโปรแกรมเปลี่ยนไฟล์
RTMPS คือสตรีมวิดีโอ RTMP (RealTime Messaging Protocol) ปกติ
ที่ส่งผ่านการเชื่อมต่อ SSL เอกสารนี้มีไว้สำหรับผู้ให้บริการโปรแกรมเปลี่ยนไฟล์ที่ต้องการเพิ่มการรองรับ RTMPS ลงในโปรแกรมเปลี่ยนไฟล์ที่รองรับ RTMP อยู่แล้ว
RTMPS เป็นตัวเลือกที่ดีสำหรับเนื้อหาของผู้ใช้ทั่วไปส่วนใหญ่ โดยเฉพาะอย่างยิ่งหากต้องมี
เวลาในการตอบสนองต่ำ ดูภาพรวมของโปรโตคอลการส่งผ่านข้อมูลต่างๆ ที่ YouTube Live Streaming
รองรับได้ใน
การเปรียบเทียบโปรโตคอลการส่งผ่านข้อมูล
ข้อกำหนด
การส่ง RTMPS ไปยัง YouTube Live มีข้อกำหนดเบื้องต้น 2-3 ข้อดังนี้
- แต่ละส่วนของ URL การเชื่อมต่อ (
<protocol>://<server>/<path>
) ต้อง
ถูกต้อง
- โปรโตคอลต้องเป็น
rtmps
- เซิร์ฟเวอร์ต้องเป็นปลายทางการส่งผ่านข้อมูล RTMPS ของ YouTube ที่ถูกต้อง
- เส้นทางต้องเป็นชื่อแอปพลิเคชัน RTMP ของ YouTube Live ที่ถูกต้อง
- การเชื่อมต่อต้องทำที่พอร์ต 443 ในเซิร์ฟเวอร์การส่งผ่านข้อมูล
- ต้องส่งสตรีมมัลติมีเดียด้วย RTMPS ซึ่งก็คือการใช้ RTMP ผ่านการเชื่อมต่อ SSL
การรับ URL การเชื่อมต่อ
หากโปรแกรมเปลี่ยนไฟล์ใช้ YouTube Live API อยู่แล้ว กระบวนการรับ URL การส่งผ่านข้อมูล RTMPS จะคล้ายกับกระบวนการรับ URL การส่งผ่านข้อมูล RTMP ส่งคำขอ LiveStreams insert (POST) เพื่อสร้างสตรีมการส่งผ่านข้อมูลใหม่ ในคำตอบ ฟิลด์
cdn.ingestionInfo.rtmpsIngestionAddress
จะระบุ URL ของ RTMPS หากคุณรองรับการส่งผ่านข้อมูลแบบคู่ ที่อยู่สำรอง
คือ cdn.ingestionInfo.rtmpsBackupIngestionAddress
สร้างการเชื่อมต่อ
ใช้ไลบรารีซ็อกเก็ตที่คุณต้องการเพื่อสร้างการเชื่อมต่อ SSL/TLS กับพอร์ต 443 ที่
เซิร์ฟเวอร์ที่ URL การส่งผ่านข้อมูลระบุ เนื่องจาก TLS ทำงานกับ
เลเยอร์การขนส่งเท่านั้น จึงไม่จำเป็นต้องใช้ชื่อโฮสต์ของเซิร์ฟเวอร์อย่างเคร่งครัดในการเริ่ม
การเชื่อมต่อ แต่จำเป็นต้องใช้สำหรับการตรวจสอบสิทธิ์กับเซิร์ฟเวอร์ของเรา ดังนั้น โปรดตรวจสอบว่าคุณได้เพิ่มส่วนขยาย SNI (การระบุชื่อเซิร์ฟเวอร์) ลงในการแฮนด์เชค SSL
และตั้งชื่อเซิร์ฟเวอร์เป็นชื่อโฮสต์ของเซิร์ฟเวอร์ที่คุณเชื่อมต่อด้วย
เมื่อสร้างการเชื่อมต่อ SSL แล้ว ให้ใช้การเชื่อมต่อดังกล่าวเป็นไลบรารีไคลเอ็นต์ RTMP
การเชื่อมต่อ SSL ที่เริ่มต้นแล้วจะมี API เดียวกันกับการเชื่อมต่อ TCP
มาตรฐาน ดังนั้นไลบรารี RTMP จึงควรทำงานกับทั้ง 2 อย่างได้
เหมือนกัน
การแก้ปัญหา
ข้อผิดพลาด SSL
หากคุณพยายามสร้างการเชื่อมต่อ SSL แต่ได้รับใบรับรองที่ไม่ถูกต้อง แสดงว่า
คุณอาจเชื่อมต่อกับเซิร์ฟเวอร์ YouTube ที่คาดหวัง RTMP ตรวจสอบว่าชื่อเซิร์ฟเวอร์ที่คุณใช้มี "rtmps" อยู่ด้วย
หาก URL ดูคล้ายจะถูกต้องแต่คุณยังเห็นข้อผิดพลาด SSL แสดงว่าคุณอาจเชื่อมต่อกับพอร์ตที่ไม่ถูกต้อง ตรวจสอบว่าคุณเชื่อมต่อกับพอร์ต 443
หาก URL และพอร์ตถูกต้อง แสดงว่าไลบรารี SSL อาจจัดการใบรับรองไม่ถูกต้อง
มองหาข้อความการวินิจฉัยระดับต่ำเกี่ยวกับความล้มเหลวของ SSL
และตรวจสอบอีกครั้งว่าคุณใช้ SNI ในการแฮนด์เชค
การเชื่อมต่อหมดเวลา
หากคุณเชื่อมต่อกับเซิร์ฟเวอร์ได้ แต่ไลบรารี RTMP หมดเวลาโดยไม่ได้รับ
การตอบกลับที่เหมาะสม คุณอาจตั้งค่าการเชื่อมต่อ RTMP แบบข้อความธรรมดา
กับเซิร์ฟเวอร์ YouTube ที่คาดหวัง RTMPS ตรวจสอบว่าคุณกำลังสร้างการเชื่อมต่อ SSL
ไม่ใช่การเชื่อมต่อ TCP แบบธรรมดา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[[["\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."]]