All Products
Search
Document Center

ApsaraVideo Live:Live stream transcoding

Last Updated:Oct 31, 2025

Live stream transcoding resolves playback issues caused by high or low ingest bitrates. This topic describes the scenarios, limits, features, template parameters, transcoding rules, and adaptive resolution of live stream transcoding.

Scenarios

  • If the ingest bitrate is high and the client has limited bandwidth, video playback may stutter. If the ingest bitrate is low, the playback quality is poor. The live stream transcoding service helps you resolve these issues.

  • Player plug-ins need to support multi-bitrate switching. To enable this on a frontend player plug-in, you must provide multiple streaming URLs with different bitrates for the same ingest stream. The real-time transcoding feature of ApsaraVideo Live provides these URLs.

    • Ingest a stream encoded in H.264 and transcode it into an H.265 stream in real time for playback to reduce bandwidth usage.

    • Ingest a stream encoded in H.265 and transcode it into a low-bitrate H.265 stream in real time for playback.

    • To resolve the incompatibility of H.265 in some browsers, you can transcode the stream into an H.264 stream in real time for playback.

Important

If you use the live stream transcoding feature, you are charged based on the transcoding standard, resolution, and total length of transcoded streams. For more information, see Live stream transcoding fees.

Limits

  • When you configure a transcoding template based on a domain name and an AppName, you cannot set the Template Type to both Standard Template and Narrowband HDTM template in the same template.

  • If you configure a transcoding template for a specific AppName, the template is applied only when the AppName in the ingest URL matches the one in the template. Subdomains for streaming reuse the transcoding templates of the primary streaming domain, and any configurations specific to the subdomains are ignored.

  • If the live center is in Beijing, Shanghai, or Shenzhen, a maximum of 300 concurrent transcoded streams are supported for each domain name. For other live centers, a maximum of 50 concurrent transcoded streams are supported for each domain name. For example, if you ingest a high-definition (HD) stream and transcode it into standard-definition (SD) and low-definition (LD) streams for playback, this counts as two transcoded streams. If the limit is reached, subsequent playback connections that exceed the limit play the original stream. You can go to Basic Information on the Basic Settings page of your streaming domain to view the current usage and increase the quota.

  • If the live streaming service does not meet your current business needs, you can contact your Alibaba Cloud account manager or Alibaba Cloud through other channels.

Features

The transcoding feature includes Default Transcoding, Custom Transcoding, Multi-bitrate Transcoding, and H5 Automatic Transcoding.

Default Transcoding: You can use system preset templates, which include template IDs and output resolutions. The output bitrates are preset by the system and cannot be modified.

Custom Transcoding: You can customize settings such as encoding format, resolution, bitrate, frame rate, video GOP, transcoding trigger, and template ID.

Multi-bitrate Transcoding: A transcoding template can contain multiple transcoding configurations. After you configure multi-bitrate transcoding, the player can automatically play the live stream with the appropriate bitrate based on the network bandwidth of the client. This improves the playback experience.

