全部产品
云市场

视频AI

更新时间:2019-01-24 15:40:00

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

提交AI作业

接口参数和返回字段请参考 SubmitAIJob

  1. import com.aliyuncs.vod.model.v20170321.SubmitAIJobRequest;
  2. import com.aliyuncs.vod.model.v20170321.SubmitAIJobResponse;
  3. /**
  4. * 提交作业
  5. */
  6. public static SubmitAIJobResponse submitAIJob(DefaultAcsClient client) throws Exception {
  7. SubmitAIJobRequest request = new SubmitAIJobRequest();
  8. // 设置视频ID
  9. request.setMediaId("3eb19a4585bc475e995bddxxxxxxxx");
  10. // 设置AI类型,请确保已开通该类型AI
  11. request.setTypes("AIVideoCover");
  12. // 返回结果
  13. return client.getAcsResponse(request);
  14. }
  15. /**
  16. * 以下为调用示例
  17. * @param args
  18. * @throws ClientException
  19. */
  20. public static void main(String[] args) throws ClientException {
  21. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  22. try {
  23. // 提交作业
  24. SubmitAIJobResponse response = submitAIJob(client);
  25. // 打印请求ID
  26. System.out.println("ResquestId:" + response.getRequestId());
  27. // 打印结果信息
  28. if (response.getAIJobList() != null && response.getAIJobList().size() != 0) {
  29. for (SubmitAIJobResponse.AIJob aiJob : response.getAIJobList()) {
  30. // 视频ID
  31. System.out.println("MediaId:" + aiJob.getMediaId());
  32. // 作业ID
  33. System.out.println("JobId:" + aiJob.getJobId());
  34. // AI类型
  35. System.out.println("Type:" + aiJob.getType());
  36. }
  37. }
  38. } catch (Exception e) {
  39. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  40. }
  41. }

查询AI作业

