媒体处理 MPC-新建独立加密任务:核心代码

时间:2024-04-30 09:35:54

核心代码

  1. 创建独立加密请求
    独立加密请求包括输入文件、输出文件和加密参数设置。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    //设置输入视频地址和输出路径
    ObsObjInfo input = new ObsObjInfo().withBucket("mpc-east-2").withLocation("region01").withObject("input/hls/index.m3u8");
    ObsObjInfo output = new ObsObjInfo().withBucket("mpc-east-2").withLocation("region01").withObject("output");
    
    String ivHlsEncrypt = System.getenv("IV_HLS_ENCRYPT");        
    String exampleKey = System.getenv("EXAMPLE_KEY");
    //创建请求
    CreateEncryptTaskRequest req = new CreateEncryptTaskRequest()
            .withBody(new CreateEncryptReq().withInput(input).withOutput(output)
                    .withEncryption(new Encryption().withHlsEncrypt(new HlsEncrypt()
                            // 设置加密算法
                            .withAlgorithm("AES-128-CBC")
                            // 密钥获取服务的地址
                            .withUrl("www.xxxxx.com")
                            // 设置初始向量
                            .withIv(ivHlsEncrypt)
                            // 设置Key
                            .withKey(exampleKey))));
    //向转码服务发送请求                        
    CreateEncryptTaskResponse rsp = initMpcClient().createEncryptTask(req);
    //打印返回消息
    System.out.println("CreateEncryptTaskResponse=" + JsonUtils.toJSON(rsp));
    
support.huaweicloud.com/sdkreference-mpc/mpc_05_0115.html