H5 Automatic Transcoding: This feature resolves issues such as the lack of support for B-frames and AAC encoding in Native Browsers for Real-Time Streaming (RTS) (artc://).

System preset templates

Template details>>

  • Standard templates

Transcoding template

Quality-first template ID - H.264

Quality-first template ID - H.265

Latency-first template ID - H.264

Latency-first template ID - H.265

Resolution

Bitrate

Low definition (landscape)

lld

lld265

lld-ll

lld265-ll

Adaptive width, height: 360

≤ 470

Standard definition (landscape)

lsd

lsd265

lsd-ll

lsd265-ll

Adaptive width, height: 432

≤ 680

High definition (landscape)

lhd

lhd265

lhd-ll

lhd265-ll

Adaptive width, height: 648

≤ 1500

Ultra-high definition (landscape)

lud

lud265

lud-ll

lud265-ll

Adaptive width, height: 1080

≤ 2500

Standard definition (landscape)

lsd540

lsd265-540

lsd540-ll

lsd265-540-ll

Adaptive width, height: 540

≤ 680

Low definition (portrait)

lld-v

lld265-v

lld-v-ll

lld265-v-ll

Width: 360, adaptive height

≤ 470

Standard definition (portrait)

lsd-v

lsd265-v

lsd-v-ll

lsd265-v-ll

Width: 432, adaptive height

≤ 680

High definition (portrait)

lhd-v

lhd265-v

lhd-v-ll

lhd265-v-ll

Width: 648, adaptive height

≤ 1500

Ultra-high definition (portrait)

lud-v

lud265-v

lud-v-ll

lud265-v-ll

Width: 1080, adaptive height

≤ 2500

Standard definition (portrait)

lsd540-v

lsd265-540-v

lsd540-v-ll

lsd265-540-v-ll

Width: 540, adaptive height

≤ 680

Original quality - Audio-only transcoding

oriopus

Original quality - Audio-only transcoding

oriaac

  • Narrowband HD templates

Transcoding template

Quality-first template ID - H.264

Quality-first template ID - H.265

Latency-first template ID - H.264

Latency-first template ID - H.265

Resolution

Bitrate

Low definition (landscape)

ld

ld265

ld-ll

ld265-ll

Adaptive width, height: 360

≤ 450

Standard definition (landscape)

sd

sd265

sd-ll

sd265-ll

Adaptive width, height: 432

≤ 480

High definition (landscape)

hd

hd265

hd-ll

hd265-ll

Adaptive width, height: 648

≤ 1200

Ultra-high definition (landscape)

ud

ud265

ud-ll

ud265-ll

Adaptive width, height: 1080

≤ 1300

Standard definition (landscape)

sd540

sd265-540

sd540-ll

sd265-540-ll

Adaptive width, height: 540

≤ 480

Low definition (portrait)

ld-v

ld265-v

ld-v-ll

ld265-v-ll

Width: 360, adaptive height

≤ 450

Standard definition (portrait)

sd-v

sd265-v

sd-v-ll

sd265-v-ll

Width: 432, adaptive height

≤ 480

High definition (portrait)

hd-v

hd265-v

hd-v-ll

hd265-v-ll

Width: 648, adaptive height

≤ 1200

Ultra-high definition (portrait)

ud-v

ud265-v

ud-v-ll

ud265-v-ll

Width: 1080, adaptive height

≤ 1300

Standard definition (portrait)

sd540-v

sd265-540-v

sd540-v-ll

sd265-540-v-ll

Width: 540, adaptive height

≤ 480

Important
  • The Template ID does not necessarily correspond to the transcoding billing specification. The actual billing specification depends on the Resolution of the transcoded video. For example, if you configure Low Definition (ld) transcoding and the Short Edge Of The Transcoded Video Is ≤ 480 Pixels And The Long Edge Is ≤ 640 Pixels, the transcoding bill is generated based on the LD specification. If you configure Low Definition (ld) transcoding but the resolution of the transcoded video is 700×360, the bill is generated based on the SD specification. For more information, see Live stream transcoding fees.

  • Transcoding uses a resolution automatic rotation algorithm that automatically adjusts the output resolution based on the landscape or portrait orientation of the video. For more information, see Resolution automatic rotation.

Transcoding rules

  • ApsaraVideo Live supports delayed transcoding by default. The system does not perform transcoding if it detects that no viewers are watching a transcoded live stream. Transcoding starts when the first viewer begins playback. If no viewers are detected within 5 minutes during the transcoding process, transcoding stops.

  • Each transcoded stream is transcoded only once.

  • Transcoding is an optional service. You can configure it as needed.

  • The transcoding feature supports the FLV, RTMP, HLS, and RTS protocols.

Adaptive resolution

Transcoding uses an adaptive resolution algorithm for landscape or portrait mode.

  • For Adaptive Landscape transcoding, the width of the transcoded video is adapted based on the template height.

  • For Adaptive Portrait transcoding, the height of the transcoded video is adapted based on the template width.

The adaptive width is calculated as follows:

高度自适应

For example, if you transcode a 1920 × 1080 video using the Low Definition Landscape template (template ID: ld) with Adaptive Width and a height of 360, the transcoded resolution is 640 × 360.

For example, if you transcode a 1920 × 1080 video using the Low Definition Portrait template (template ID: ld-v) with a width of 360 and Adaptive Height, the transcoded resolution is 360 × 203.

Important

Currently, only Default Transcoding and Custom Transcoding support adaptive resolution.

Configuration

Default transcoding

You can configure default transcoding for ApsaraVideo Live in two ways:

Configure default transcoding in the console

  1. Log on to the ApsaraVideo Live console.
  2. Click Feature Management > Live Stream Transcoding to go to the Live Stream Transcoding page.

  3. Select the domain name that you want to configure, click the Default Transcoding tab, and then click Add to configure a transcoding template.

    image

    The following table describes the parameters for the transcoding template.

    Parameter

    Description

    AppName

    AppName matching has a priority. The system first tries to match a transcoding template with the same AppName as the ingest URL. If no such template exists, the system matches a template configured with a single asterisk (*) for the AppName within the domain name.

    Trigger Transcoding

    • Enabled: Transcoding starts only when the transcoded stream is pulled for the first time.

    • Disabled: Transcoding starts as long as there is an ingest stream, regardless of whether the stream is being pulled.

    Template Type

    • Provides Standard Template and Narrowband HD™ Template. The quality, performance, and price of these templates are different. The Standard Template provides an Original Quality - Audio-only Transcoding template. You can select only one template type at a time.

    • You can select multiple transcoding templates at a time.

    • When you use a transcoding template, the Template ID is a parameter for constructing the transcoding URL. For instructions on how to construct the URL, see Generate ingest and streaming URLs. For more information about the template ID and other specifications, see System preset templates. Transcoding modes include quality-first and latency-first. The latency-first mode provides lower latency for the transcoded stream.

    • For the same domain name, the AppName and template ID form a Composite Primary Key.

    Live Stream Encryption

    After you enable this feature, you can configure Alibaba Cloud Video Encryption or DRM Encryption.

    Note

    DRM encryption is supported only in the Shanghai and Singapore live centers.

    • Alibaba Cloud Video Encryption

      • Alibaba Cloud video encryption supports only HLS and FLV output formats.

      • KMS Master Key: The region of the KMS key must be the same as the live center of the domain name. If you do not have a key, go to the KMS Service to create one. For detailed instructions, see Purchase and enable a KMS instance.

      • Key Rotation Period: An integer from 60 to 3600.

      • For more information, see Alibaba Cloud Proprietary Cryptography.

    • DRM Encryption

      • Before you enable this feature, you need to first configure DRM encryption. For more information, see Configure DRM encryption.

      • Videos in the HLS format can be encrypted using Widevine and FairPlay DRM. To use FairPlay DRM, you must upload a FairPlay Streaming certificate that you obtain from Apple on the DRM Management page. For more information, see Request a FairPlay certificate.

  4. After you complete the configuration, click OK.

Configure default transcoding using an API

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class AddLiveStreamTranscode {
    public static void main(String[] args) throws Exception {

        // HttpClient Configuration
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                .maxConnections(128) // Set the connection pool size
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                // Configure the proxy
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure Credentials authentication information, including ak, secret, token
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                .build());

        // Configure the Client
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // Region ID
                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // Service-level configuration
                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about endpoints, see https://api.aliyun.com/product/live
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Parameter settings for API request
        AddLiveStreamTranscodeRequest addLiveStreamTranscodeRequest = AddLiveStreamTranscodeRequest.builder()
                .regionId("<Your RegionId>")
                .domain("<Your Domain>")
                .app("<Your App Name>")
                .template("<Your Template>")
                .encryptParameters("<Your EncryptParameters>")
                // Request-level configuration rewrite, can set Http request parameters, etc.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request
        CompletableFuture<AddLiveStreamTranscodeResponse> response = client.addLiveStreamTranscode(addLiveStreamTranscodeRequest);
        // Synchronously get the return value of the API request
        AddLiveStreamTranscodeResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronous processing of return values
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handling exceptions
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Finally, close the client
        client.close();
    }

}
Note
  • The preceding example shows how to configure transcoding for a live stream with the AppName <AppName> using the system preset template <ld>. For more information about system preset templates, see System Preset Templates.

  • setLazy("<true>") indicates that transcoding is triggered only by Stream Pulling. To trigger transcoding during Stream Ingest, set the setLazy parameter to "false".

  • For more information, see AddLiveStreamTranscode.

