全部产品
媒体转码

截图

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

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

提交截图作业

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

  1. import json
  2. from aliyunsdkmts.request.v20140618 import SubmitSnapshotJobRequest
  3. from aliyunsdkcore import client
  4. region = '<region>'
  5. access_key_id = '<access_key_id>'
  6. access_key_secret = '<access_key_secret>'
  7. pipeline_id = '<pipeline_id>'
  8. oss_location='<oss_location>'
  9. input_bucket='<input_bucket>'
  10. input_object='<input_object>'
  11. output_bucket='<output_bucket>'
  12. output_object='<output_object>'
  13. time='<time>'
  14. interval='<interval>'
  15. num='<num>'
  16. frame_type='<frame_type>'
  17. width='<width>'
  18. height='<height>'
  19. input={ 'Location': oss_location,
  20. 'Bucket': input_bucket,
  21. 'Object': input_object
  22. }
  23. output={
  24. 'Location': oss_location,
  25. 'Bucket': output_bucket,
  26. 'Object': output_object
  27. }
  28. snapshot_config={
  29. 'OutputFile':output,
  30. 'Time':time,
  31. 'Interval':interval,
  32. 'Num':num,
  33. 'FrameType':frame_type,
  34. "Width":width,
  35. "Height":height
  36. }
  37. client = client.AcsClient(access_key_id, access_key_secret, region)
  38. request = SubmitSnapshotJobRequest.SubmitSnapshotJobRequest()
  39. request.set_PipelineId(pipeline_id)
  40. request.set_Input(input)
  41. request.set_SnapshotConfig(snapshot_config)
  42. response = client.do_action_with_exception(request);
  43. json_response = json.loads(response)
  44. snapshotJob = json_response['SnapshotJob']
  45. print 'snapshotJob id:' + snapshotJob['Id']

查询截图作业

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

  1. import json
  2. from aliyunsdkmts.request.v20140618 import QuerySnapshotJobListRequest
  3. from aliyunsdkcore import client
  4. region = '<region>'
  5. access_key_id = '<access_key_id>'
  6. access_key_secret = '<access_key_secret>'
  7. // job_id,多个截图任务用','分隔
  8. job_id = '<job_id>'
  9. client = client.AcsClient(access_key_id, access_key_secret, region)
  10. request = QuerySnapshotJobListRequest.QuerySnapshotJobListRequest()
  11. request.set_SnapshotJobIds(job_id)
  12. request.set_accept_format("JSON")
  13. response = client.do_action(request);
  14. json_response = json.loads(response)
  15. snapshots = json_response['SnapshotJobList']['SnapshotJob']
  16. for snapshot in snapshots:
  17. print 'snapshot id:' + snapshot['Id'] + ', count:' + snapshot['Count']
本文导读目录
本文导读目录
以上内容是否对您有帮助?