3.代码示例
1.创建动图任务,并查询任务状态,更多参数请参考API参考
Copied!
class TestAnimatedGraphics {
public static MpcClient getMpcClient() {
HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig().withIgnoreSSLVerification(true).withTimeout(3);
String ak = System.getenv("HUAWEICLOUD_SDK_AK");
String sk = System.getenv("HUAWEICLOUD_SDK_SK");
String projectId = "********************************";
String endpoint = "https://mpc.cn-east-2.myhuaweicloud.com";
BasicCredentials auth = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId);
return MpcClient.newBuilder()
.withHttpConfig(httpConfig)
.withCredential(auth)
.withEndpoint(endpoint)
.build();
}
public static void main(String[] args) {
ObsObjInfo input = new ObsObjInfo().withBucket("mpc-east-2").withLocation("cn-east-2").withObject("ok.mp4");
ObsObjInfo output = new ObsObjInfo().withBucket("mpc-east-2").withLocation("cn-east-2").withObject("output");
CreateAnimatedGraphicsTaskRequest req = new CreateAnimatedGraphicsTaskRequest()
.withBody(new CreateAnimatedGraphicsTaskReq().withInput(input).withOutput(output)
.withOutputParam(new AnimatedGraphicsOutputParam()
.withFormat(AnimatedGraphicsOutputParam.FormatEnum.GIF)
.withFrameRate(15)
.withHeight(480)
.withWidth(360)
.withStart(1500)
.withEnd(3000)));
try {
CreateAnimatedGraphicsTaskResponse rsp = getMpcClient().createAnimatedGraphicsTask(req);
System.out.println("CreateAnimatedGraphicsTaskResponse=" + JsonUtils.toJSON(rsp));
} catch (ConnectionException | RequestTimeoutException | ServiceResponseException e) {
System.out.println(e);
}
}
}
转码服务动图场景示例(Java版本)
0.版本说明
本示例基于华为云SDK V3.0版本开发
1.功能介绍
本示例介绍了如何使用媒体处理SDK发起创建动图任务状态
2.准备工作
1、已安装JDK1.8及以上版本并完成环境配置,可参考JDK安装完成配置
2、已安装Maven,如若未安装,请下载安装。
3、已具备Eclipse等开发环境。 4、动图任务输入、输出的OBS桶必须是和endpoint是在同一个region,且已进行桶授权进行授权 5、查询region,请参考地区和终端节点。 6、媒体处理SDK获取,请参考SDK
3.代码示例
1.创建动图任务,并查询任务状态,更多参数请参考API参考
class TestAnimatedGraphics { /** * 初始化 MpcClient * @return */ public static MpcClient getMpcClient() { HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig().withIgnoreSSLVerification(true).withTimeout(3); // 根据实际需要,可以设置代理 // httpConfig.withProxyHost("proxy.xxxxxx.com").withProxyPort(8080).withProxyUsername("xxxxxx").withProxyPassword("********"); // 根据实际填写ak,sk,华为云控制台账号名下“我的凭证”>访问密钥上创建和查看您的AK/SK // 认证用的ak和sk直接写到代码中有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); // 根据实际填写项目ID,华为云控制台账号名下“我的凭证”>API凭证下查看您的项目ID String projectId = "********************************"; // 根据实际填写所需endpoint,这里以华东2为例 String endpoint = "https://mpc.cn-east-2.myhuaweicloud.com"; BasicCredentials auth = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId); return MpcClient.newBuilder() .withHttpConfig(httpConfig) .withCredential(auth) .withEndpoint(endpoint) .build(); } /** * 创建动图任务 */ public static void main(String[] args) { // 设置输入视频地址和输出路径 ObsObjInfo input = new ObsObjInfo().withBucket("mpc-east-2").withLocation("cn-east-2").withObject("ok.mp4"); ObsObjInfo output = new ObsObjInfo().withBucket("mpc-east-2").withLocation("cn-east-2").withObject("output"); // 创建动图请求 CreateAnimatedGraphicsTaskRequest req = new CreateAnimatedGraphicsTaskRequest() .withBody(new CreateAnimatedGraphicsTaskReq().withInput(input).withOutput(output) .withOutputParam(new AnimatedGraphicsOutputParam() // 设置动图格式 .withFormat(AnimatedGraphicsOutputParam.FormatEnum.GIF) // 设置动图帧率 .withFrameRate(15) // 设置动图高度 .withHeight(480) // 设置动图宽度 .withWidth(360) // 设置起始时间,单位毫秒 .withStart(1500) // 设置结束时间,单位毫秒,最大时间间隔60s .withEnd(3000))); try { CreateAnimatedGraphicsTaskResponse rsp = getMpcClient().createAnimatedGraphicsTask(req); System.out.println("CreateAnimatedGraphicsTaskResponse=" + JsonUtils.toJSON(rsp)); } catch (ConnectionException | RequestTimeoutException | ServiceResponseException e) { System.out.println(e); } } }
4.参考
更多信息请参考APIExplorer
5.修订记录