You can log on to the ApsaraVideo Live console. Choose Stream Management. Find the stream ingest record and click Streaming URL in the Actions column to view the transcoded streaming URL.

Note
  • The streaming URLs include the URL for the original quality stream and the URLs for the transcoded streams.

  • You can create a transcoded streaming URL by appending _TemplateID to the StreamName in the original streaming URL. For more information, see Generate ingest URLs and streaming URLs.

Custom transcoding

If the default transcoding templates do not meet your requirements, you can use custom transcoding configurations. You can customize settings such as encoding format, resolution, bitrate, frame rate, video GOP, transcoding trigger, and template ID.

You can configure custom transcoding for ApsaraVideo Live in two ways:

Configure custom transcoding in the console

  1. Log on to the ApsaraVideo Live console.
  2. Click Feature Management > Live Stream Transcoding to go to the Live Stream Transcoding page.

  3. Select the domain name that you want to configure, click the Custom Transcoding tab, and then click Add to configure a transcoding template.image.png

    The following table describes the parameters for the transcoding template.

    Parameter

    Description

    AppName

    AppName matching has a priority. The system first tries to match a transcoding template with the same AppName as the ingest URL. If no such template exists, the system matches a template configured with a single asterisk (*) for the AppName within the domain name.

    Template ID

    • When you use a transcoding template, the Template ID is a parameter used to construct the transcoding URL, as detailed in Generate ingest URLs and streaming URLs.

    • Do not set a template ID that is identical to the ID of a system preset template. For more information about system preset template IDs, see System preset templates.

    • For the same domain name, the AppName and template ID form a Composite Primary Key.

    Template Type

    • Includes Standard Template, Narrowband HD™ Template, and Audio-only Transcoding Template. The quality, performance, and price of the standard and Narrowband HD™ templates are different.

    • The Audio-only Transcoding Template removes the video and outputs only the audio stream.

    Encoding Format

    Supports H.264 and H.265.

    Recommended Template Parameters

    Four recommended parameter sets are available: low definition, standard definition, ultra-high definition, and high definition. If you select a profile, the corresponding frame rate, bitrate, and resolution are automatically filled with default values. You can adjust these values.

    Resolution

    The resolution of the output video in pixels. You can select a fixed resolution or follow the source resolution.

    Follow source resolution: If the width and height of the source stream are smaller than the adaptive dimensions, the output resolution is the same as the source. If the width and height of the source stream are larger than the adaptive dimensions, the output resolution is the adaptive dimensions. You can select different adaptation methods:

    • Short side adaptation

    • Long side adaptation

    • Landscape/portrait adaptation

    Fixed resolution: The output has a specified resolution. Different resolution profiles correspond to different prices. The resolution profiles are as follows:

    • LD: (640 × 480) and lower.

    • SD: (1280 × 720) and lower.

    • HD: (1920 × 1080) and lower.

    • 2K: (2560 × 1440) and lower.

    • 4K: (3840 × 2160) and lower.

    Note

    • Transcoding is billed based on the resolution profile (LD, SD, HD, 2K, or 4K). The resolution profile is not related to the template ID of the standard template (such as lld, lsd, lhd, and lud) or the Narrowband HD™ template (such as ld, sd, hd, and ud) in the default templates. The template ID is used only as an identifier for service calls. Do not confuse them.

    • The console does not support custom resolutions higher than 1080p. If your scenario requires 2K or 4K resolution, you can submit a ticket to apply for it.

      For information about how to submit a ticket, see Contact Us.

    Resolution profile determination rule: The output specification is determined by whether the long and short sides of the output video fall within the range defined by the output specification.

    Take the SD (1280 × 720) specification as an example:

    • If the long side of the output video is less than or equal to 1280 and the short side is less than or equal to 720, the video belongs to this output specification.

    • If the long side of the output video is greater than 1280 or the short side is greater than 720, the video belongs to a higher output specification.

    Video Frame Rate

    Follow source frame rate: If the source frame rate is within the allowed range, the output frame rate is the same as the source. If the source frame rate exceeds the upper limit, the upper limit is used. If the source frame rate is below the lower limit, the lower limit is used.

    Fixed frame rate: The output has a specified video frame rate in FPS. The value must be less than or equal to the input frame rate.

    Video Bitrate

    Follow source bitrate: If the source bitrate is within the allowed range, the output bitrate is the same as the source. If the source bitrate exceeds the upper limit, the upper limit is used. If the source bitrate is below the lower limit, the lower limit is used. You can also set the output bitrate as a multiple of the source bitrate.

    Fixed bitrate: The output has a specified bitrate in kbps. The bitrates for different resolution profiles are as follows:

    • LD: 100 to 800.

    • SD: 200 to 1500.

    • HD: 500 to 4000.

    • 2K: 2000 to 8000.

    • 4K: 4000 to 30000.

    Video GOP

    The GOP (Group of Pictures) of the output video. This is the interval between two I-frames. The value must be less than or equal to the input value. To ensure low latency, the GOP size cannot exceed 3 seconds.

    Audio Bitrate (Audio-only transcoding)

    This parameter is displayed when you set Template Type to Audio-only Transcoding Template. Unit: kbps. Valid values: 8 to 1000.

    Encoding Profile (Audio-only transcoding)

    This parameter is displayed when you set Template Type to Audio-only Transcoding Template.

    • LC-AAC: Low Complexity Advanced Audio Coding. This profile provides high transcoding efficiency.

    • HE-AAC: High-Efficiency Advanced Audio Coding. This profile provides better sound effects than LC-AAC at low audio bitrates (usually below 128 kbps).

    Sample Rate (Audio-only transcoding)

    This parameter is displayed when you set Template Type to Audio-only Transcoding Template. Valid values: 22050, 32000, 44100, 48000, and 96000.

    Number Of Sound Channels (Audio-only transcoding)

    This parameter is displayed when you set Template Type to Audio-only Transcoding Template. The number of sound tracks. Valid values: 1 and 2.

    Transcoding Mode (Advanced Configuration)

    Supports quality-first and latency-first. The latency-first mode provides lower latency for transcoded streams.

    Trigger Transcoding (Advanced Configuration)

    • Enabled: Transcoding starts only when the stream is pulled for the first time.

    • Disabled: Transcoding starts as long as there is an ingest stream, regardless of whether the stream is being pulled.

    Video Encryption (Advanced Configuration)

    After you enable this feature, you can configure Alibaba Cloud video encryption or DRM encryption.

    Note

    DRM encryption is supported only in the Shanghai and Singapore live centers.

    • Alibaba Cloud video encryption

      • Alibaba Cloud video encryption supports only HLS and FLV output formats.

      • KMS CMK ID: The region of the CMK must be the same as the region in which the domain name resides. If you do not have a key, go to Key Management Service (KMS) to create one. For more information, see Purchase and enable a KMS instance.

      • Key rotation period: An integer from 60 to 3600.

      • For more information, see Alibaba Cloud Proprietary Cryptography.

    • DRM encryption

      • Before you enable this feature, you need to first configure DRM encryption. For more information, see Configure DRM encryption.

      • Content that uses the HLS protocol can be encrypted using Widevine and FairPlay. To use FairPlay, you must upload a certificate that you obtain from Apple in DRM Certificate Management. For more information, see Request a FairPlay Certificate.

    Pass Through All Types Of SEI (Advanced Configuration)

    If enabled, all types of SEI are passed through. If disabled, SEI is not passed through.

    Follow Source Keyframe (Advanced Configuration)

    If enabled, the keyframes of the transcoded stream are consistent with the keyframes of the original stream.

    Follow Source PTS (Advanced Configuration)

    If enabled, the PTS of the transcoded stream is consistent with the PTS of the original stream.

  4. Click Add.

