You need to enable JavaScript to run this app.
文档中心
视频点播

视频点播

复制全文
下载 pdf
Python SDK
视频剪辑
复制全文
下载 pdf
视频剪辑

本文为您提供了服务端 Python SDK 的视频剪辑模块的接口调用示例。

前提条件

调用接口前,请确保您已完成集成 Python SDK。

调用示例

示例中的 your ... 均需替换。Uploader 是剪辑产物上传的目标空间名称,可从视频点播控制台获取;EditParam 是剪辑配置,按各节所链接的接口文档和视频剪辑参数说明构造,不能填写空间名称;ReqId 使用提交异步剪辑任务后返回的任务 ID;CallbackUri 使用业务服务端接收回调的地址,CallbackArgs 为业务自定义透传信息。 将需要运行的单个示例保存为 .py 文件,完成 SDK 安装、凭证配置及参数替换后,在终端执行 python3 <脚本文件名>.py。

提交异步剪辑任务

接口请求参数和返回参数说明详见提交异步剪辑任务。

# coding:utf-8
from __future__ import print_function

import json

from volcengine.vod.VodService import VodService
from volcengine.vod.models.request.request_vod_pb2 import VodSubmitDirectEditTaskAsyncRequest

if __name__ == '__main__':
    # Create a VOD instance in the specified region.
    # vod_service = VodService('cn-north-1')
    vod_service = VodService()
    
    # Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65646.
    # The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
    # During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
    # vod_service.set_ak('your ak')
    # vod_service.set_sk('your sk')

    req = VodSubmitDirectEditTaskAsyncRequest()
    req.Uploader = 'your uploader'
    req.Application = 'VideoTrackHighlight'
    req.Priority = 0
    req.CallbackUri = 'your callback uri'
    req.CallbackArgs = 'your callback args'
    editParam = {
        "Canvas": {
            "Height": 2160,
            "Width": 3840
        },
        "Output": {
            "Alpha": False,
            "Codec": {
                "AudioBitrate": 128,
                "AudioCodec": "aac",
                "Crf": 23,
                "Preset": "slow",
                "VideoCodec": "h264"
            },
            "DisableAudio": False,
            "DisableVideo": False,
            "Fps": 30
        },
        "Track": [
            [
                {
                    "ID": "video1",
                    "Source": "your source",
                    "TargetTime": [
                        0,
                        10000
                    ],
                    "Type": "video"
                }
            ]
        ],
        "Upload": {
            "SpaceName": "your uploader",
            "VideoName": "your video name"
        },
        "Uploader": "your uploader"
    }
    req.EditParam = json.dumps(editParam).encode('utf-8')
    resp = vod_service.submit_direct_edit_task_async(req)
    l = json.loads(resp)
    print(json.dumps(l, ensure_ascii=False, indent=4))
    print("****")

提交同步剪辑任务

接口请求参数和返回参数说明详见提交同步剪辑任务。

# coding:utf-8
from __future__ import print_function

import json

from volcengine.vod.VodService import VodService
from volcengine.vod.models.request.request_vod_pb2 import VodSubmitDirectEditTaskSyncRequest

if __name__ == '__main__':
    # Create a VOD instance in the specified region.
    # vod_service = VodService('cn-north-1')
    vod_service = VodService()

    # Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65646.
    # The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
    # During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
    # vod_service.set_ak('your ak')
    # vod_service.set_sk('your sk')

    req = VodSubmitDirectEditTaskSyncRequest()
    req.Uploader = 'your uploader'
    req.Application = 'SimpleCut'
    editParam = {
            "Source": "your source",
            "Upload": {
                "SpaceName": "your uploader",
                "StorageBind": False
            },
            "CutList": [
                {
                    "StartTime": 9,
                    "EndTime": 78
                },
                {
                    "StartTime":   157,
                    "EndTime": 370
                }
            ]
        }
    req.EditParam = json.dumps(editParam).encode('utf-8')
    resp = vod_service.submit_direct_edit_task_sync(req)
    l = json.loads(resp)
    print(json.dumps(l, ensure_ascii=False, indent=4))
    print("****")

取消剪辑任务

接口请求参数和返回参数说明详见取消剪辑任务。

# coding:utf-8
from __future__ import print_function

import json

from volcengine.vod.VodService import VodService
from volcengine.vod.models.request.request_vod_pb2 import VodCancelDirectEditTaskRequest

if __name__ == '__main__':
    # Create a VOD instance in the specified region.
    # vod_service = VodService('cn-north-1')
    vod_service = VodService()
    
    # Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65646.
    # The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
    # During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
    # vod_service.set_ak('your ak')
    # vod_service.set_sk('your sk')

    req = VodCancelDirectEditTaskRequest()
    req.ReqId = 'your ReqId'
    resp = vod_service.cancel_direct_edit_task(req)
    l = json.loads(resp)
    print(json.dumps(l, ensure_ascii=False, indent=4))
    print("****")

查询任务进度

接口请求参数和返回参数说明详见查询任务进度。

# coding:utf-8
from __future__ import print_function

import json

from volcengine.vod.VodService import VodService
from volcengine.vod.models.request.request_vod_pb2 import VodGetDirectEditProgressRequest

if __name__ == '__main__':
    # Create a VOD instance in the specified region.
    # vod_service = VodService('cn-north-1')
    vod_service = VodService()

    # Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65646.
    # The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
    # During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
    # vod_service.set_ak('your ak')
    # vod_service.set_sk('your sk')

    req = VodGetDirectEditProgressRequest()
    req.ReqId = 'your ReqId'
    resp = vod_service.get_direct_edit_progress(req)
    l = json.loads(resp)
    print(json.dumps(l, ensure_ascii=False, indent=4))
    print("****")

查询任务详情

接口请求参数和返回参数说明详见查询任务详情。

# coding:utf-8
from __future__ import print_function

import json

from volcengine.vod.VodService import VodService
from volcengine.vod.models.request.request_vod_pb2 import VodGetDirectEditResultRequest

if __name__ == '__main__':
    # Create a VOD instance in the specified region.
    # vod_service = VodService('cn-north-1')
    vod_service = VodService()

    # Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65646.
    # The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
    # During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
    # vod_service.set_ak('your ak')
    # vod_service.set_sk('your sk')

    req = VodGetDirectEditResultRequest()
    req.ReqIds.extend(['your ReqId'])

    resp = vod_service.get_direct_edit_result(req)
    l = json.loads(resp)
    print(json.dumps(l, ensure_ascii=False, indent=4))
    print("****")

最近更新时间:2026.10.29 14:45:45
这个页面对您有帮助吗?
有用
有用
无用
无用