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(oss_input_object) }request.set_Input(json.dumps(job_input))
    • Output
      1. output = {‘OutputObject’: quote(oss_output_object)}
      • Container
        1. output[‘Container’] = {‘Format’: mp4’}
      • Video
        1. output[‘Video’] = {‘Codec’: H. 264’, Bitrate’: 1500, Width’: 1280, Fps’: 25}
      • Audio
        1. output[‘Audio’] = {‘Codec’: AAC’, Bitrate’: 128, Channels’: 2, Samplerate’: 44100}
      • TemplateId
        1. output[‘TemplateId’] = template_id
    • PipelineId
      1. request.set_PipelineId(pipeline_id)
  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-200010’oss_location = ‘oss-cn-hangzhou’oss_bucket = ‘xxx’oss_input_object = ‘input.mp4’oss_output_object = ‘output.mp4’Create AcsClient instanceclient = AcsClient(access_key_id, access_key_secret, mps_region_id);Create request,and set parametersrequest = 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->Containeroutput[‘Container’] = {‘Format’: ‘mp4’}# Ouput->Videooutput[‘Video’] = {‘Codec’: ‘H. 264’, ‘Bitrate’: 1500, ‘Width’: 1280, ‘Fps’: 25}# Ouput->Audiooutput[‘Audio’] = {‘Codec’: ‘AAC’, ‘Bitrate’: 128, ‘Channels’: 2, ‘Samplerate’: 44100}# Ouput->TemplateIdoutput[‘TemplateId’] = template_idoutputs = [output]request.set_Outputs(json.dumps(outputs))request.set_OutputBucket(oss_bucket)request.set_OutputLocation(oss_location)# PipelineIdrequest.set_PipelineId(pipeline_id)Initiate API request and diaplay returned valueresponse_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>