Configure custom transcoding using an API

Because custom transcoding parameters are complex, we recommend that you use the console together with API calls to configure custom transcoding.

First, add a custom transcoding configuration in the console.

Note

The console provides a preview of the resolution effect and lets you quickly populate parameters for low definition, standard definition, high definition, and ultra-high definition templates.

After you adjust the parameters, call the DescribeLiveStreamTranscodeInfo API operation to query the transcoding configuration.

The following sample code shows how to Query The Transcoding Configuration using the Java SDK:

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class DescribeLiveStreamTranscodeInfo {
    public static void main(String[] args) throws Exception {

        // HttpClient Configuration
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                .maxConnections(128) // Set the connection pool size
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                // Configure the proxy
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure Credentials authentication information, including ak, secret, token
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                .build());

        // Configure the Client
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // Region ID
                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // Service-level configuration
                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about endpoints, see https://api.aliyun.com/product/live
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Parameter settings for API request
        DescribeLiveStreamTranscodeInfoRequest describeLiveStreamTranscodeInfoRequest = DescribeLiveStreamTranscodeInfoRequest.builder()
                .regionId("<Your RegionId>")
                .domainTranscodeName("<Your DomainTranscodeName>")
                .appName("<Your AppName>")
                // Request-level configuration rewrite, can set Http request parameters, etc.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request
        CompletableFuture<DescribeLiveStreamTranscodeInfoResponse> response = client.describeLiveStreamTranscodeInfo(describeLiveStreamTranscodeInfoRequest);
        // Synchronously get the return value of the API request
        DescribeLiveStreamTranscodeInfoResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronous processing of return values
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handling exceptions
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Finally, close the client
        client.close();
    }

}
Note
  • You can save the queried custom transcoding configuration as a template in your business system.

  • For a description of the return parameters, see the DescribeLiveStreamTranscodeInfo API.

