全部产品
媒体转码

截图

更新时间:2017-07-06 13:11:33   分享:   

对存储于OSS上的视频文件截取指定时间的JPG格式图像。提供一系列截图接口 ,比如SubmitSnapshotJob,QuerySnapshotJobList。

提交截图作业

可以直接通过SubmitSnapshotJob接口提交截图任务。

  1. String region = "<region>";
  2. String accessKeyId = "<accessKeyId>";
  3. String accessKeySecret = "<accessKeySecret>";
  4. String pipelineId = "<pipelineId>";
  5. String inputBucket="<bucket>";
  6. String ossLocation = "<ossLocation>";
  7. String inputObject = "<inputObject>";
  8. String outputBucket="<outputBucket>";
  9. String outputObject = "<outputObject>";
  10. String time = "<time>";
  11. String interval="<interval>";
  12. String num = "<num>";
  13. String frameType = "<frameType>";
  14. String width="<width>";
  15. String height="<height>";
  16. DefaultProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
  17. DefaultAcsClient client = new DefaultAcsClient(profile);
  18. try{
  19. SubmitSnapshotJobRequest request=new SubmitSnapshotJobRequest();
  20. request.setInput(generateSnapshotInput(ossLocation,inputBucket,inputObject).toJSONString());
  21. request.setSnapshotConfig(generateSnapshotConfig(ossLocation,outputBucket,outputObject,time,
  22. interval,num,frameType,width,height).toJSONString());
  23. request.setPipelineId(pipelineId);
  24. SubmitSnapshotJobResponse response=client.getAcsResponse(request);
  25. SnapshotJob job=response.getSnapshotJob();
  26. System.out.println(job.getId());
  27. } catch (ClientException e) {
  28. System.out.println(e.getErrMsg());
  29. } catch (Exception e) {
  30. System.out.println(e.getMessage());
  31. }
  32. private static JSONObject generateSnapshotConfig(String osslocation, String outputbucket,
  33. String outputobject,String time, String interval, String num,
  34. String frametype, String width, String height) {
  35. JSONObject snapshotConfig = new JSONObject();
  36. JSONObject output = generateSnapshotInput(osslocation,outputbucket,outputobject);
  37. snapshotConfig.put("OutputFile", output);
  38. snapshotConfig.put("Time", time);
  39. snapshotConfig.put("Interval", interval);
  40. snapshotConfig.put("Num", num);
  41. snapshotConfig.put("FrameType", frametype);
  42. snapshotConfig.put("Width", width);
  43. snapshotConfig.put("Height", height);
  44. return snapshotConfig;
  45. }
  46. private static JSONObject generateSnapshotInput(String ossLocation,
  47. String inputBucket, String inputObject){
  48. JSONObject input = new JSONObject();
  49. input.put("Location", ossLocation);
  50. input.put("Bucket", inputBucket);
  51. input.put("Object", inputObject);
  52. return input;
  53. }

查询截图作业

如果已经知道snapshotJobId,可以通过snapshotJobId调用QuerySnapshotJobList接口查询截图信息。

  1. String region = "<region>";
  2. String accessKeyId = "<accessKeyId>";
  3. String accessKeySecret = "<accessKeySecret>";
  4. // 已知的截图jobId,多个截图任务用','分隔
  5. String jobIds = "<jobId>";
  6. DefaultProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
  7. DefaultAcsClient client = new DefaultAcsClient(profile);
  8. try{
  9. QuerySnapshotJobListRequest request=new QuerySnapshotJobListRequest();
  10. request.setSnapshotJobIds(jobIds);
  11. QuerySnapshotJobListResponse response=client.getAcsResponse(request);
  12. List<SnapshotJob> jobList=response.getSnapshotJobList();
  13. System.out.println(jobList.get(0).getId());
  14. } catch (ClientException e) {
  15. System.out.println(e.getErrMsg());
  16. } catch (Exception e) {
  17. System.out.println(e.getMessage());
  18. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?