edit-icon download-icon

Screenshot

Last Updated: Apr 19, 2018

MPS allows you to take JPG screenshots at a specified time of a video file stored in OSS. It provides a series of screenshot APIs such as SubmitSnapshotJob and QuerySnapshotJobList.

Submit a screenshot task

You can submit a screenshot task over 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']

Query a screenshot task

If you already have the screenshot task ID, you can use the ID to call QuerySnapshotJobList to query the screenshot information.

  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. // Task ID. Multiple screenshot tasks are separated by commas&nbsp;(,)
  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']
Thank you! We've received your feedback.