All Products
Search
Document Center

ApsaraVideo Live:Get started with co-streaming

Last Updated:Aug 27, 2024

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.

Note
  • 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

  1. Log on to the Alibaba Cloud official website and go to the ApsaraVideo Live product page. Click Activate Now.

  2. On the page that appears, click Activate.

  3. 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.

  1. Log on to the ApsaraVideo Live console.

  2. In the left-side navigation pane, click Domain Names. The Domain Management page appears.

  3. Click Add Domain.

  4. Configure the domain name based on your business requirements.

    Important

    When 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.

    配置域名

    Show parameters

    Parameter

    Option

    Description

    Domain Type

    • Streaming Domain

    • Ingest Domain

    The type of the domain name. You can add an ingest domain or a streaming domain. This parameter cannot be modified once set.

    Note
    • To add an ingest domain, select Ingest Domain for Domain Type. To add a streaming domain, select Streaming Domain for Domain Type.

    • You cannot add a domain name both as an ingest domain and as a streaming domain.

    Domain Name

    N/A

    Enter the domain name that you want to accelerate. Take note of the following points:

    • In most cases, use a subdomain as an accelerated domain name. Example: demo.aliyundoc.com.

    • ApsaraVideo Live does not support wildcard domain names, such as *.aliyundoc.com.

    • Duplicate accelerated domain names are not allowed. If the error message The specified domain already exists is displayed, check whether the domain name is added to other cloud services such as ApsaraVideo VOD, Dynamic Route for CDN (DCDN), Secure CDN (SCDN), or Video Surveillance System.

    • After you activate ApsaraVideo Live, you can add up to 20 domain names to ApsaraVideo Live for each Alibaba Cloud account. If the average daily peak bandwidth of your domain names exceeds 50 Mbit/s, you can submit a ticket to increase the quota of domain names. Make sure that the quota increase does not incur business risks. For more information about how to submit a ticket, see Contact us.

    • Content that is served from the domain name must comply with the limits of ApsaraVideo Live. For more information, see Verify a domain name.

    Note

    The specified subdomain must belong to the same Alibaba Cloud account. When you add a subdomain, ApsaraVideo Live verifies the ownership of the subdomain. If the subdomain belongs to a different account, an error message appears.

    Acceleration Region

    Chinese Mainland

    • For an ingest domain, if the streamers are located in the Chinese mainland, select Chinese Mainland.

    • For a streaming domain, if the viewers are located in the Chinese mainland, select Chinese Mainland.

    Apply for an ICP filing from the Ministry of Industry and Information Technology of China (MIIT) for the domain name. We recommend that you use the Alibaba Cloud ICP Filing system.

    Global

    • For an ingest domain, if the streamers are located in the Chinese mainland, Hong Kong (China), Macao (China), Taiwan (China), and other countries and regions, select Global.

    • For a streaming domain, if the viewers are located in the Chinese mainland, Hong Kong (China), Macao (China), Taiwan (China), and other countries and regions, select Global.

    Apply for an ICP filing from the MIIT for the domain name. We recommend that you use the Alibaba Cloud ICP Filing system.

    Outside Chinese Mainland

    • For an ingest domain, if the streamers are located in countries and regions outside the Chinese mainland, including Hong Kong (China), Macao (China), and Taiwan (China), select Outside Chinese Mainland.

    • For a streaming domain, if the viewers are located in countries and regions outside the Chinese mainland, including Hong Kong (China), Macao (China), and Taiwan (China), select Outside Chinese Mainland.

    • If you select Outside Chinese Mainland and the live center is located outside the Chinese mainland, you do not need to apply for an ICP filing for the domain name.

    • If you select Outside Chinese Mainland and the live center is located in the Chinese mainland, you must apply for an ICP filing for the domain name. We recommend that you apply for an ICP filing by using the Alibaba Cloud ICP Filing system.

    Note

    For more information about how to select the acceleration region, see How do I select the acceleration region for a domain name? .

    Live Center

    N/A

    A live center provides media processing features for live streams in the cloud, such as snapshot capture, recording, transcoding, and production studio.

    The live center of an ingest domain must be located in the same region as that of the associated streaming domain. This parameter cannot be modified once set.

    For more information about how to select a live center, see How do I select a live center? .

  5. Note down the generated CNAME for use in the next step.

    image

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.

Note
  • 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.

  1. Log on to the Alibaba Cloud DNS console.

  2. In the left-side navigation pane, click Domain Name Resolution. The Domain Name Resolution page appears.

  3. Find the domain name for which you want to add a CNAME record and click DNS Settings in the Actions column.

  4. Click Add DNS Record and configure the parameters that are described in the following table.001

    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.

  5. Click OK.

Check whether a CNAME record takes effect

  • Method 1: On the Domain Management page of the ApsaraVideo Live console, click Open Configuration Guide in the CNAME Status column of the domain name. In the CNAME Configuration Guide panel, click Verify in the Verify the CNAME record section. You can know whether the CNAME record takes effect from the verification result that is displayed.

    image

  • Method 2: Run the nslookup -type=cname yourdomain.com command. If the CNAME that is returned is the same as the CNAME that is assigned to the domain name in the ApsaraVideo Live console, the CNAME record takes effect.image

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.

  1. 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 Streaming Management > Basic Settings page appears.

  2. 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.基础信息

    Note
    • You 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.

  3. Click the Stream Ingest Information tab.

  4. 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

  1. Log on to the ApsaraVideo Live console.

  2. In the left-side navigation pane, choose Live + > ApsaraVideo Real-time Communication > Applications.

  3. On the Applications page, click Create Application.ed34559efbe60c8073c93d6038eaaeaa

  4. Enter a custom name in the Instance Name field, select Terms of Service, and then click Buy Now.

  5. After the application is created, refresh the Applications page to view the application.

    Note

    By 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

Note

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.

  1. In the left-side navigation pane, choose Live + > ApsaraVideo Real-time Communication > Applications.

  2. Find the application that you created and click Manage in the Actions column.

  3. 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.

      Important

      Do 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.

      Note

      If 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

Important
  • 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

  1. 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:

      image

    • Flutter:

      image

  2. Open the native demo. The Homepage appears. Tap Co-streaming to try the co-streaming feature, or tap Battle to try the battle feature.

    image

  3. If you install the demo for the first time, you need to enter the application information.

    1. In the left-side navigation pane of the ApsaraVideo Live console, choose Live + > ApsaraVideo Real-time Communication > Applications.

    2. Find the application that you created and click Manage in the Actions column.

    3. 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.

      image

  4. Enter the user ID and room ID to start using the co-streaming or battle feature.

    Note
    • When 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.

    imageimage

    Note

    If 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.

    imageimage

  5. 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

      image

    • During the battle

      image

Web demo

  1. Visit the web demo page or scan the following QR code to access the demo.

    image

  2. 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.

    Important

    You 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.

    image

    The following figure shows the output:

    image

Windows demo

Important

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.

  1. Click here to download the Windows demo. For more information, see SDK download.

  2. Decompress the demo package. Go to the /bin/64bit folder.

  3. Click obs64.exe to start running the program.

  4. In the lower-right corner of the homepage, click Settings.

  5. 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******&timestamp=17211***&token=b4718487960******.

    Stream Key

    Leave this parameter empty.

  6. In the Sources section, add a source.

  7. Click Start Streaming to start streaming.