剪辑合成

通过阅读本文,您可以了解通过服务端SDK调用OpenAPI创建智能媒体服务剪辑合成任务的示例代码。

示例代码

您可以通过阿里云OpenAPI开发者门户在线调试。

import json
import os
import sys
from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
# 引入阿里云IMS SDK
from alibabacloud_ice20201109 import models as ice20201109_models
# Credentials和云产品SDK都需引入Client,此处为创建别名
from alibabacloud_credentials.client import Client as CredClient
# 引入阿里云SDK核心包
from alibabacloud_tea_openapi.models import Config


#######需要的依赖#############
#pip install alibabacloud_credentials
#pip install alibabacloud_ice20201109==1.3.11
class Sample:

    # 初始化客户端
    @staticmethod
    def create_client(region: str) -> ICE20201109Client:
        # 使用默认凭证初始化Credentials Client
        cred = CredClient()
        config = Config(credential = cred)
        # 配置云产品服务接入地址(endpoint)
        config.endpoint = 'ice.' + region + '.aliyuncs.com'
        # 使用Credentials Client初始化ECS Client
        return ICE20201109Client(config)

    # @staticmethod
    # def create_client(
    #     access_key_id: str,
    #     access_key_secret: str,
    #     region: str,
    # ) -> ICE20201109Client:
    #     如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全
    #     config = open_api_models.Config(
    #         # 必填,您的 AccessKey ID,
    #         access_key_id = access_key_id,
    #         # 必填,您的 AccessKey Secret,
    #         access_key_secret = access_key_secret
    #     )
    #     # 访问的域名
    #     config.endpoint = 'ice.' + region + '.aliyuncs.com'
    #     return ICE20201109Client(config)

    # 读取命令行参数
    @staticmethod
    def main() -> None:
        region = 'cn-shanghai'
        # 初始化客户端
        client = Sample.create_client(region)

        # 提交剪辑合成作业
        submit_media_producing_job_request = ice20201109_models.SubmitMediaProducingJobRequest()
        # projectId, timeline, templateId 有且只有一个非空

        # 通过timeline创建合成任务
        submit_media_producing_job_request.timeline = "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****81539d420bb04d8ac4f48f2c****\"},{\"MediaId\":\"****20b48fb04483915d4f2cd8ac****\"}]}]}"
        submit_media_producing_job_request.project_metadata = "{\"coverURL\":\"http://test.testvod123.com/media/cover/mediaid.jpg\",\"description\":\"description\",\"title\":\"title\",\"tags\":\"Tag1,Tag2,Test\"}"
        submit_media_producing_job_request.output_media_config = "{\"mediaURL\":\"http://ice-editing.oss-cn-shanghai.aliyuncs.com/ice/testOutput.mp4\"}"

        # 通过模板创建合成任务
        # request.template_id = 'IceSys_VideoMerge'
        # request.clips_param = "{\"VideoArray\":[\"****05512043f49f697f7425****\",\"****2788e810116a45109f2e****\",\"****67f44f4964e6c998dee8****\"]}"
        # request.output_media_config = "{\"mediaURL\":\"http://ice-editing.oss-cn-shanghai.aliyuncs.com/ice/testOutput.mp4\"}"

        # 通过project创建合成任务
        # request.project_id = '****24b4549d46c88681030f6eab****'
        # request.output_media_config = "{\"mediaURL\":\"http://ice-editing.oss-cn-shanghai.aliyuncs.com/ice/testOutput.mp4\"}"

        submit_media_producing_job_response = client.submit_media_producing_job(submit_media_producing_job_request)
        print(submit_media_producing_job_response)
        print('request id:', submit_media_producing_job_response.body.request_id)
        print('project id:', submit_media_producing_job_response.body.project_id)
        print('job id', submit_media_producing_job_response.body.job_id)

        # 查询剪辑合成作业
        get_media_producing_job_request = ice20201109_models.GetMediaProducingJobRequest()
        get_media_producing_job_request.job_id = '****24b4549d46c88681030f6eab****'

        get_media_producing_job_response = client.get_media_producing_job(get_media_producing_job_request)
        print(get_media_producing_job_response)
        print('request id:', get_media_producing_job_response.body.request_id)
        print('media producing job:', get_media_producing_job_response.body.media_producing_job)

if __name__ == '__main__':
    Sample.main()

相关接口