Then, call the AddCustomLiveStreamTranscode API operation to add a custom transcoding configuration for a domain name and AppName.

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class AddCustomLiveStreamTranscode {
    public static void main(String[] args) throws Exception {

        // HttpClient Configuration
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                .maxConnections(128) // Set the connection pool size
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                // Configure the proxy
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure Credentials authentication information, including ak, secret, token
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                .build());

        // Configure the Client
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // Region ID
                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // Service-level configuration
                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about endpoints, see https://api.aliyun.com/product/live
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Parameter settings for API request
        AddCustomLiveStreamTranscodeRequest addCustomLiveStreamTranscodeRequest = AddCustomLiveStreamTranscodeRequest.builder()
                .regionId("<Your RegionId>")
                .domain("<Your Domain>")
                .app("<Your App>")
                .kmsKeyID("<Your KmsKeyID>")
                .kmsUID("<Your KmsUID>")
                .kmsKeyExpireInterval("<Your KmsKeyExpireInterval>")
                .template("<Your Template>")
                .templateType("<Your TemplateType>")
                // Request-level configuration rewrite, can set Http request parameters, etc.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request
        CompletableFuture<AddCustomLiveStreamTranscodeResponse> response = client.addCustomLiveStreamTranscode(addCustomLiveStreamTranscodeRequest);
        // Synchronously get the return value of the API request
        AddCustomLiveStreamTranscodeResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronous processing of return values
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handling exceptions
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Finally, close the client
        client.close();
    }

}
Note

