1. AcsClient インスタンスを作成します。
    1. client = AcsClient(access_key_id, access_key_secret, mps_region_id);
  2. AcsClient インスタンスを作成します。
    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)}
  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(head_object) }request.set_Input(json.dumps(job_input))# Outputoutput = {‘OutputObject’: quote(oss_output_object)}# Ouput->TemplateIdoutput[‘TemplateId’] = template_id# Ouput->Videooutput[‘Video’] = {‘Width’: 1280, ‘Height’: 720}# Output->MergeListmerge_video = {‘MergeURL’: ‘http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(oss_input_object))}merge_tail = {‘MergeURL’: ‘http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(tail_object))}output[‘MergeList’] = [merge_video, merge_tail]# 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>