本文提供Python SDK添加媒体工作流的代码示例。
完整代码
import os
import json
from urllib.parse import quote
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.AddMediaWorkflowRequest import AddMediaWorkflowRequest
# 读取环境变量中设置的ACCESS_KEY ACCESS_KEY_SECRET信息
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# region_id 为调用的服务地域ID,支持的地域参考 https://help.aliyun.com/document_detail/43248.html
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
request = AddMediaWorkflowRequest()
request.set_Name("Sequential-workflow")
startActivity = {
"Type": "Start",
"Parameters": {
"InputFile": {
"Bucket": "<your input bucket>",
"Location": "oss-cn-shanghai",
"ObjectPrefix": "media/"
},
"PipelineId": "9bad3801a2c561c22c4df9c6****"
}
}
transcodeActivity = {
"Type": "Transcode",
"Parameters": {
"Outputs": [
{
"OutputObject": quote("transcode/{ObjectPrefix}/{FileName}.{ExtName}"),
"TemplateId": "S00000001-000070"
}
],
"OutputLocation": "oss-cn-shanghai",
"OutputBucket": "<your output bucket>"
}
}
reportActivity = {
"Type": "Report",
"Parameters": {
}
}
topology = {
"Activities": {
"startNode": startActivity,
"transcodingNode": transcodeActivity,
"reportNode": reportActivity
},
"Dependencies": {
"startNode": ["transcodingNode"],
"transcodingNode": ["reportNode"],
"reportNode": []
}
}
request.set_Topology(topology)
response = client.do_action_with_exception(request)
# 输出打印
print(str(response, encoding='utf-8'))
文档内容是否对您有帮助?