全部产品

视频剪辑

本篇文档提供了Java SDK视频剪辑模块相关功能的API调用示例。包含创建云剪辑工程、修改云剪辑工程、删除云剪辑工程、获取单个云剪辑工程、发起剪辑合成等。

初始化客户端

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

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

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

绝大多数场景下,使用这种方式即可合成视频。接口参数和返回字段请参见ProduceEditingProjectVideo。调用示例如下:

说明

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

import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoRequest;
import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        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接口,完成通过云剪辑工程-发起剪辑合成功能。

对云剪辑工程有较高管理需求的场景下,可以使用这种方式合成视频。接口参数和返回字段请参见ProduceEditingProjectVideo。调用示例如下:

import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoRequest;
import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        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接口,完成创建云剪辑工程功能。

接口参数和返回字段请参见AddEditingProject。调用示例如下:

import com.aliyuncs.vod.model.v20170321.AddEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.AddEditingProjectResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        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接口,完成修改云剪辑工程功能。

接口参数和返回字段请参见UpdateEditingProject。调用示例如下:

import com.aliyuncs.vod.model.v20170321.UpdateEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.UpdateEditingProjectResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        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接口,完成删除云剪辑工程功能。

接口参数和返回字段请参见DeleteEditingProject。调用示例如下:

import com.aliyuncs.vod.model.v20170321.DeleteEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.DeleteEditingProjectResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        DeleteEditingProjectRequest request = new DeleteEditingProjectRequest();
        // Use comma to split Multi Editing Project IDs
        request.setProjectIds("projectid1,projectid2");
        DeleteEditingProjectResponse 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());
        }
    }

获取单个云剪辑工程

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

接口参数和返回字段请参见GetEditingProject。调用示例如下:

import com.aliyuncs.vod.model.v20170321.GetEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.GetEditingProjectResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        GetEditingProjectRequest request = new GetEditingProjectRequest();
        request.setProjectId("projectId");

        GetEditingProjectResponse 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 Timeline:" + response.getProject().getTimeline());
                    System.out.println("Editing Project Title:" + response.getProject().getTitle());
                    System.out.println("Editing Project Description:" + response.getProject().getDescription());
                    System.out.println("Editing Project Cover URL:" + response.getProject().getCoverURL());
                    System.out.println("Editing Project Create Time:" + response.getProject().getCreationTime());
                    System.out.println("Editing Project Last Modified Time:" + response.getProject().getModifiedTime());
                    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());
        }
    }

搜索云剪辑工程

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

接口参数和返回字段请参见SearchEditingProject。调用示例如下:

import com.aliyuncs.vod.model.v20170321.SearchEditingProjectRequest;
import com.aliyuncs.vod.model.v20170321.SearchEditingProjectResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        SearchEditingProjectRequest request = new SearchEditingProjectRequest();
        request.setTitle("Title Keywords");
        request.setStartTime("2017-01-11T12:00:00Z");
        request.setEndTime("2017-01-12T12:00:00Z");
        request.setPageSize(10);
        request.setPageNo(1);

        SearchEditingProjectResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response != null){
                if (response.getProjectList() != null && response.getProjectList().size() > 0){
                    System.out.println("Total Size:" + response.getProjectList().size());
                    for (int i=0; i<response.getProjectList().size(); i++){
                        System.out.println("No " + i + " Editing Project");

                        SearchEditingProjectResponse.Project editingProject = response.getProjectList().get(i);
                        System.out.println("Editing Project ID:" + editingProject.getProjectId());
                        System.out.println("Editing Project Title:" + editingProject.getTitle());
                        System.out.println("Editing Project Description:" + editingProject.getDescription());
                        System.out.println("Editing Project Cover URL:" + editingProject.getCoverURL());
                        System.out.println("Editing Project Create Time:" + editingProject.getCreationTime());
                        System.out.println("Editing Project Last Modified Time:" + editingProject.getModifiedTime());
                        System.out.println("Editing Project Status:" + editingProject.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());
        }
    }

设置云剪辑工程素材

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

接口参数和返回字段请参见SetEditingProjectMaterials。调用示例如下:

import com.aliyuncs.vod.model.v20170321.SetEditingProjectMaterialsRequest;
import com.aliyuncs.vod.model.v20170321.SetEditingProjectMaterialsResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<您的AccessKeySecret>");

        SetEditingProjectMaterialsRequest request = new SetEditingProjectMaterialsRequest();
        // Editing Project ID
        request.setProjectId("projectid");
        // Set Editing Project Material IDs, use comma to split
        request.setMaterialIds("materialId1,materialId2");

        SetEditingProjectMaterialsResponse 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());
        }
    }

获取云剪辑工程素材

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

接口参数和返回字段请参见GetEditingProjectMaterials。调用示例如下:

import com.aliyuncs.vod.model.v20170321.GetEditingProjectMaterialsRequest;
import com.aliyuncs.vod.model.v20170321.GetEditingProjectMaterialsResponse;

    /**
     * Sample Code
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");

        GetEditingProjectMaterialsRequest request = new GetEditingProjectMaterialsRequest();
        request.setProjectId("projectid");
        request.setType("video");

        GetEditingProjectMaterialsResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response != null){
                if (response.getMaterialList() != null && response.getMaterialList().size() > 0){
                    for (int i=0; i<response.getMaterialList().size(); i++){
                        System.out.println("No " + i + " Material");

                        GetEditingProjectMaterialsResponse.Material material = response.getMaterialList().get(i);
                        System.out.println("Editing Project Material ID:" + material.getMaterialId());
                        System.out.println("Editing Project Material Title:" + material.getTitle());
                        System.out.println("Editing Project Material Category ID:" + material.getCateId());
                        System.out.println("Editing Project Material Category Name:" + material.getCateName());
                        System.out.println("Editing Project Material Tags:" + material.getTags());
                        System.out.println("Editing Project Material Cover URL:" + material.getCoverURL());
                        System.out.println("Editing Project Material Create Time:" + material.getCreationTime());
                        System.out.println("Editing Project Material Last Modified Time:" + material.getModifiedTime());
                    }
                }

                // 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());
        }
    }