视频加密旨在通过对视频内容进行深度安全处理,确保视频数据不被非法获取和传播,可有效防止视频泄露和盗链问题,广泛用于在线教育及财经等对内容安全性要求高的领域。本文提供Python SDK创建HLS标准加密工作流相关功能的示例代码。
简介
示例调用API,创建HLS标准加密工作流。创建HLS标准加密工作流到播放加密视频的完整步骤,参见HLS的加密与播放。MPS 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("hls-transcode-workflow")
startActivity = {
"Type": "Start",
"Parameters": {
"InputFile": {
"Bucket": "<your input bucket>",
"Location": "oss-cn-shanghai",
"ObjectPrefix": "media/"
},
"PipelineId": "<PipelineId>"
}
}
transcodeActivity = {
"Type": "Transcode",
"Parameters": {
"Outputs": [
{
"OutputObject": quote("transcode/{ObjectPrefix}/{FileName}.{ExtName}"),
"TemplateId": "<hls TemplateId>",
"Encryption": {
"Type": "hls-aes-128",
"KeyUri": "<解密密钥的URI #如http://example.aliyundoc.com>"
}
}
],
"OutputLocation": "oss-cn-shanghai",
"OutputBucket": "<your output bucket>"
}
}
reportActivity = {
"Type": "Report",
"Parameters": {
}
}
topology = {
"Activities": {
"Act-Start": startActivity,
"transcodingNode": transcodeActivity,
"reportNode": reportActivity
},
"Dependencies": {
"Act-Start": ["transcodingNode"],
"transcodingNode": ["reportNode"],
"reportNode": []
}
}
request.set_Topology(topology)
response = client.do_action_with_exception(request)
# 输出打印
print(str(response, encoding='utf-8'))
文档内容是否对您有帮助?