This topic describes how to reduce the live streaming latency to less than 400 ms based on Real-Time Streaming (RTS), providing a smooth and instant viewing experience.
Solution overview
RTS relies on Alibaba Cloud Global Realtime Transport Network (GRTN) to implement an end-to-end latency of 200 to 400 ms based on full-link Web Real-Time Communication (WebRTC). You can seamlessly upgrade from standard streaming to RTS. This way, forward compatibility is achieved.
Use RTS 2.0 to implement an end-to-end latency of 200 to 400 ms
After collecting a live stream from a device, a streamer can use Push SDK to ingest the live stream to Alibaba Cloud points of presence (POPs) over the RTS protocol that is based on WebRTC.
The live stream is transmitted among over 3,200 POPs of GRTN in real time based on the intelligent routing and quality of service (QoS) technologies.
Viewers pull the live stream from the nearest POPs over the RTS protocol that is based on WebRTC and play the live stream. The end-to-end latency is 200 to 400 ms.
(Optional) Enable stream relay to implement media processing of streams that are based on RTS 1.0 and standard streaming
After you enable stream relay, ApsaraVideo Live can automatically encapsulate the live stream that is ingested by the streamer and generate a Real-Time Messaging Protocol (RTMP) stream.
You can configure media processing settings, such as transcoding, recording, and snapshot capture, for the live stream.
If you want to have a low latency for stream pulling, use RTS 1.0. This way, viewers can pull the live stream over the RTS protocol that is based on WebRTC. The end-to-end latency is 500 to 1,000 ms.
If you use standard streaming, viewers can pull the live stream over protocols such as RTMP, Flash Video (FLV), and HTTP Live Streaming (HLS).
Solution implementation
Prerequisites
ApsaraVideo Live is activated. For more information, see Activate ApsaraVideo Live.
An ingest domain and a streaming domain for ApsaraVideo Live are configured. For more information, see the Add an ingest domain and a streaming domain, Add CNAME records, and Associate the streaming domain with the ingest domain steps in Get started with ApsaraVideo Live.
Configure HTTPS certificates for the ingest domain and streaming domain
In this topic, a demo for web browsers is used as an example to show you how to pull and ingest streams. In this case, you must configure HTTPS certificates for the ingest domain and streaming domain due to security concerns for WebRTC. For more information, see Configure HTTPS secure acceleration.
If you use Native RTS SDK for stream ingest and playback, you do not need to configure HTTPS certificates.
Configure RTS 2.0 for the streaming domain
Log on to the ApsaraVideo Live console.
In the left-side navigation pane, click Domain Names. The Domain Management page appears.
Find the streaming domain that you want to configure and click Domain Settings in the Actions column.
On the page that appears, choose
.Click Modify. In the dialog box that appears, set Version to RTS 2.0 and Scenario to Live Stream Viewing.
Click OK.
Configure RTS 2.0 for the ingest domain
Log on to the ApsaraVideo Live console.
In the left-side navigation pane, click Domain Names. The Domain Management page appears.
Find the ingest domain that you want to configure and click Domain Settings in the Actions column.
On the page that appears, choose
.Click Modify. In the dialog box that appears, set Version to RTS 2.0 for Stream Ingest.
Click OK.
Generate ingest and streaming URLs
In the feature verification phase, you can use the URL generator to generate ingest and streaming URLs. For more information, see Live URL generator.
You can also construct ingest and streaming URLs by using the concatenation rules. For more information, see Generate ingest and streaming URLs.
Implement RTS-based stream ingest on the streamer side
You can use one of the following SDKs to ingest streams over RTS.
SDK | References |
Push SDK for iOS | Note By default, Push SDK for iOS supports stream ingest that is based on WebRTC. |
Push SDK for Android | Note By default, Push SDK for Android supports stream ingest that is based on WebRTC. |
Third-party SDKs based on standard WebRTC |
In the following example, the RTS demo for web is used to ingest a stream over RTS.
Open the RTS demo for web page.
In the demo, select the Stream Ingest mode.
Expand the none drop-down box and select camera or screen based on your business requirements.
If you select camera, click Mic and Camera at the bottom of the page to authorize the player to access your devices. After the authorization is successful, expand the Select Microphone and Select Camera drop-down boxes to select corresponding devices.
Enter the ingest URL in the RTS format that is generated in Generate ingest and streaming URLs and click Create Local Stream.
Click Start to start stream ingest.
Implement RTS playback on the viewer side
You can use one of the following SDKs to play streams over RTS.
SDK | References |
Web RTS SDK | |
Native RTS SDK for iOS | |
Native RTS SDK for Android | |
Native RTS SDK for macOS | |
Native RTS SDK for Windows | |
Third-party SDKs based on standard WebRTC |
In the following example, the RTS demo for web is used to play a stream over RTS.
Open the RTS demo for web page.
In the demo, select the Stream Pulling mode.
Enter the streaming URL in the RTS format that is generated in Generate ingest and streaming URLs.
Click Start to start stream pulling.
(Optional) Configure stream relay
Log on to the ApsaraVideo Live console.
In the left-side navigation pane, click Domain Names. The Domain Management page appears.
Find the ingest domain that you want to configure and click Domain Settings in the Actions column.
On the page that appears, choose
.Click Modify. In the dialog box that appears, set Version to RTS 2.0 for Stream Ingest, turn on Stream Relay, and select another domain name to which RTMP streams are relayed.
For example, if you set the Relayed To parameter to
push.example.com
, whose associated streaming domain ispull.example.com
, take note of the following points:You cannot enable RTS 2.0 for push.example.com and pull.example.com.
You are not charged additional fees for this feature.
(Optional) Configure media processing templates for relayed streams
After you configure stream relay, you can configure media processing templates for the streaming domain that is associated with the ingest domain to which streams are relayed. In this example, the streaming domain is pull.example.com
.
On the domain name management page, click Templates and configure templates based on your business requirements.
(Optional) Use RTS 1.0 and standard streaming for relayed streams
After you configure stream relay, you can use RTS 1.0 and standard streaming for the streaming domain that is associated with the ingest domain to which streams are relayed. This way, you can play the source streams or transcoded streams over RTS and RTMP, FLV, and HLS at the same time. In this example, the streaming domain is pull.example.com
.
For more information about standard streaming, see Get started with ApsaraVideo Live.
From September 1, 2022, all streaming domains support playback based on RTS 1.0 by default. You need only to integrate RTS SDK on the playback side. For more information, see Get started with RTS.