全部产品
云市场
云游戏

视频标志擦除

更新时间:2020-06-28 15:24:20

本文介绍视频标志擦除(EraseLogoInVideo)的语法及示例。

功能描述

可以擦除视频中的常见标志,如台标、互联网平台logo等。

前提条件

请确保您已开通服务,具体请参见服务开通。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String EraseLogoInVideo 要执行的操作。取值:EraseLogoInVideo
JobId String 564B7-DA93-447A-xxxx-191BA6AA 任务ID,同一个云账号下的所有异步处理的JobId不能重复, 建议UUID
VideoUrl String http://ivpd-cn-shanghai.oss-cn-hangzhou.aliyuncs.com/test/delele-video-logo/test1.mp4 输入视频URL。URL地址中不能包含中文字符,限定同Region的OSS上的文件URL。
Boxes.N.H Float 1.0 Logo区域高度与视频高度的占比值,取值0~1。
Boxes.N.W Float 1.0 Logo区域宽度与视频宽度的占比值,取值0~1。
Boxes.N.X Float 0.0 Logo区域左上角点x坐标与视频宽度的占比值,取值0~1。
Boxes.N.Y Float 0.0 Logo区域左上角点y坐标与视频高度的占比值,取值0~1。

返回数据

名称 类型 示例值 描述
JobId String 564B7-DA93-447A-xxxx-191BA6AA 输入的JobId
VideoUrl String http://algo-app-aic-vd-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/video-delogo/2020-03-20-11/53%3A56-DGNUGG7AcRlAylhr.mp4?Expires=1584707036&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=7CvsX7X1rSU%2B%2FDxnw484lb3LCD**** 输出处理后的视频URL地址,需要通过异步接口(GetAsyncResult)获取。

示例

1) 发起视频擦除任务

请求示例

  1. http(s)://[Endpoint]/?Action=EraseLogoInVideo
  2. &Boxes.1.H=1.0
  3. &Boxes.1.W=1.0
  4. &Boxes.1.X=0.0
  5. &Boxes.1.Y=0.0
  6. &JobId=001
  7. &VideoUrl=http://ivpd-cn-shanghai.oss-cn-hangzhou.aliyuncs.com/test/delele-video-logo/test1.mp4
  8. &<公共请求参数>

正常返回示例

JSON 格式

  1. {
  2. "RequestId": "3E1564B7-DA93-447A-xxxx-191BA6AACAF8",
  3. "Message": "Accepted",
  4. "Data": {
  5. "JobId": "001"
  6. },
  7. "Code": "0"
  8. }

该接口为异步接口,当前并未返回真实的请求结果,您需要通过返回的JobId调用GetJobStatus获取任务状态,如果执行成功通过调用GetAsyncResult接口来获取该接口的真实请求结果。

2) 查询任务状态(GetJobStatus)

通过轮询读取任务进度。

  1. http(s)://[Endpoint]/?Action=EraseLogoInVideo
  2. &JobId=001
  3. &<公共请求参数>

处理中

处理成功

  1. {
  2. "RequestId": "9E58E3E3-6FB5-47DA-xxxx-9E83A443A521",
  3. "Message": "",
  4. "Data": {
  5. "Status": "PROCESS_SUCCESS",
  6. "BatchSize": 1,
  7. "Progress": 100,
  8. "TimeToLive": -1,
  9. "Message": "",
  10. "TotalUsedTime": 42,
  11. "Completed": true
  12. },
  13. "Code": "0"
  14. }

处理失败

  1. {
  2. "RequestId": "B504322D-FF0A-4487-xxxx-72BFBADADCEE",
  3. "Message": "400:not supported region.",
  4. "Data": {
  5. "Status": "PROCESS_FAILED",
  6. "BatchSize": 1,
  7. "Progress": 100,
  8. "TimeToLive": -1,
  9. "Message": "400:not supported region.",
  10. "TotalUsedTime": 0,
  11. "Completed": true
  12. },
  13. "Code": "0"
  14. }

3) 查询任务结果(GetAsyncResult)

  1. {
  2. "RequestId": "28A7EBA0-AEBE-47DB-******-E1ACC5CAB5F5",
  3. "Message": "",
  4. "Data": {
  5. "Status": "PROCESS_SUCCESS",
  6. "Progress": 100,
  7. "Message": "",
  8. "TotalUsedTime": 42,
  9. "Completed": true,
  10. "Result": {
  11. "videoUrl": "http://algo-app-aic-vd-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/video-delogo/2020-06-26-09/18%3A30-ExAnesXrPW4IDZCq.mp4?Expires=1593422310&OSSAccessKeyId=LTAI4G9FM6qs4yUhx9PDT45m&Signature=%2FbTbqQd9GDtHh7UKzBv5As******"
  12. }
  13. },
  14. "Code": "0"
  15. }

4) 反序列化任务结果

如果任务执行成功(Data.Status==PROCESS_SUCCESS), 将Data.Result反序列化为 EraseLogoInVideoResponse.Data 。


