文档

视频剪辑

视频点播云剪辑提供专业的在线视频剪辑能力,支持音视频、文字等素材剪辑合成新的视频。本文提供了Java SDK视频剪辑相关的API调用示例,包含创建及管理云剪辑工程、发起剪辑合成任务等。

接口调用说明

  • 本文提供的接口调用示例均通过AccessKey初始化客户端实例。

  • 接口的参数解释和返回字段的详细说明请访问阿里云OpenAPI门户,在各接口右侧的文档页签查看。

  • 本文仅提供部分复杂接口的代码示例,其余接口的SDK代码示例,可以通过阿里云OpenAPI门户获取。访问阿里云OpenAPI门户,在接口的左侧参数配置页签,填写需要的参数信息并发起调用后,在右侧的SDK示例页签,选择SDK版本,选择目标语言,查看并下载示例代码。

  • 本文均以V1.0版本的SDK为例进行接口调用,如需获取V2.0版本的SDK示例,请在通过阿里云OpenAPI门户获取SDK示例时,指定到对应的SDK版本。image.png

初始化客户端

使用前请先初始化客户端,请参见初始化

通过时间线-发起剪辑合成

调用ProduceEditingProjectVideo接口,完成通过时间线-发起剪辑合成功能。

绝大多数场景下,使用这种方式即可合成视频。

阿里云OpenAPI门户地址:ProduceEditingProjectVideo

调用示例如下:

说明

通过时间线实现剪辑合成的更多Timeline示例请参见视频剪辑-使用示例

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoRequest;
import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoResponse;

   /**
    *读取AccessKey信息
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // 点播服务接入地域
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}
    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient();

        ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
        // Build Editing Project Timeline
        request.setTimeline(buildTimeline());
        // Set Produce Media Metadata
        request.setMediaMetadata(buildMediaMetadata());
        // Set Produce Configuration
        request.setProduceConfig(buildProduceConfig());

        ProduceEditingProjectVideoResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response != null){
                // Produce Media ID
                System.out.println("MediaId:" + response.getMediaId());
                // Request ID
                System.out.println("RequestId:" + response.getRequestId());
            }
        } catch (ServerException e){
            System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (ClientException e){
            System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
    }

    public static String buildMediaMetadata(){
        JSONObject mediaMetadata = new JSONObject();
        // Produce Media Title
        mediaMetadata.put("Title", "Title");
        // Produce Media Description
        mediaMetadata.put("Description", "Description");
        // Produce Media UserDefined Cover URL
        mediaMetadata.put("CoverURL", "http://192.168.0.0/16/media/cover/mediaid.jpg");
        // Produce Media Category ID
        mediaMetadata.put("CateId", null);
        // Produce Media Category Name
        mediaMetadata.put("Tags", "Tag1,Tag2,Test");
        return mediaMetadata.toString();
    }

    public static String buildProduceConfig(){
        JSONObject produceConfig = new JSONObject();
        /*
         The produce process can generate media mezzanine file. You can use the mezzanine file to transcode other media files,just like the transcode process after file upload finished. This field describe the Transocde TemplateGroup ID after produce mezzanine finished.
         1. Not required 
         2. Use default transcode template group id when empty
         */
        produceConfig.put("TemplateGroupId", null);
        return produceConfig.toString();
    }

    /**
     * This Sample shows how to merge two videos
     */
    public static String buildTimeline(){
        JSONObject timeline = new JSONObject();

        // Video Track
        JSONArray videoTracks = new JSONArray();
        JSONObject videoTrack = new JSONObject();

        // Video Track Clips
        JSONArray videoTrackClips = new JSONArray();
        JSONObject videoTrackClip1 = new JSONObject();
        videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe****");
        videoTrackClips.add(videoTrackClip1);
        JSONObject videoTrackClip2 = new JSONObject();
        videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe****");
        videoTrackClips.add(videoTrackClip2);

        videoTrack.put("VideoTrackClips", videoTrackClips);
        videoTracks.add(videoTrack);

        timeline.put("VideoTracks", videoTracks);

        return timeline.toString();
    }

通过云剪辑工程-发起剪辑合成

调用ProduceEditingProjectVideo接口,完成通过云剪辑工程-发起剪辑合成功能。

对云剪辑工程有较高管理需求的场景下,可以使用这种方式合成视频。

阿里云OpenAPI门户地址:ProduceEditingProjectVideo

调用示例如下:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoRequest;
import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoResponse;

   /**
    *读取AccessKey信息
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // 点播服务接入地域
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient();

        ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
        // Set Editing Project ID need to produce
        request.setProjectId("ProjectId");
        // Set Produce Media Metadata
        request.setMediaMetadata(buildMediaMetadata());
        // Set Produce Configuration
        request.setProduceConfig(buildProduceConfig());

        ProduceEditingProjectVideoResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response != null){
                // Produce Media ID
                System.out.println("MediaId:" + response.getMediaId());
                // Request ID
                System.out.println("RequestId:" + response.getRequestId());
            }
        } catch (ServerException e){
            System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (ClientException e){
            System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
    }

    public static String buildMediaMetadata(){
        JSONObject mediaMetadata = new JSONObject();
        // Produce Media Title
        mediaMetadata.put("Title", "Title");
        // Produce Media Description
        mediaMetadata.put("Description", "Description");
        // Produce Media UserDefined Cover URL
        mediaMetadata.put("CoverURL", "http://192.168.0.0/16/media/cover/mediaid.jpg");
        // Produce Media Category ID
        mediaMetadata.put("CateId", null);
        // Produce Media Category Name
        mediaMetadata.put("Tags", "Tag1,Tag2,Test");
        return mediaMetadata.toString();
    }

    public static String buildProduceConfig(){
        JSONObject produceConfig = new JSONObject();
        /*
         The produce process can generate media mezzanine file. You can use the mezzanine file to transcode other media files,just like the transcode process after file upload finished. This field describe the Transocde TemplateGroup ID after produce mezzanine finished.
         1. Not required 
         2. Use default transcode template group id when empty
         */
        produceConfig.put("TemplateGroupId", null);
        return produceConfig.toString();
    }

