1. 建立AcsClient執行個體。
    client = AcsClient(access_key_id, access_key_secret, mps_region_id);
  2. 建立request,並設定參數。
    request = SubmitJobsRequest.SubmitJobsRequest()
    request.set_accept_format('json')
  3. 設定轉碼參數。
    • Input
      job_input = {'Location': oss_location,
              'Bucket': oss_bucket,
              'Object': quote(head_object) }
       request.set_Input(json.dumps(job_input))
    • Output
      output = {'OutputObject': quote(oss_output_object)}
      • Video
        output['Video'] = {'Width': 1280,
                           'Height': 720}
      • OpeningList
        opening_video = {'OpenUrl': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(head_object)),
                 'Width': 640,
                 'Start': 2}
        output['OpeningList'] = [opening_video]
      • TailSlateList
        tailslate_video = {'TailUrl': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(tail_object)),
                   'Width': 640,
                   'BlendDuration': 3,
                   'BgColor': 'Black'}
        output['TailSlateList'] = [tailslate_video]
  4. 發起API請求並顯示傳回值。
    response_str = client.do_action_with_exception(request)
      response = json.loads(response_str)
      print 'RequestId is:', response['RequestId']
      if response['JobResultList']['JobResult'][0]['Success']:
          print 'JobId is:', response['JobResultList']['JobResult'][0]['Job']['JobId']
      else:
          print ('SubmitJobs Failed code:',
                 response['JobResultList']['JobResult'][0]['Code'],
                 'message:',
                 response['JobResultList']['JobResult'][0]['Message'])
完整代碼
# -*- coding: utf8 -*-
import json
from urllib import quote
from aliyunsdkcore.client import AcsClient
from aliyunsdkmts.request.v20140618 import SubmitJobsRequest
access_key_id = 'xxx'
access_key_secret = 'xxx'
mps_region_id = 'cn-hangzhou'
pipeline_id = 'xxx'
template_id = 'S00000001-200030'
oss_location = 'oss-cn-hangzhou'
oss_bucket = 'xxx'
oss_input_object = 'input.mp4'
oss_output_object = 'output.mp4'
head_object = 'head.mp4'
tail_object = 'tail.mp4'
# AcsClient
client = AcsClient(access_key_id, access_key_secret, mps_region_id);
# request
request = SubmitJobsRequest.SubmitJobsRequest()
request.set_accept_format('json')
# Input
job_input = {'Location': oss_location,
             'Bucket': oss_bucket,
             'Object': quote(oss_input_object) }
request.set_Input(json.dumps(job_input))
# Output
output = {'OutputObject': quote(oss_output_object)}
# Ouput->TemplateId
output['TemplateId'] = template_id
# Output->OpeningList
opening_video = {'OpenUrl': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(head_object)),
                 'Width': 640,
                 'Start': 2}
output['OpeningList'] = [opening_video]
# Output->TailSlateList
tailslate_video = {'TailUrl': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(tail_object)),
                   'Width': 640,
                   'BlendDuration': 3,
                   'BgColor': 'Black'}
output['TailSlateList'] = [tailslate_video]
# Outputs
outputs = [output]
request.set_Outputs(json.dumps(outputs))
request.set_OutputBucket(oss_bucket)
request.set_OutputLocation(oss_location)
# PipelineId
request.set_PipelineId(pipeline_id)
# call api
response_str = client.do_action_with_exception(request)
response = json.loads(response_str)
print 'RequestId is:', response['RequestId']
if response['JobResultList']['JobResult'][0]['Success']:
    print 'JobId is:', response['JobResultList']['JobResult'][0]['Job']['JobId']
else:
    print ('SubmitJobs Failed code:',
           response['JobResultList']['JobResult'][0]['Code'],
           ' message:',
           response['JobResultList']['JobResult'][0]['Message'])