Notes:

  • The configuration takes effect only after you restart the stream ingest.

  • The transcoding template is applied only if the value of App matches the AppName in the ingest URL. The value can be up to 255 characters long and can contain digits, uppercase and lowercase letters, hyphens (-), and underscores (_). The value cannot start with a hyphen (-) or an underscore (_).

  • The value of App can also be an asterisk (*), which matches any string, including an empty string.

  • Transcoding templates are matched based on priority. The system first attempts to match a template where the AppName matches the AppName in the ingest URL. If a match is not found, the system uses the template where App is set to an asterisk (*).

  • The template ID and AppName form a composite primary key.

You can log on to the ApsaraVideo Live console. Choose Stream Management. Find the stream ingest record and click Streaming URL in the Actions column to view the transcoded streaming URL.

Note
  • The streaming URLs include the URL for the original quality stream and the URLs for the transcoded streams.

  • You can create a transcoded streaming URL by appending _TemplateID to the StreamName in the original streaming URL. For more information, see Generate ingest URLs and streaming URLs.

Multi-bitrate transcoding

Multi-bitrate transcoding lets you configure multiple transcoding profiles within a single transcoding template. Network conditions can vary significantly by region, and network fluctuations can affect the playback experience on clients. To accommodate this, you can configure multiple bitrates for different bandwidth conditions. After you configure multi-bitrate transcoding, the player can automatically select the live stream with the appropriate bitrate based on the client's network bandwidth, which improves the playback experience.

