直播录制

直播录制

方法二:API配置调用添加录制配置接口添加配置。SDK调用参考如下:

Java// 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 AddLiveAppRecordConfig {

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("", 9001))

.setCredentials("", ""))

// 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("") // 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()

// Endpoint 请参考 https://api.aliyun.com/product/live

.setEndpointOverride("live.aliyuncs.com")

//.setConnectTimeout(Duration.ofSeconds(30))

)

.build();

// Parameter settings for API request

AddLiveAppRecordConfigRequest addLiveAppRecordConfigRequest = AddLiveAppRecordConfigRequest.builder()

.domainName("")

.appName("")

.ossEndpoint("")

.ossBucket("")

.streamName("")

// 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 response = client.addLiveAppRecordConfig(addLiveAppRecordConfigRequest);

// Synchronously get the return value of the API request

AddLiveAppRecordConfigResponse 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();

}

}说明 以上示例代码表示,对域名进行录制存储至OSS配置,AppName为,StreamName为,储存格式为m3u8,存储至中。

可通过所属地域在OSS地域和Endpoint进行查看。

AppName和StreamName配置详情请参见:自动录制生效规则。

录制转码流如果希望在存储录制内容时减少录制文件体积,可通过录制转码流实现(在保证画质质量的前提下,调整视频码率、提高视频压缩率、减小文件体积)。录制存储至OSS功能支持同时存储转码流与原始流,也支持仅存储转码流或原始流。

重要 使用直播转码功能会产生转码费用,按转码标准、分辨率规格及对应总转码时长计费。计费规则详见直播转码费用。

配置录制转码流示例代码>>>

Java //需要将<>内容替换成实际使用的值

List transcodeFormatList=new ArrayList();

AddLiveAppRecordConfigRequest.TranscodeRecordFormat m3u8TranscodeFormat=new AddLiveAppRecordConfigRequest.TranscodeRecordFormat();

m3u8TranscodeFormat.setFormat("m3u8");

//转码流录制OSS存储的录制文件名

m3u8TranscodeFormat.setOssObjectPrefix("");

//转码流录制切片名称

m3u8TranscodeFormat.setSliceOssObjectPrefix("");

transcodeFormatList.add(m3u8TranscodeFormat);

addLiveAppRecordConfigRequest.setTranscodeRecordFormats(transcodeFormatList);

List transcodeTemplateList=new ArrayList();

//转码模板ID

transcodeTemplateList.add("");

addLiveAppRecordConfigRequest.setTranscodeTemplatess(transcodeTemplateList);说明 若仅需录制转码流,则可以不设置原始流(setRecordFormats)。

设置录制转码流(setTranscodeRecordFormats)时,需同时指定转码模板ID(setTranscodeTemplatess),转码模板需要进行配置,具体操作请参见直播转码。

录制转码流需要在配置转码模板时,将转码配置为推流触发。

转码流录制文件名StreamName会转换成StreamName加_转码模板ID的形式。

📌 相关推荐

釰牌简介
365不给提款怎么办

釰牌简介

📅 10-13 👁️ 1848