本示例介绍使用Alibaba Cloud SDK for Java调用AddTrancodeSEI接口添加转码SEI信息。

前提条件

请在pom.xml文件中增加以下依赖,准确的SDK版本号,请参见阿里云开发工具包(SDK)

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>java.demo</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.4.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-live -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-live</artifactId>
            <version>3.7.5</version>
        </dependency>
    </dependencies>
</project>

示例代码

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.live.model.v20161101.AddTrancodeSEIRequest;
import com.aliyuncs.live.model.v20161101.AddTrancodeSEIResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

/**
 * 添加转码的SEI信息
 */
public class TestAddTrancodeSEI {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile(
                "<your-region-id>", // 地域ID,可以通过接口 DescribeRegions 查看可用的地域ID。
                "<your-access-key-id>", // 您的AccessKey ID
                "<your-access-key-secret>"); // 您的AccessKey Secret
        IAcsClient client = new DefaultAcsClient(profile);

        AddTrancodeSEIRequest request = new AddTrancodeSEIRequest();
        // 您的加速域名
        request.setDomainName("www.yourDomainName.com");
        // 接收到命令后的 delay 时间, 单位: 毫秒
        request.setDelay(1000);
        // 重复次数, -1 代表无限
        request.setRepeat(1);
        // 追加到每一个关键帧 / 每一帧,取值:keyframe / frame
        request.setPattern("keyframe");
        // SEI文本, 长度限制: 4000 字节
        request.setText("firsttxt");
        // 直播流名
        request.setStreamName("StreamName");
        // 直播流所属应用名称
        request.setAppName("testApp");

        try {
            AddTrancodeSEIResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }

}