问题描述:

现在有个需求,需要对视频平均截9张图;参考阿里云文档(https://help.aliyun.com/document_detail/56333.html?spm=a2c4g.11186623.6.754.56b5d84aXbBrNs),发现如下问题

  1. 当Interval小于等于2得时候,其他参数无效,只能抽取首帧1张图(即num设置无效)
  2. 参考文档得抽帧截图参数部分(如下图):https://help.aliyun.com/document_detail/29253.html?spm=a2c4g.11186623.6.729.20fad84aBPIdhz ,(用了一个5s得视频测试,只有一张图,测试视频[https://gusteau-test.oss-cn-hangzhou.aliyuncs.com/component/1592380139915.mp4])(用了一个半分钟得视频测试,只有5张图,测试视频[http://gusteau-test.oss-cn-hangzhou.aliyuncs.com/material/clip/video/2020/09/21/e6u47i5g8fk.mp4])

image.png

测试代码如下

  1. private static String accessKeyId = "xxx";
  2. private static String accessKeySecret = "xxx";
  3. private static String ossLocation = "oss-cn-hangzhou";
  4. private static String mpsRegionId = "cn-hangzhou";
  5. private static String pipelineId = "xxx";
  6. private static String ossBucket = "xxx";
  7. private static String ossInputObject = "xxx";
  8. private static String ossOutputObject = "xxx";
  9. public static void main(String[] args) {
  10. // DefaultAcsClient
  11. DefaultProfile profile = DefaultProfile.getProfile(
  12. mpsRegionId, // Region ID
  13. accessKeyId, // AccessKey ID
  14. accessKeySecret); // Access Key Secret
  15. IAcsClient client = new DefaultAcsClient(profile);
  16. // request
  17. SubmitSnapshotJobRequest request = new SubmitSnapshotJobRequest();
  18. // Input
  19. JSONObject input = new JSONObject();
  20. input.put("Location", ossLocation);
  21. input.put("Bucket", ossBucket);
  22. try {
  23. input.put("Object", URLEncoder.encode(ossInputObject, "utf-8"));
  24. } catch (UnsupportedEncodingException e) {
  25. throw new RuntimeException("input URL encode failed");
  26. }
  27. request.setInput(input.toJSONString());
  28. // SnapshotConfig
  29. JSONObject snapshotConfig = new JSONObject();
  30. // SnapshotConfig->OutputFile
  31. JSONObject output = new JSONObject();
  32. output.put("Location", ossLocation);
  33. output.put("Bucket", ossBucket);
  34. try {
  35. output.put("Object", URLEncoder.encode(ossOutputObject, "utf-8"));
  36. } catch (UnsupportedEncodingException e) {
  37. throw new RuntimeException("output URL encode failed");
  38. }
  39. snapshotConfig.put("OutputFile", output.toJSONString());
  40. // SnapshotConfig->Time
  41. snapshotConfig.put("Time", "0");
  42. // SnapshotConfig->Interval/Num
  43. snapshotConfig.put("Interval", "0");
  44. snapshotConfig.put("Num", "9");
  45. // SnapshotConfig->Width/Height
  46. // snapshotConfig.put("Height", "360");
  47. // SnapshotConfig
  48. request.setSnapshotConfig(snapshotConfig.toJSONString());
  49. // PipelineId
  50. request.setPipelineId(pipelineId);
  51. // call api
  52. SubmitSnapshotJobResponse response;
  53. try {
  54. response = client.getAcsResponse(request);
  55. System.out.println("RequestId is:"+response.getRequestId());
  56. System.out.println("JobId is:" + response.getSnapshotJob().getId());
  57. } catch (ServerException e) {
  58. e.printStackTrace();
  59. } catch (ClientException e) {
  60. e.printStackTrace();
  61. }
  62. }

解决:

找了阿里客服,最后的解决也很简单,如果视频很短最好将FrameType设置为normal
image.png
晕死,文档也没说鸭。