Currently, you can configure multi-bitrate transcoding only in the ApsaraVideo Live console.

Configure multi-bitrate transcoding in the console

  1. Log on to the ApsaraVideo Live console.
  2. Click Feature Management > Live Stream Transcoding to go to the Live Stream Transcoding page.

  3. Select the domain name that you want to configure, click the Multi-bitrate Transcoding tab, and then click Add to add a multi-bitrate transcoding template group.

    1. Click Basic Information to edit the basic information of the multi-bitrate transcoding template group.

      多码率转码模板组-基本信息

      The following table describes the parameters.

      Parameter

      Description

      AppName

      The AppName must be the same as the AppName in the ingest URL for the transcoding template to take effect. For the same domain name, the AppName and template group ID form a Composite Primary Key.

      Template Group ID

      The ID of the transcoding template group. The template group ID is a parameter used to construct the multi-bitrate transcoding URL. It can be up to 10 characters in length and can contain digits, uppercase letters, lowercase letters, and hyphens (-).

      Container Format

      Currently, only HLS is supported.

      Trigger Transcoding

      Currently, transcoding can be triggered only by stream ingest. This incurs transcoding fees. Triggering transcoding by stream pulling is not supported.

      Timestamp Alignment

      If you enable this feature, the GOP setting for each template is unavailable. The GOP of the source video is used.

    2. Click +Add Template to add a template.image

      Click the added template to edit its parameters. The parameters that you need to specify vary based on the template type. The following table describes the parameters.

      Parameter

      Description

      Template ID

      The ID of a single template within the transcoding template group. Template IDs within the same template group must be unique.

      Template Type

      Standard Template, Narrowband HD™ Template, and Audio-only Transcoding Template.

      The Audio-only Transcoding Template removes the video and outputs only the audio stream.

      Resolution

      The resolution of the output video in pixels. Different resolution profiles correspond to different prices. The resolution profiles are as follows:

      • LD: (640 × 480) and lower.

      • SD: (1280 × 720) and lower.

      • HD: (1920 × 1080) and lower.

      • 2K: (2560 × 1440) and lower.

      • 4K: (3840 × 2160) and lower.

      Note

      Transcoding is billed based on the resolution profile (LD, SD, HD, 2K, or 4K). The resolution profile is not related to the template ID of the standard template (such as lld, lsd, lhd, and lud) or the template ID of the Narrowband HD™ template (such as ld, sd, hd, and ud) in the default templates. Do not confuse them.

      Resolution profile determination rule: The output specification is determined by whether the long and short sides of the output video fall within the range defined by the output specification.

      Take the SD (1280 × 720) specification as an example:

      • If the long side of the output video is less than or equal to 1280 and the short side is less than or equal to 720, the video belongs to this output specification.

      • If the long side of the output video is greater than 1280 or the short side is greater than 720, the video belongs to a higher output specification.

      Video Bitrate

      The bitrate for the specified Resolution. Unit: kbps. The bitrates for different resolution profiles are as follows:

      • LD: 100 to 800.

      • SD: 200 to 1500.

      • HD: 500 to 4000.

      • 2K: 2000 to 8000.

      • 4K: 4000 to 30000.

      Video Frame Rate

      The frame rate of the output video in FPS. The value must be less than or equal to the input frame rate.

      Video GOP

      The GOP (Group of Pictures) of the output video. This is the interval between two I-frames. The value must be less than or equal to the input value. To ensure low latency, the GOP size cannot exceed 3 seconds.

      Encoding Format (Audio-only transcoding)

      Currently, only the AAC encoding format is supported.

      Encoding Profile (Audio-only transcoding)

      • LC-AAC: Low Complexity Advanced Audio Coding. This profile provides high transcoding efficiency.

      • HE-AAC: High-Efficiency Advanced Audio Coding. This profile provides better sound effects than LC-AAC at low audio bitrates (usually below 128 kbps).

      Bitrate (Audio-only transcoding)

      The audio bitrate. Valid values: 8 to 1000.

      Number Of Sound Channels (Audio-only transcoding)

      The number of sound tracks. Valid values: 1 and 2.

      Bandwidth Threshold

      An integer or a decimal number from 100 Kbps to 100 Mbps, with up to two decimal places. We recommend that you set this value to 1.2 to 1.5 times the video bitrate.

  4. After you complete the configuration, click OK.

