Co-streaming is a typical scenario of ApsaraVideo Real-time Communication (ARTC). This topic describes how to get started with co-streaming.
Prerequisites
An ingest domain and a streaming domain are available.
If you want to quickly try the basic features of ApsaraVideo Live, we recommend that you use domain names that are located outside the Chinese mainland and set Acceleration Region to Outside Chinese Mainland for the domain names. This frees you from the need to apply for ICP filings for the domain names.
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.
Activate ApsaraVideo Live
Log on to the Alibaba Cloud official website and go to the ApsaraVideo Live product page. Click Activate Now.
On the page that appears, click Activate.
On the ApsaraVideo Live buy page, select Pay-By-Traffic or Pay-By-Peak-Bandwidth as the metering method, tick I have read and agree to ApsaraVideo Live Terms of Service, and click Activate Now. Then, you can use the ApsaraVideo Live console.
Step 1: Add an ingest domain and a streaming domain
To use ApsaraVideo Live, you must add an ingest domain and a streaming domain.
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.
Step 2: Add CNAME records to enable acceleration
To enable acceleration for ApsaraVideo Live, 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.
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
Step 3: Associate the streaming domain with the ingest domain
ApsaraVideo Live uses the edge ingest method. To ingest and play streams, you must associate the streaming domain with the ingest domain.
In the left-side navigation pane, click Domain Names. On the page that appears, 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.
Create an ARTC application
Log on to the ApsaraVideo Live console.
In the left-side navigation pane, choose
.On the Applications page, click Create Application.
Enter a custom name in the Instance Name field, select Terms of Service, and then click Buy Now.
After the application is created, refresh the Applications page to view the application.
NoteBy default, no fees are incurred when you create an application. You are charged based on your actual usage in the cloud. For more information, see Billing of ARTC.
Configure stream relay
In co-streaming scenarios, you need to configure global single-stream relay to ApsaraVideo Live and specify a streaming domain for viewers in the live room. This way, the stream of the streamer is relayed to ApsaraVideo Live by default and played in the live room for viewers to watch. After co-streaming is started, the stream of the streamer and the stream of the co-streamer are mixed by calling the stream mixing method provided by the SDK. Then, the mixed stream is ingested to viewers.
In the left-side navigation pane, choose
.Find the application that you created and click Manage in the Actions column.
Click the Stream Relay tab. In the Global Stream Relay to ApsaraVideo Live section, turn on Stream Relay. In the dialog box that appears, configure the stream relay parameters.
Streaming Domain: Select a streaming domain that is relayed for standard streaming. You can play live streams, configure transcoding and recording settings, and perform other operations based on the streaming domain.
ImportantDo not enable RTS 2.0 for the streaming domain. Otherwise, relayed stream pulling fails.
AppName: the application name in the streaming URL after stream relay. Default value: live. You can specify a custom application name.
NoteIf you need to configure templates such as transcoding, recording, and snapshot templates for the relayed stream, you must specify an application name that is the same as the application name specified in the templates. Otherwise, the templates do not take effect.
SEI Insertion: uses supplemental enhancement information (SEI) to insert basic user information such as the UID and mixed-stream layout parameters into streams. This way, in co-streaming scenarios, when the layout for stream mixing and relay changes, the app that viewers use to watch streams can parse the layout information from SEI in real time. This helps facilitate the adjustment of interaction styles. For more information, see SEI format.
Insert SEI at Regular Intervals: This option lets you insert SEI at a specified interval from 1,000 to 5,000 ms.
Insert SEI in I-frames: This option lets you insert SEI in I-frames of a video stream.
(Optional) Configure HTTPS settings and HTTP header settings
If some of the viewers require playback on the web, you need to configure HTTPS secure acceleration and allow cross-origin requests for the streaming domain. For more information about how to configure HTTPS secure acceleration, see Configure HTTPS secure acceleration.
For more information about how to configure the Access-Control-Allow-Origin header to allow cross-origin requests, see Configure HTTP headers.
Generate ingest and streaming URLs for co-streaming
You can use the native demo or Web demo to try co-streaming.
Co-streaming does not support the use of OBS (Open Broadcaster Software). You can use a generated ingest URL for co-streaming in the Windows demo to ingest a stream.
You can generate the ingest and streaming URLs of the streamer and co-streamer and the CDN streaming URL of viewers by using the ApsaraVideo Live console, or construct these URLs by using the concatenation rules.
Method 1: Generate the URLs by using the console
You can use the URL generator in the ApsaraVideo Live console to generate the ingest and streaming URLs of the streamer and co-streamer and the CDN streaming URL of viewers. For more information, see Co-streaming URL generator.
Method 2: Construct the URLs
Tokens in ingest and streaming URLs of the streamer and co-streamer that are generated by using the console are temporary, and are usually used for testing.
If you need ingest and streaming URLs that are used for business purposes, construct the URLs by using the concatenation rules for security reasons. Tokens in URLs that you construct by using the concatenation rules are calculated based on the SdkAppID, AppKey, room ID, UserID, and timestamp by using the SHA-256 encryption algorithm. This prevents malicious parties from forging a token to gain access to your cloud services. For more information about the concatenation rules, see Ingest and streaming URLs of streamers and co-streamers in co-streaming scenarios and CDN streaming URLs of viewers.
Run the demo
Native demo
Use the links provided in SDK download or scan the following QR codes to download the demo of the interactive edition of Push SDK.
Android/iOS:
Flutter:
Open the native demo. The Homepage appears. Tap Co-streaming to try the co-streaming feature, or tap Battle to try the battle feature.
If you install the demo for the first time, you need to enter the application information.
In the left-side navigation pane of the ApsaraVideo Live console, choose
.Find the application that you created and click Manage in the Actions column.
On the page that appears, obtain the application ID and AppKey and the streaming domain configured for stream relay. Fill the obtained information in the demo.
Enter the user ID and room ID to start using the co-streaming or battle feature.
NoteWhen you use the co-streaming feature, make sure that the room ID of the viewer is the same as that of the streamer while the user IDs of the streamer and viewer are different.
During co-streaming, a viewer needs to enter the ID of the streamer after entering the room. This way, the viewer can pull the stream of the streamer from CDN.
Make sure that the devices are connected to the network.
NoteIf you require co-streaming between the native side and a web client, tap Parameter Settings in the upper-right corner of the page for entering the co-streaming information or battle information. On the page that appears, turn on HTML5 Compatible Mode or HTML5 Compatibility.
Start the live room and initiate co-streaming.
By default, co-streaming does not automatically start when the streamer and viewer enter the live room. The streamer and viewer need to tap the Start Co-streaming button, respectively, and enter the user ID of each other to start co-streaming. The following figures show the output:
During co-streaming
During the battle
Web demo
Visit the web demo page or scan the following QR code to access the demo.
On the web demo page, enter the application ID and AppKey and the streaming domain configured for stream relay that are obtained from the ApsaraVideo Live console. Then, enter the room ID and user ID and specify the user role. Click OK to start the live room and initiate co-streaming.
By default, co-streaming does not automatically start when the streamer and viewer enter the live room. The streamer and viewer need to click the Start Co-streaming button, respectively, and enter the user ID of each other to start co-streaming.
ImportantYou must disable URL signing for the streaming domain so that it can work properly in the demo. For more information, see Configure URL signing. However, we strongly recommend that you enable URL signing for official uses.
The following figure shows the output:
Windows demo
You need to prepare an ingest URL for co-streaming, which is different from a regular ingest URL. For more information, see Co-streaming URL generator.
Click here to download the Windows demo. For more information, see SDK download.
Decompress the demo package. Go to the /bin/64bit folder.
Click obs64.exe to start running the program.
In the lower-right corner of the homepage, click Settings.
In the Settings window, click Stream. The following table describes the parameters:
Parameter
Description
Service
Select ALIRTC.
Server
Enter the ingest URL for co-streaming that is generated. Example: artc://live.aliyun.com/push/100******?sdkAppId=580c9e85-176f-4a******&userId=10******×tamp=17211***&token=b4718487960******.
Stream Key
Leave this parameter empty.
In the Sources section, add a source.
Click Start Streaming to start streaming.