示例代码(Java):

  1. package com.aliyun.ivpd.demo;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.alibaba.fastjson.serializer.SerializerFeature;
  5. import com.aliyuncs.AcsResponse;
  6. import com.aliyuncs.DefaultAcsClient;
  7. import com.aliyuncs.IAcsClient;
  8. import com.aliyuncs.RpcAcsRequest;
  9. import com.aliyuncs.exceptions.ClientException;
  10. import com.aliyuncs.http.ProtocolType;
  11. import com.aliyuncs.ivpd.model.v20190625.*;
  12. import com.aliyuncs.profile.DefaultProfile;
  13. import org.apache.http.util.Asserts;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.UUID;
  17. /**
  18. * doc: https://help.aliyun.com/document_detail/133958.html?spm=a2c4g.11174283.6.559.2db8519cdKrB6k
  19. */
  20. public class IVPDSdkDemoVideo {
  21. static IAcsClient client = null;
  22. static String regionId = "cn-shanghai";
  23. public static void main(String[] args) throws Exception {
  24. DefaultProfile profile = DefaultProfile.getProfile(regionId, Config.acccessKeyId, Config.accesssKeySecret);
  25. profile.getHttpClientConfig().setMaxRequests(100);
  26. profile.getHttpClientConfig().setMaxRequestsPerHost(50);
  27. client = new DefaultAcsClient(profile);
  28. testVideoLogo();
  29. }
  30. public static void testVideoLogo() throws Exception {
  31. EraseLogoInVideoRequest req = new EraseLogoInVideoRequest();
  32. List<EraseLogoInVideoRequest.Boxes> boxess = new ArrayList<>();
  33. EraseLogoInVideoRequest.Boxes boxes = new EraseLogoInVideoRequest.Boxes();
  34. boxes.setX(0f);
  35. boxes.setY(0f);
  36. boxes.setW(1f);
  37. boxes.setH(1f);
  38. boxess.add(boxes);
  39. req.setBoxess(boxess);
  40. req.setVideoUrl("http://ivpd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/test/delele-video-logo/test1.mp4");
  41. String jobId = UUID.randomUUID().toString().replace("-", "");
  42. req.setJobId(jobId);
  43. EraseLogoInVideoResponse resp = getAcsResponse(req);
  44. printResponse(req.getSysActionName(), resp.getRequestId(), resp.getCode(), resp.getMessage(), resp.getData());
  45. System.out.println("-------- EraseLogoInVideo--GetJobStatus --------------");
  46. GetJobStatusRequest statusRequest = new GetJobStatusRequest();
  47. statusRequest.setJobId(jobId);
  48. int tryTimes = 0, maxTryTimes = 16;
  49. GetJobStatusResponse statusResp = null;
  50. //2. 查询状态: GetJobStatus
  51. do {
  52. statusResp = getAcsResponse(statusRequest);
  53. System.out.println(String.format("status => completed=%s progress=%f status=%s timeToLive=%d",
  54. statusResp.getData().getCompleted(), statusResp.getData().getProgress(), statusResp.getData().getStatus(), statusResp.getData().getTimeToLive()));
  55. Thread.sleep(5000);
  56. } while (tryTimes ++ < maxTryTimes && !statusResp.getData().getCompleted());
  57. System.out.println("-------- EraseLogoInVideo--GetJobResult --------------");
  58. //3. 获取结果: GetJobResult
  59. GetAsyncResultRequest resultReq = new GetAsyncResultRequest();
  60. resultReq.setJobId(jobId);
  61. GetAsyncResultResponse resultResp = getAcsResponse(resultReq);
  62. printResponse(resultReq.getSysActionName(), resultResp.getRequestId(), resultResp.getCode(), resultResp.getMessage(), resultResp.getData());
  63. //4. 反序列化结果
  64. JSONObject json = (JSONObject) JSON.toJSON(resultResp.getData().getResult());
  65. EraseLogoInVideoResponse.Data jobRespData = json.toJavaObject(EraseLogoInVideoResponse.Data.class);
  66. StringBuilder bf = new StringBuilder();
  67. bf.append("TotalUsedTime=").append(resultResp.getData().getTotalUsedTime()).append("\n");
  68. bf.append("videoUrl=").append(jobRespData.getVideoUrl()).append("\t");
  69. System.out.println("------------result DataList ------------------------------------------------------------------");
  70. System.out.println(bf.toString());
  71. }
  72. public static void printResponse(String action, String requestId, String code, String message, Object data) {
  73. System.out.print(" " + action + " ======================================\n");
  74. System.out.println("requestId: " + requestId);
  75. System.out.println("code: " + code);
  76. System.out.println(" msg: " + message);
  77. System.out.println("body.class: " + data == null ? null : data.getClass());
  78. System.out.println("body: " + JSON.toJSONString(data, SerializerFeature.PrettyFormat));
  79. Asserts.check("0".equals(code), "assert code == 0 req:");
  80. Asserts.check(null != data, "assert data != null");
  81. System.out.println("\n");
  82. }
  83. private static <R extends RpcAcsRequest<T>, T extends AcsResponse> T getAcsResponse(R req) throws Exception {
  84. req.setSysProtocol(ProtocolType.HTTPS);
  85. try {
  86. return client.getAcsResponse(req);
  87. } catch (ClientException e) {
  88. throw e;
  89. }
  90. }
  91. }

错误码

具体请参见常见错误码。