Important
  • Currently, multi-bitrate transcoding can only provide HLS Transcoded Stream URLs.

  • To play a Multi-bitrate Transcoded stream, you must add the aliyunols=on parameter. aliyunols=on is a required parameter.

The following is an example URL:

http://<DomainName>/<AppName>/<StreamName>_<Template group ID>.m3u8?aliyunols=on&auth_key=1234****

The following example shows how to use multi-bitrate transcoding in a real-world scenario:

For example, add a multi-bitrate transcoding configuration as shown in the following figure.

image

Note

This template group contains four levels of custom transcoding configurations. For the parameter value settings for different levels, see System Preset Templates.

Then, ingest the stream and use the web-based ApsaraVideo Player for playback. During testing, you can observe that the player automatically selects the transcoded stream with the appropriate bitrate based on the client's network bandwidth.

image

Note

To use ApsaraVideo Player, see Player SDK.

H5 automatic transcoding

Real-Time Streaming (RTS) is based on WebRTC signaling. Native Browser WebRTC does not support video B-frames or AAC encoding. The automatic H5 transcoding feature provides adaptive transcoding to resolve these limitations and ensure smooth playback.

When you enable Real-Time Streaming (RTS), you can also enable the automatic H5 transcoding feature. For more information, see Step 5: Enable the Real-Time Streaming (RTS) feature.

Note
  • H5 automatic transcoding resolves issues such as B-frames and AAC encoding for RTS (artc://) in Native Browsers. To transcode video content, such as adjusting the bitrate, frame rate, or resolution, you still need to configure default or custom transcoding.

  • H5 automatic transcoding can be used together with default or custom transcoding.

  • Using H5 automatic transcoding incurs audio-only transcoding fees. For more information, see Live stream transcoding fees.

Video encryption

When you configure default or custom transcoding, you may notice fields related to video encryption. You can use the transcoding configuration to enable the Alibaba Cloud Video Encryption feature. For more information about this feature and how to implement it, see Alibaba Cloud Video Encryption.

References

For APIs related to transcoding configuration, see Live stream transcoding.

For information about using the Java SDK, see Java SDK User Guide.