はじめに

ここでは、HLS 標準暗号化ワークフローを作成するための、API 呼び出しの例を紹介しています。 HLS の標準暗号化ワークフローの作成、および暗号化ビデオの再生の詳細については、「HLS の暗号化と再生」をご参照ください。 MPS SDK の詳細については、「インストール」をご参照ください。

コードの例

  1. import jsonfrom aliyunsdkmts.request.v20140618 import AddMediaWorkflowRequestfrom aliyunsdkcore import clientREGIONID = ‘<region>’ACCESSKEYID = ‘<accessKeyId>’ACCESSKEY_SECRET = ‘<accessKeySecret>’PIPELINE_ID = “<PipelineId>”TEMPLATE_ID = S00000001-100020 #Transcoding template ID, m3u8 template, set as neededOSS_LOCATION = “<OssLocation>”INPUT_BUCKET = “<InputBucket>”INPUT_PATH = “<InputPath>” ##Example: “HLS-Encryption”OUTPUT_BUCKET = “<OutputBucket>”ENCRYPTION_TYPE = “hls-aes-128”HLS_KEY_URI = “<URI of decryption key>” #Example: http://decrypt.testdomain.comACT_START = “Act-Start”ACT_ENCRYPTION = “Act-HLS-Encryption”ACT_REPORT = “Act-Report”def addMediaWorkflow(): global client client = client.AcsClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET, REGION_ID) request = AddMediaWorkflowRequest.AddMediaWorkflowRequest() request.set_Topology(buildWorkflowTopology()) request.set_Name(“HLS encryption workflow py”) response = client.do_action_with_exception(request) print json.loads(response)def buildWorkflowTopology(): workflow = {} workflow[“Activities”] = buildActivities() workflow[“Dependencies”] = buildDependencies() print json.dumps(workflow) return json.dumps(workflow)def buildActivities(): activities = {} activities[ACT_START] = buildStartActivity() activities[ACT_ENCRYPTION] = buildTranscodeActivity() activities[ACT_REPORT] = buildReportActivity() return activitiesdef buildStartActivity(): startActivity = {} startActivity[“Name”] = ACT_START startActivity[“Type”] = “Start” startActivity[“Parameters”] = buildStartParameters() return startActivitydef buildStartParameters(): startParameters = {} startParameters[“PipelineId”] = PIPELINE_ID startParameters[“InputFile”] = buildInputFile(); return startParametersdef buildInputFile(): inputFile = {} inputFile[“Bucket”] = INPUT_BUCKET inputFile[“Location”] = OSS_LOCATION inputFile[“ObjectPrefix”] = INPUT_PATH return inputFiledef buildTranscodeActivity(): transcodeActivity = {} transcodeActivity[“Name”] = ACT_ENCRYPTION transcodeActivity[“Type”] = “Transcode” transcodeActivity[“Parameters”] = buildTranscodeParameters() return transcodeActivitydef buildTranscodeParameters(): transcodeParameters = {} transcodeParameters[“OutputBucket”] = OUTPUT_BUCKET transcodeParameters[“OutputLocation”] = OSS_LOCATION transcodeParameters[“Outputs”] = buildOutputsConfig() return transcodeParametersdef buildOutputsConfig(): outputs = [] output = {} output[“ObjectRegex”] = ACT_ENCRYPTION + “/{RunId}/{FileName}” output[“TemplateId”] = TEMPLATE_ID output[“Encryption”] = buildEncryption() outputs.append(output) return outputsdef buildEncryption(): encryption = {} encryption[“Type”] = ENCRYPTION_TYPE encryption[“KeyUri”] = HLS_KEY_URI return encryptiondef buildReportActivity(): reportActivity = {} reportActivity[“Name”] = ACT_REPORT reportActivity[“Parameters”] = buildReportParameters() reportActivity[“Type”] = “Report” return reportActivitydef buildReportParameters(): parameters = {} parameters[“PublishType”] = “Auto” return parametersdef buildDependencies(): dependencies ={} subActivityOfStart = [ACT_ENCRYPTION] dependencies[ACT_START] = subActivityOfStart subActivityOfTranscode = [ACT_REPORT] dependencies[ACT_ENCRYPTION] = subActivityOfTranscode dependencies[ACT_REPORT] = [] return dependenciesif __name == “__main“: addMediaWorkflow()
  1. </article>
  2. </main>