媒体处理 MPC-新增动图任务:核心代码

时间:2024-07-30 16:48:27

核心代码

  1. 创建动图任务
    动图任务需要设置输入视频文件、输出动图路径、动图帧率、动图宽高等参数。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    //设置输入视频地址和输出路径
    ObsObjInfo input = new ObsObjInfo().withBucket("mpc-east-2").withLocation("region01").withObject("ok.mp4");
    ObsObjInfo output = new ObsObjInfo().withBucket("mpc-east-2").withLocation("region01").withObject("output");
    //创建动图请求
    CreateAnimatedGraphicsTaskRequest req = new CreateAnimatedGraphicsTaskRequest()
            .withBody(new CreateAnimatedGraphicsTaskReq().withInput(input).withOutput(output)
                    .withOutputParam(new AnimatedGraphicsOutputParam()
                            //设置动图格式
                            .withFormat(AnimatedGraphicsOutputParam.FormatEnum.GIF)
                            //设置动图帧率
                            .withFrameRate(15)
                            //设置起始时间,单位毫秒
                            .withStart(0)
                            //设置结束时间,单位毫秒,最大时间间隔60s
                            .withEnd(3_000)));
    
    // 发起请求
    CreateAnimatedGraphicsTaskResponse rsp = initMpcClient().createAnimatedGraphicsTask(req);
    // 打印结果
    System.out.println("CreateAnimatedGraphicsTaskResponse=" + JsonUtils.toJSON(rsp)); 
    
support.huaweicloud.com/sdkreference-mpc/mpc_05_0119.html