1. AcsClient インスタンスを作成します。
    1. client = AcsClient(access_key_id, access_key_secret, mps_region_id);
  2. リクエストを作成して、パラメーターを設定します。
    1. request = SubmitJobsRequest.SubmitJobsRequest()request.set_accept_format(‘json’)
  3. トランスコードパラメーターを設定します。
    • Input
      1. job_input = {‘Location’: oss_location, Bucket’: oss_bucket, Object’: quote(head_object) } request.set_Input(json.dumps(job_input))
    • Output
      1. output = {‘OutputObject’: quote(oss_output_object)}
      • Video
        1. output[‘Video’] = {‘Width’: 1280, Height’: 720}
      • OpeningList
        1. 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
        1. 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 リクエストを開始して、戻り値を表示します。
    1. 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’])
コード全体
  1. # -- coding: utf8 --import jsonfrom urllib import quotefrom aliyunsdkcore.client import AcsClientfrom aliyunsdkmts.request.v20140618 import SubmitJobsRequestaccess_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’# AcsClientclient = AcsClient(access_key_id, access_key_secret, mps_region_id);# requestrequest = SubmitJobsRequest.SubmitJobsRequest()request.set_accept_format(‘json’)# Inputjob_input = {‘Location’: oss_location, ‘Bucket’: oss_bucket, ‘Object’: quote(oss_input_object) }request.set_Input(json.dumps(job_input))# Outputoutput = {‘OutputObject’: quote(oss_output_object)}# Ouput->TemplateIdoutput[‘TemplateId’] = template_id# Output->OpeningListopening_video = {‘OpenUrl’: ‘http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(head_object)), ‘Width’: 640, ‘Start’: 2}output[‘OpeningList’] = [opening_video]# Output->TailSlateListtailslate_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]# Outputsoutputs = [output]request.set_Outputs(json.dumps(outputs))request.set_OutputBucket(oss_bucket)request.set_OutputLocation(oss_location)# PipelineIdrequest.set_PipelineId(pipeline_id)# call apiresponse_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’])
  1. </div>
  2. </article>
  3. </main>