edit-icon download-icon

Add media workflow

Last Updated: Mar 28, 2018

The user can assemble activities provided by MPS, such as transcode activity and screenshot activity into a topology. The topology is as follows:

  1. import json
  2. from aliyunsdkcore.acs_exception.exceptions import ServerException
  3. from aliyunsdkmts.request.v20140618 import AddMediaWorkflowRequest
  4. from aliyunsdkcore import client
  5. import urllib
  6. import thread
  7. # Step 1 set region
  8. REGION = "cn-shenzhen";
  9. OSS_REGION = "oss-cn-shenzhen";
  10. mtsEndpoint = "mts." + REGION + ".aliyuncs.com";
  11. # Step 2.set accesskey & keySecret
  12. accessKeyId = "";
  13. accessKeySecret = "";
  14. # Step 3.set mps transcoding queue id
  15. PIPELINE_ID = "38bba54d524448be92d277caaa8da118";
  16. cl = client.AcsClient(accessKeyId, accessKeySecret, REGION)
  17. def addMeidaWorkflow():
  18. request = AddMediaWorkflowRequest.AddMediaWorkflowRequest()
  19. request.set_Name("Sequential-workflow");
  20. startActivity = {
  21. "Type": "Start",
  22. "Parameters": {
  23. "InputFile": {
  24. "Bucket": "mtb-sz-in",
  25. "Location": OSS_REGION,
  26. "ObjectPrefix": "media/"
  27. },
  28. "PipelineId": PIPELINE_ID
  29. }
  30. }
  31. transcodeActivity = {
  32. "Type": "Transcode",
  33. "Parameters": {
  34. "Outputs": [
  35. {
  36. "OutputObject": encodeByRFC3986("transcode/{ObjectPrefix}/{FileName}.{ExtName}"),
  37. "TemplateId": "S00000001-000070"
  38. }
  39. ],
  40. "OutputLocation": OSS_REGION,
  41. "OutputBucket": "mtb-sz-out"
  42. }
  43. }
  44. reportActivity = {
  45. "Type": "Report",
  46. "Parameters": {
  47. }
  48. }
  49. topology = {
  50. "Activities": {
  51. "startNode": startActivity,
  52. "transcodingNode": transcodeActivity,
  53. "reportNode": reportActivity
  54. },
  55. "Dependencies": {
  56. "startNode": ["transcodingNode"],
  57. "transcodingNode": ["reportNode"],
  58. "reportNode": []
  59. }
  60. }
  61. request.set_Topology(topology)
  62. try:
  63. response = json.loads(cl.do_action_with_exception(request))
  64. print json.dumps(response)
  65. except ServerException, e:
  66. print e.get_error_code(), e.get_error_msg()
  67. def encodeByRFC3986(ossObject):
  68. return urllib.quote(ossObject)
  69. if __name__ == "__main__":
  70. addMeidaWorkflow()
Thank you! We've received your feedback.