创建云剪辑工程

调用AddEditingProject接口,完成创建云剪辑工程功能。

阿里云OpenAPI门户地址:AddEditingProject

调用示例如下:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.AddEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.AddEditingProjectResponse;

   /**
    *读取AccessKey信息
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // 点播服务接入地域
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient();

        AddEditingProjectRequest request = new AddEditingProjectRequest();
        // Build Editing Project Timeline
        request.setTimeline(buildTimeline());
        // Set Editing Project Title
        request.setTitle("Editing Project Title");
        // Set Editing Project Description
        request.setDescription("Editing Project Description");
        // Set Editing Project Cover URL
        request.setCoverURL("http://192.168.0.0/16/editingproject/cover/projectid.jpg");

        AddEditingProjectResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response != null){
                if (response.getProject() != null){
                    System.out.println("Editing Project ID:" + response.getProject().getProjectId());
                    System.out.println("Editing Project Title:" + response.getProject().getTitle());
                    System.out.println("Editing Project Create Time:" + response.getProject().getCreationTime());
                    System.out.println("Editing Project Description:" + response.getProject().getDescription());
                    System.out.println("Editing Project Status:" + response.getProject().getStatus());
                }

                // Request ID
                System.out.println("RequestId:" + response.getRequestId());
            }
        } catch (ServerException e){
            System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (ClientException e){
            System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
    }

    /**
     * This Sample shows how to merge two videos
     */
    public static String buildTimeline(){
        JSONObject timeline = new JSONObject();

        // Video Track
        JSONArray videoTracks = new JSONArray();
        JSONObject videoTrack = new JSONObject();

        // Video Track Clips
        JSONArray videoTrackClips = new JSONArray();
        JSONObject videoTrackClip1 = new JSONObject();
        videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe****");
        videoTrackClips.add(videoTrackClip1);
        JSONObject videoTrackClip2 = new JSONObject();
        videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe****");
        videoTrackClips.add(videoTrackClip2);

        videoTrack.put("VideoTrackClips", videoTrackClips);
        videoTracks.add(videoTrack);

        timeline.put("VideoTracks", videoTracks);

        return timeline.toString();
    }

修改云剪辑工程

调用UpdateEditingProject接口,完成修改云剪辑工程功能。

阿里云OpenAPI门户地址:UpdateEditingProject

调用示例如下:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.UpdateEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.UpdateEditingProjectResponse;

   /**
    *读取AccessKey信息
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // 点播服务接入地域
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient();

        UpdateEditingProjectRequest request = new UpdateEditingProjectRequest();
        request.setProjectId("YourProjectId");
        // Set Editing Project Timeline
        request.setTimeline(buildTimeline());
        // Set Editing Project Title
        request.setTitle("Editing Project Title");
        // Set Editing Project Description
        request.setDescription("Editing Project Description");
        // Set Editing Project Cover URL
        request.setCoverURL("http://192.168.0.0/16/editingproject/cover/projectid.jpg");

        UpdateEditingProjectResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response != null){
                // Request ID
                System.out.println("RequestId:" + response.getRequestId());
            }
        } catch (ServerException e){
            System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (ClientException e){
            System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
    }

    /**
     * This Sample shows how to merge two videos
     */
    public static String buildTimeline(){
        JSONObject timeline = new JSONObject();

        // Video Track
        JSONArray videoTracks = new JSONArray();
        JSONObject videoTrack = new JSONObject();

        // Video Track
        JSONArray videoTrackClips = new JSONArray();
        JSONObject videoTrackClip1 = new JSONObject();
        videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe****");
        videoTrackClips.add(videoTrackClip1);
        JSONObject videoTrackClip2 = new JSONObject();
        videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe****");
        videoTrackClips.add(videoTrackClip2);

        videoTrack.put("VideoTrackClips", videoTrackClips);
        videoTracks.add(videoTrack);

        timeline.put("VideoTracks", videoTracks);

        return timeline.toString();
    }

删除云剪辑工程

调用DeleteEditingProject接口,完成删除云剪辑工程功能。

阿里云OpenAPI门户地址:DeleteEditingProject

获取单个云剪辑工程

调用GetEditingProject接口,完成获取单个云剪辑工程功能。

阿里云OpenAPI门户地址:GetEditingProject

搜索云剪辑工程

调用SearchEditingProject接口,完成搜索云剪辑工程功能。

阿里云OpenAPI门户地址:SearchEditingProject

设置云剪辑工程素材

调用SetEditingProjectMaterials接口,完成设置云剪辑工程素材功能。

阿里云OpenAPI门户地址:SetEditingProjectMaterials

获取云剪辑工程素材

调用GetEditingProjectMaterials接口,完成获取云剪辑工程素材功能。

阿里云OpenAPI门户地址:GetEditingProjectMaterials

相关文档

  • 本页导读 (1)