edit-icon download-icon

Screenshot

Last Updated: Sep 10, 2018

Procedure

  1. Create AcsClient instance.

    1. client = AcsClient(access_key_id, access_key_secret, mps_region_id);
  2. Create request, and set parameters.

    1. request = SubmitSnapshotJobRequest.SubmitSnapshotJobRequest()
    2. request.set_accept_format('json')
  3. Transcoding parameters.

    • Input

      1. job_input = {'Location': oss_location,
      2. 'Bucket': oss_bucket,
      3. 'Object': quote(head_object) }
      4. request.set_Input(json.dumps(job_input))
    • SnapshotConfig

      • OutputFile

        1. job_output = {'Location': oss_location,
        2. 'Bucket': oss_bucket,
        3. 'Object': quote(oss_output_object) }
        4. snapshot_config = {'OutputFile': job_output}
      • Time

        1. snapshot_config['Time'] = 2
      • Interval/Num

        1. snapshot_config['Interval'] = 2
        2. snapshot_config['Num'] = 3
      • Width/Height

        1. snapshot_config['Height'] = 360
  4. Initiate API request and display returned value.

    1. response_str = client.do_action_with_exception(request)
    2. response = json.loads(response_str)
    3. print response
    4. print 'RequestId is:', response['RequestId']
    5. print 'JobId is:', response['SnapshotJob']['Id']
    6. print 'http://%s.%s.aliyuncs.com/output_00001.jpg' % (oss_bucket, oss_location)
    7. print 'http://%s.%s.aliyuncs.com/output_00002.jpg' % (oss_bucket, oss_location)
    8. print 'http://%s.%s.aliyuncs.com/output_00003.jpg' % (oss_bucket, oss_location)

Full codes

  1. # -*- coding: utf8 -*-
  2. import json
  3. from urllib import quote
  4. from aliyunsdkcore.client import AcsClient
  5. from aliyunsdkmts.request.v20140618 import SubmitSnapshotJobRequest
  6. access_key_id = 'xxx'
  7. access_key_secret = 'xxx'
  8. mps_region_id = 'cn-hangzhou'
  9. pipeline_id = 'xxx'
  10. oss_location = 'oss-cn-hangzhou'
  11. oss_bucket = 'xxx'
  12. oss_input_object = 'input.mp4'
  13. oss_output_object = 'output_{Count}.jpg'
  14. # AcsClient
  15. client = AcsClient(access_key_id, access_key_secret, mps_region_id);
  16. # request
  17. request = SubmitSnapshotJobRequest.SubmitSnapshotJobRequest()
  18. request.set_accept_format('json')
  19. # Input
  20. job_input = {'Location': oss_location,
  21. 'Bucket': oss_bucket,
  22. 'Object': quote(oss_input_object) }
  23. request.set_Input(json.dumps(job_input))
  24. # SnapshotConfig->OutputFile
  25. job_output = {'Location': oss_location,
  26. 'Bucket': oss_bucket,
  27. 'Object': quote(oss_output_object) }
  28. snapshot_config = {'OutputFile': job_output}
  29. # SnapshotConfig->Time
  30. snapshot_config['Time'] = 2
  31. # SnapshotConfig->Interval/Num
  32. snapshot_config['Interval'] = 2
  33. snapshot_config['Num'] = 3
  34. # SnapshotConfig->Width/Height
  35. snapshot_config['Height'] = 360
  36. # SnapshotConfig
  37. request.set_SnapshotConfig(json.dumps(snapshot_config))
  38. # PipelineId
  39. request.set_PipelineId(pipeline_id)
  40. # call api
  41. response_str = client.do_action_with_exception(request)
  42. response = json.loads(response_str)
  43. print response
  44. print 'RequestId is:', response['RequestId']
  45. print 'JobId is:', response['SnapshotJob']['Id']
  46. print 'http://%s.%s.aliyuncs.com/output_00001.jpg' % (oss_bucket, oss_location)
  47. print 'http://%s.%s.aliyuncs.com/output_00002.jpg' % (oss_bucket, oss_location)
  48. print 'http://%s.%s.aliyuncs.com/output_00003.jpg' % (oss_bucket, oss_location)
Thank you! We've received your feedback.