接口参数和返回字段请参考 ListAIJob

  1. import com.aliyuncs.vod.model.v20170321.ListAIJobRequest;
  2. import com.aliyuncs.vod.model.v20170321.ListAIJobResponse;
  3. /**
  4. * 查询作业
  5. */
  6. public static ListAIJobResponse listAIJob(DefaultAcsClient client) throws Exception {
  7. ListAIJobRequest request = new ListAIJobRequest();
  8. // 设置作业ID
  9. request.setJobIds("979d4d7a36ae41b1a945a2xxxxx,3eb19a4585bc475e995bddeaxxxxx");
  10. // 返回结果
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. * @param args
  16. * @throws ClientException
  17. */
  18. public static void main(String[] args) throws Exception {
  19. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. try {
  21. // 查询作业
  22. ListAIJobResponse response = listAIJob(client);
  23. // 打印请求ID
  24. System.out.println("ResquestId:" + response.getRequestId());
  25. // 打印作业列表
  26. System.out.println("============ AIJobList:");
  27. if (response.getAIJobList() != null && response.getAIJobList().size() != 0) {
  28. for (ListAIJobResponse.AIJob aiJob: response.getAIJobList()) {
  29. // 视频ID
  30. System.out.println("MediaId:" + aiJob.getMediaId());
  31. // 作业ID
  32. System.out.println("JobId:" + aiJob.getJobId());
  33. // AI类型
  34. System.out.println("Type:" + aiJob.getType());
  35. // 作业状态
  36. System.out.println("Status:" + aiJob.getStatus());
  37. // 作业结果
  38. System.out.println("Data:" + aiJob.getData());
  39. }
  40. }
  41. // 打印不存在的作业ID
  42. System.out.println("============ NonExistAIJobIds:");
  43. if (response.getNonExistAIJobIds() != null && response.getNonExistAIJobIds().size() != 0) {
  44. for (String jobId: response.getNonExistAIJobIds()) {
  45. // 作业ID
  46. System.out.println("NonExistAIJobId:" + jobId);
  47. }
  48. }
  49. } catch (Exception e) {
  50. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  51. }
  52. }

添加AI模板

接口参数和返回字段请参考 AddAITemplate

  1. import com.alibaba.fastjson.JSONArray;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyuncs.vod.model.v20170321.AddAITemplateRequest;
  4. import com.aliyuncs.vod.model.v20170321.AddAITemplateResponse;
  5. /**
  6. * 添加AI模板
  7. */
  8. public static AddAITemplateResponse addAITemplate(DefaultAcsClient client) throws Exception {
  9. AddAITemplateRequest request = new AddAITemplateRequest();
  10. // 设置模板类型,以智能审核模板为例
  11. request.setTemplateType("AIMediaAudit");
  12. // 设置模板名称
  13. request.setTemplateName("myaitemplate");
  14. // 设置模板详细配置
  15. JSONObject templateConfig = new JSONObject();
  16. JSONArray auditItem = new JSONArray();
  17. auditItem.add("terrorism");
  18. auditItem.add("porn");
  19. templateConfig.put("AuditItem", auditItem);
  20. JSONArray auditRange = new JSONArray();
  21. auditRange.add("video");
  22. auditRange.add("image-cover");
  23. auditRange.add("text-title");
  24. templateConfig.put("AuditRange", auditRange);
  25. JSONArray auditContent = new JSONArray();
  26. auditContent.add("screen");
  27. templateConfig.put("AuditContent", auditContent);
  28. templateConfig.put("AuditAutoBlock", "no");
  29. request.setTemplateConfig(templateConfig.toString());
  30. // 返回结果
  31. return client.getAcsResponse(request);
  32. }
  33. /**
  34. * 以下为调用示例
  35. * @param args
  36. * @throws ClientException
  37. */
  38. public static void main(String[] args) throws Exception {
  39. // 初始化客户端
  40. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  41. try {
  42. // 获取执行结果
  43. AddAITemplateResponse response = addAITemplate(client);
  44. // 打印请求ID
  45. System.out.println("ResquestId:" + response.getRequestId());
  46. // 打印模板ID
  47. System.out.println("TemplateId:" + response.getTemplateId());
  48. } catch (Exception e) {
  49. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  50. }
  51. }

删除AI模板

接口参数和返回字段请参考 DeleteAITemplate

  1. import com.aliyuncs.vod.model.v20170321.DeleteAITemplateRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteAITemplateResponse;
  3. /**
  4. * 删除AI模板
  5. */
  6. public static DeleteAITemplateResponse deleteAITemplate(DefaultAcsClient client) throws Exception {
  7. DeleteAITemplateRequest request = new DeleteAITemplateRequest();
  8. // 设置模板ID
  9. request.setTemplateId("1d763dd8987a122ab8596eb7dxxxxxx");
  10. // 返回结果
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. * @param args
  16. * @throws ClientException
  17. */
  18. public static void main(String[] args) throws Exception {
  19. // 初始化客户端
  20. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. try {
  22. // 获取执行结果
  23. DeleteAITemplateResponse response = deleteAITemplate(client);
  24. // 打印请求ID
  25. System.out.println("ResquestId:" + response.getRequestId());
  26. // 打印模板ID
  27. System.out.println("TemplateId:" + response.getTemplateId());
  28. } catch (Exception e) {
  29. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  30. }
  31. }

修改AI模板

接口参数和返回字段请参考 UpdateAITemplate

  1. import com.alibaba.fastjson.JSONArray;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyuncs.vod.model.v20170321.UpdateAITemplateRequest;
  4. import com.aliyuncs.vod.model.v20170321.UpdateAITemplateResponse;
  5. /**
  6. * 修改AI模板
  7. */
  8. public static UpdateAITemplateResponse updateAITemplate(DefaultAcsClient client) throws Exception {
  9. UpdateAITemplateRequest request = new UpdateAITemplateRequest();
  10. // 设置模板ID
  11. request.setTemplateId("1d763dd8987a122ab8596eb7d2xxxxxx");
  12. // 设置模板名称
  13. request.setTemplateName("myaitemplate1");
  14. // 设置模板详细配置
  15. JSONObject templateConfig = new JSONObject();
  16. JSONArray auditItem = new JSONArray();
  17. //auditItem.add("terrorism");
  18. auditItem.add("porn");
  19. templateConfig.put("AuditItem", auditItem);
  20. JSONArray auditRange = new JSONArray();
  21. auditRange.add("video");
  22. auditRange.add("image-cover");
  23. //auditRange.add("text-title");
  24. templateConfig.put("AuditRange", auditRange);
  25. JSONArray auditContent = new JSONArray();
  26. auditContent.add("screen");
  27. templateConfig.put("AuditContent", auditContent);
  28. templateConfig.put("AuditAutoBlock", "no");
  29. request.setTemplateConfig(templateConfig.toString());
  30. // 返回结果
  31. return client.getAcsResponse(request);
  32. }
  33. /**
  34. * 以下为调用示例
  35. * @param args
  36. * @throws ClientException
  37. */
  38. public static void main(String[] args) throws Exception {
  39. // 初始化客户端
  40. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  41. try {
  42. // 获取执行结果
  43. UpdateAITemplateResponse response = updateAITemplate(client);
  44. // 打印请求ID
  45. System.out.println("ResquestId:" + response.getRequestId());
  46. // 打印模板ID
  47. System.out.println("TemplateId:" + response.getTemplateId());
  48. } catch (Exception e) {
  49. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  50. }
  51. }

查询AI模板

接口参数和返回字段请参考 GetAITemplate

  1. import com.aliyuncs.vod.model.v20170321.GetAITemplateRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetAITemplateResponse;
  3. /**
  4. * 查询AI模板
  5. */
  6. public static GetAITemplateResponse getAITemplate(DefaultAcsClient client) throws Exception {
  7. GetAITemplateRequest request = new GetAITemplateRequest();
  8. // 设置模板ID
  9. request.setTemplateId("1d763dd8987a122ab8596eb7d2xxxxxx");
  10. // 返回结果
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. * @param args
  16. * @throws ClientException
  17. */
  18. public static void main(String[] args) throws Exception {
  19. // 初始化客户端
  20. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. try {
  22. // 获取执行结果
  23. GetAITemplateResponse response = getAITemplate(client);
  24. // 打印请求ID
  25. System.out.println("ResquestId:" + response.getRequestId());
  26. // 打印模板信息
  27. System.out.println("TemplateId:" + response.getTemplateInfo().getTemplateId());
  28. System.out.println("TemplateType:" + response.getTemplateInfo().getTemplateType());
  29. System.out.println("TemplateName:" + response.getTemplateInfo().getTemplateName());
  30. System.out.println("TemplateConfig:" + response.getTemplateInfo().getTemplateConfig());
  31. } catch (Exception e) {
  32. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  33. }
  34. }

查询AI模板列表

接口参数和返回字段请参考 ListAITemplate

  1. import com.aliyuncs.vod.model.v20170321.ListAITemplateRequest;
  2. import com.aliyuncs.vod.model.v20170321.ListAITemplateResponse;
  3. /**
  4. * 查询AI模板列表
  5. */
  6. public static ListAITemplateResponse listAITemplate(DefaultAcsClient client) throws Exception {
  7. ListAITemplateRequest request = new ListAITemplateRequest();
  8. // 设置模板类型,以智能审核模板为例
  9. request.setTemplateType("AIMediaAudit");
  10. // 返回结果
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. * @param args
  16. * @throws ClientException
  17. */
  18. public static void main(String[] args) throws Exception {
  19. // 初始化客户端
  20. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. try {
  22. // 查询结果
  23. ListAITemplateResponse response = listAITemplate(client);
  24. // 打印请求ID
  25. System.out.println("ResquestId:" + response.getRequestId());
  26. // 打印模板信息
  27. if (response.getTemplateInfoList() != null) {
  28. for (ListAITemplateResponse.TemplateInfoListItem templateInfo : response.getTemplateInfoList()) {
  29. System.out.println("================");
  30. System.out.println("TemplateId:" + templateInfo.getTemplateId());
  31. System.out.println("TemplateType:" + templateInfo.getTemplateType());
  32. System.out.println("TemplateName:" + templateInfo.getTemplateName());
  33. System.out.println("TemplateConfig:" + templateInfo.getTemplateConfig());
  34. }
  35. }
  36. } catch (Exception e) {
  37. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  38. }
  39. }

设置默认AI模板

接口参数和返回字段请参考 SetDefaultAITemplate

  1. import com.aliyuncs.vod.model.v20170321.SetDefaultAITemplateRequest;
  2. import com.aliyuncs.vod.model.v20170321.SetDefaultAITemplateResponse;
  3. /**
  4. * 设置默认AI模板
  5. */
  6. public static SetDefaultAITemplateResponse setDefaultAITemplate(DefaultAcsClient client) throws Exception {
  7. SetDefaultAITemplateRequest request = new SetDefaultAITemplateRequest();
  8. // 设置模板ID
  9. request.setTemplateId("1d763dd8987a122ab8596eb7xxxxxx");
  10. // 返回结果
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. * @param args
  16. * @throws ClientException
  17. */
  18. public static void main(String[] args) throws Exception {
  19. // 初始化客户端
  20. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. try {
  22. // 获取执行结果
  23. SetDefaultAITemplateResponse response = setDefaultAITemplate(client);
  24. // 打印请求ID
  25. System.out.println("ResquestId:" + response.getRequestId());
  26. // 打印模板ID
  27. System.out.println("TemplateId:" + response.getTemplateId());
  28. } catch (Exception e) {
  29. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  30. }
  31. }

查询默认AI模板

接口参数和返回字段请参考 GetDefaultAITemplate

  1. import com.aliyuncs.vod.model.v20170321.GetDefaultAITemplateRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetDefaultAITemplateResponse;
  3. /**
  4. * 查询默认AI模板
  5. */
  6. public static GetDefaultAITemplateResponse getDefaultAITemplate(DefaultAcsClient client) throws Exception {
  7. GetDefaultAITemplateRequest request = new GetDefaultAITemplateRequest();
  8. // 设置模板类型,以智能审核模板为例
  9. request.setTemplateType("AIMediaAudit");
  10. // 返回结果
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. * @param args
  16. * @throws ClientException
  17. */
  18. public static void main(String[] args) throws Exception {
  19. // 初始化客户端
  20. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. try {
  22. // 获取执行结果
  23. GetDefaultAITemplateResponse response = getDefaultAITemplate(client);
  24. // 打印请求ID
  25. System.out.println("ResquestId:" + response.getRequestId());
  26. // 打印模板信息
  27. System.out.println("TemplateId:" + response.getTemplateInfo().getTemplateId());
  28. System.out.println("TemplateType:" + response.getTemplateInfo().getTemplateType());
  29. System.out.println("TemplateName:" + response.getTemplateInfo().getTemplateName());
  30. System.out.println("IsDefault:" + response.getTemplateInfo().getIsDefault());
  31. System.out.println("TemplateConfig:" + response.getTemplateInfo().getTemplateConfig());
  32. } catch (Exception e) {
  33. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  34. }
  35. }