With the rapid development of the live streaming industry, the requirements on latency are becoming increasingly stringent. ApsaraVideo Live provides the Real-Time Streaming (RTS) feature to reduce the live streaming latency, which improves user experience. RTS reduces the latency to milliseconds, compared with 3 to 6 seconds of standard streaming. RTS also provides stronger resistance to packet loss. It is suitable for scenarios that require ultra-low latency and high interactivity, such as e-commerce live streaming, online education, live events, and live shows. This topic describes how to implement RTS.
Prerequisites
An ingest domain and a streaming domain are available. Internet content provider (ICP) filing for the domain names is complete.
NoteIf you are in a live center outside the Chinese mainland and set Acceleration Region to Outside Chinese Mainland for the domain names, ICP filing is not required.
If the ingest domain and streaming domain are second-level domain names under the same top-level domain name, you need to apply for an ICP filing only for the top-level domain name.
Basic procedure
Activate ApsaraVideo Live
You can view the tutorial video to learn how to activate ApsaraVideo Live. For more information, see Activate ApsaraVideo Live.
Log on to the Alibaba Cloud official website. In the top navigation bar, choose . The ApsaraVideo Live homepage appears.
Click Activate Now.
On the ApsaraVideo Live activation page, select Pay-By-Traffic as the metering method. Read and agree to the ApsaraVideo Live Terms of Service.
Click Activate Now.
Add an ingest domain and a streaming domain
To use RTS, you must add an ingest domain and a streaming domain.
You can view the tutorial video to learn how to add a domain name. For more information, see Add a domain name.
Log on to the ApsaraVideo Live console.
In the left-side navigation pane, click Domain Names. The Domain Management page appears.
Click Add Domain.
Configure the domain name based on your business requirements.
ImportantWhen you add a domain name to ApsaraVideo Live for the first time, ApsaraVideo Live verifies the ownership of the domain name. For more information, see Verify the ownership of a domain name.
Note down the generated CNAME for use in the next step.
Add CNAME records
Before you use RTS, you must add CNAME records at your DNS provider to map your ingest domain and streaming domain to the CNAME that is assigned by ApsaraVideo Live. The following example shows how to add a CNAME record when your DNS provider is Alibaba Cloud. For information about how to add a CNAME record at other DNS providers, see Add a CNAME record.
The server that Alibaba Cloud CDN uses to resolve the CNAME of a domain name is deployed in the Chinese mainland. If you configure region-specific DNS settings for your domain name, for example, you add a CNAME record for your domain name in regions outside the Chinese mainland, including Hong Kong (China), Macao (China), and Taiwan (China), the domain name cannot be mapped to the CNAME. The status of the CNAME is Pending Configuration in the Alibaba Cloud CDN console. However, CDN acceleration for the domain name is not affected.
CNAMEs that are assigned by Alibaba Cloud CDN, Dynamic Content Delivery Network (DCDN), ApsaraVideo Live, and ApsaraVideo VOD can be used only for domain name resolution. If Alibaba Cloud discovers that your CNAME is used for unauthorized or malicious activities, Alibaba Cloud reserves the right to close your Alibaba Cloud account and remove the domain names.
Log on to the Alibaba Cloud DNS console.
In the left-side navigation pane, click Domain Name Resolution. The Domain Name Resolution page appears.
Find the domain name for which you want to add a CNAME record and click DNS Settings in the Actions column.
Click Add DNS Record and configure the parameters that are described in the following table.
Parameter
Description
Record Type
Select CNAME from the drop-down list.
Hostname
Specify a prefix for the domain name. For more information about regular prefixes of domain names and sample domain names, see the following table.
DNS Request Source
Use the default value.
Record Value
Enter the CNAME that you obtained.
TTL Period
Use the default value.
Prefix
Sample domain name
Description
demo
demo.aliyundoc.com
The subdomain name.
@
aliyundoc.com
The root domain name.
*
*.aliyundoc.com
The wildcard domain name.
Click OK.
Check whether a CNAME record takes effect
Associate the streaming domain with the ingest domain
RTS uses the edge ingest method. To ingest and play streams, you must associate the streaming domain with the ingest domain.
You can view the tutorial video to learn how to associate a streaming domain with an ingest domain. For more information, see Associate a streaming domain with an ingest domain.
On the Domain Management page, find the streaming domain that you added and click Domain Settings in the Actions column. The page appears.
On the Basic Settings page, click the Basic Information tab.
On the Basic Information tab, you can view the CNAME record, the time when the domain name was created, the type of the domain name, the live center, the acceleration region, and the quota limits.
NoteYou can manage quotas of ApsaraVideo Live only in the China (Beijing), China (Shanghai), China (Shenzhen), and Singapore regions. To increase quotas for other live centers, submit a ticket. For more information, see Contact us.
For more information about how to manage quotas of ApsaraVideo Live, see Quota management.
For more information about how to modify the acceleration region, see the Modify the acceleration region section of this topic.
Click the Stream Ingest Information tab.
Click Add Stream Ingest Information or the Edit icon next to Ingest Domain and select the ingest domain that you want to associate.
(Optional) Configure SSL certificates
For security reasons, if you want to implement RTS in a native browser, you must configure Secure Sockets Layer (SSL) certificates for the ingest domain and the streaming domain. For more information, see Configure HTTPS secure acceleration.
If you use RTS SDK or the RTS demo, SSL certificates are not required.
Enable RTS
From September 1, 2022, RTS and auto transcoding for HTML5 playback are automatically enabled for streaming domains that you add. No additional configurations are required. For streaming domains that were added before September 1, 2022, you must manually configure the settings.
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 for which you want to enable RTS and click Domain Settings in the Actions column.
On the page that appears, choose .
Turn on RTS.
In the dialog box that appears, choose RTS 1.0 and turn on HTML5 Auto Transcoding.
The WebRTC of native browsers does not support B-frames and the AAC audio format. To ensure smooth playback, the feature of auto transcoding for HTML5 playback performs adaptive transcoding.
If you use a browser to play a stream that contains B-frames and AAC audio, the B-frames are removed and the audio format is converted. You are charged for standard transcoding fees.
If you use a browser to play a stream that contains AAC audio but does not contain B-frames, the audio format is converted. You are charged for audio-only transcoding fees.
If you use a browser to play a stream and have configured a transcoding template, both the feature of auto transcoding for HTML5 playback and the transcoding template take effect. The transcoding is billed only once.
If you use Native RTS SDK to play a stream, transcoding is not required because the SDK supports B-frames and the AAC audio format.
NoteWait a few minutes and then check whether the configurations for RTS take effect.
To map an ingest domain to multiple streaming domains, you must bind one or more sub-streaming domains to a main streaming domain. For more information, see Bind a sub-streaming domain to a main streaming domain.
RTS and standard streaming can share the same streaming domain. However, we recommend that you configure a separate streaming domain for RTS because RTS uses User Datagram Protocol (UDP) while standard streaming uses Transmission Control Protocol (TCP).
(Optional) Configure custom URL signing
The URL signing feature can be used to protect resources on origin servers from unauthorized access and downloads. By default, URL signing is enabled for a domain name that you add.
You can use the default URL signing settings or custom URL signing settings based on your business requirements. If you use the default URL signing settings, no additional configuration is required. If you do not want to use the default settings, you can specify the Primary Key, Secondary Key, and Validity Period parameters.
You can view the tutorial video to learn how to configure URL signing. For more information, see Configure URL signing.
In the left-side navigation pane of the ApsaraVideo Live console, choose Domain Names. On the Domain Name Management page, find the streaming domain for which RTS is enabled and click Domain Settings in the Actions column.
Choose . The Access Control page appears.
Click the URL Signing tab. Then, click Change Settings.
NoteWhen URL signing is enabled, you can click Change Settings to modify the URL signing settings. When URL signing is disabled, you can turn on URL Signing and then configure the URL signing settings.
Configure the URL signing settings. The following table describes the parameters.
Parameter
Description
Authentication Type
ApsaraVideo Live streaming domains support only the authentication type of Type A to protect resources on the origin server.
Note
If URL signing fails, HTTP status code 403 is returned. In this case, you must recalculate the signature.
Invalid MD5 value
Example:
X-Tengine-Error:denied by req auth: invalid md5hash=de7bfdc915ced05e17380a149bd760be
Invalid timestamp
Example:
X-Tengine-Error:denied by req auth: expired timestamp=1439469547
Primary Key
After you add a domain name, ApsaraVideo Live generates a random primary key for the domain name. In the left-side navigation pane of the ApsaraVideo Live console, click Domain Names. Find the domain name that you want to configure and click Domain Settings in the Actions column. On the page that appears, choose
. On the URL Signing tab, you can view the primary key and can also change the primary key.Secondary Key
Specify a custom secondary key.
Validity Period
The signed URL can be used to initiate stream ingest or streaming requests only within the validity period. Persistent connections are established for stream ingest and streaming. Stream ingest and streaming requests that are initiated within the validity period are not dropped after the validity period expires. New stream ingest and streaming requests fail to be initiated after the validity period expires.
The default validity period for a signed URL under a domain name that you add is 1 day or 1,440 minutes. You can specify a custom validity period for the signed URL. The minimum value is 1 minute. There is no upper limit.
Generate ingest and streaming URLs
You can generate an ingest URL and a streaming URL by using the ApsaraVideo Live console or construct the URLs by using the concatenation rules.
Method 1: Generate the URLs by using the console
If you want to quickly generate ingest and streaming URLs, use the URL generator in the console. For more information, see Live URL generator.
Method 2: Construct the URLs
Before you construct an ingest URL or a streaming URL for a live stream by using the concatenation rules, check whether the stream is transcoded and authenticated. Then, obtain an ingest domain, a streaming domain, an application name, a stream name, a transcoding template ID, and an access token. The transcoding template ID and access token are optional. The following table describes the concatenation rules.
URL type | URL format | Concatenation rule |
Ingest URL | The Real-Time Messaging Protocol (RTMP), RTS, and Secure Reliable Transport (SRT) formats are supported. We recommend that you use the RTMP format. Example: Ingest URL in the RTMP format: Note RTS allows you to pull streams over RTS. | Ingest domain + Application name + Stream name + Access token |
Streaming URL | The RTMP, Flash Video (FLV), M3U8, and RTS formats are supported. We recommend that you use the RTS format. Example: Streaming URL in the RTS format: | Streaming domain + Application name + Stream name + Access token |
Transcoded stream URL Note You must provide a transcoding template ID to construct a transcoded stream URL. The transcoded stream URL is required only if a transcoding template is used. | The RTMP, FLV, M3U8, and RTS formats are supported. We recommend that you use the RTS format. Example: Transcoded stream URL in the RTS format: artc://example.aliyundoc.com/app/stream_{Transcoding template ID}?auth_key={Access token} | Streaming domain + Application name + Stream name_Transcoding template ID + Access token |
Associated streaming domain and ingest domain can be properly used only if the application name and stream name of the streaming domain match those of the ingest domain.
You must provide a transcoding template ID to generate a transcoded stream URL. You can view the transcoding template ID in the console. For more information, see Transcoding management.
An access token (auth_key) is an encrypted string that is generated based on the URL authentication algorithm. Access tokens are required if you enable URL signing. You can use the MD5 algorithm to obtain access tokens. For more information, see Construct a signed URL.
When you construct a URL by using the concatenation rules, replace {Transcoding template ID} or {Access token} with the actual value without {}.
Start RTS-based stream ingest
We recommend that you use the RTMP format for RTS-based stream ingest. In the following example, OBS Studio is used to ingest streams over RTMP. For more information about how to ingest streams over RTS, see Stream ingest for RTS.
Download and install OBS Studio. Download link: OBS Studio.
Run OBS Studio.
In the menu bar, choose .
On the Settings page, click Stream and configure the following parameters.
Parameter
Description
Service
Select Custom....
Server
Enter the signed ingest URL that is generated. Example:
rtmp://demo.aliyundoc.com/app/stream?auth_key=1543302081-0-0-9c6e7c8190c10bdfb3c0************
.Stream Key
Leave this parameter empty.
Optional: On the Settings page, click Output and configure the following parameters to remove B-frames.
Output Mode: Advanced
Keyframe Interval (seconds, 0=auto): 1
CPU Usage Preset (higher = less CPU): veryfast
Profile: baseline
Tune: zerolatency
Go to the homepage of OBS Studio. Find the Sources section, add a source, and click Start Streaming.
If you encounter issues such as stream ingest exceptions during stream ingest, you can use the troubleshooting tool to troubleshoot the issues. The tool allows you to diagnose common stream ingest issues and provides suggestions for you to resolve specific exceptions. For more information, see Troubleshooting.
Start RTS playback
The following table lists the players integrated with RTS SDK for RTS playback. Alibaba Cloud RTS provides demos for both mobile and web clients.
Players:
Player
References
ApsaraVideo Player for mobile clients
Third-party players that are based on FFmpeg
Integrate Native RTS SDK with a third-party player that is based on FFmpeg
ApsaraVideo Player for Web
For information about the RTS demo, see Play an RTS stream.
If you encounter issues such as playback exceptions during streaming, you can use the troubleshooting tool to troubleshoot the issues. The tool allows you to diagnose common stream playback issues and provides suggestions for you to resolve specific exceptions. For more information, see Troubleshooting.
Other operations: verify the latency of RTS
You can add a time calibrator URL during stream ingest to verify the latency of RTS by comparing the streaming time with UTC. OBS Studio is used in this example.
Go to the homepage of OBS Studio. Add a time calibrator URL in the Sources section, and click Start Streaming.