All Products
Search
Document Center

Video editing

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Produce videos based on a timeline

In most scenarios, you can use this method to produce videos. For more information about the request and response parameters, see ProduceEditingProjectVideo.

For more information about examples of producing videos based on a timeline, see Video editing: Examples.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
        // Constructs a timeline for producing videos.
        request.setTimeline(buildTimeline());
        // Specifies the metadata of the produced video.
        request.setMediaMetadata(buildMediaMetadata());
        // Specifies the production configuration.
        request.setProduceConfig(buildProduceConfig());

        ProduceEditingProjectVideoResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response ! = null){
                // The ID of the produced video.
                System.out.println("MediaId:" + response.getMediaId());
                // The GUID generated by Alibaba Cloud for the request.
                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();
        // Sets the title of the produced video.
        mediaMetadata.put("Title", "Title");
        // Sets the description of the produced video.
        mediaMetadata.put("Description", "Description");
        // Sets the user-defined thumbnail URL of the produced video.
        mediaMetadata.put("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
        // Sets the category ID of the produced video.
        mediaMetadata.put("CateId", null);
        // Sets the tags of the produced video.
        mediaMetadata.put("Tags", "Tag1,Tag2,Test");
        return mediaMetadata.toString();
    }

    public static String buildProduceConfig(){
        JSONObject produceConfig = new JSONObject();
        /*
         A mezzanine file is generated in the production process. You can transcode this mezzanine file to other formats. This process is similar to the transcoding process after a file is uploaded. The TemplateGroupId parameter indicates the transcoding template group ID to be used by the generated mezzanine file of the produced video for transcoding.
         1. This parameter is optional. 
         2. If you do not set this parameter, the default transcoding template group ID is used.
         */
        produceConfig.put("TemplateGroupId", null);
        return produceConfig.toString();
    }

    /**
     * The following example shows how to merge two videos.
     */
    public static String buildTimeline(){
        JSONObject timeline = new JSONObject();

        // Specifies video tracks.
        JSONArray videoTracks = new JSONArray();
        JSONObject videoTrack = new JSONObject();

        // Specifies video track clips.
        JSONArray videoTrackClips = new JSONArray();
        JSONObject videoTrackClip1 = new JSONObject();
        videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
        videoTrackClips.add(videoTrackClip1);
        JSONObject videoTrackClip2 = new JSONObject();
        videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
        videoTrackClips.add(videoTrackClip2);

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

        timeline.put("VideoTracks", videoTracks);

        return timeline.toString();
    }

Produce videos based on an online editing project

If online editing projects need to be managed with high requirements, you can use this method to produce videos. For more information about the request and response parameters, see ProduceEditingProjectVideo.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
        // Sets the ID of the online editing project.
        request.setProjectId("ProjectId");
        // Specifies the metadata of the produced video.
        request.setMediaMetadata(buildMediaMetadata());
        // Specifies the production configuration.
        request.setProduceConfig(buildProduceConfig());

        ProduceEditingProjectVideoResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response ! = null){
                // The ID of the produced video.
                System.out.println("MediaId:" + response.getMediaId());
                // The GUID generated by Alibaba Cloud for the request.
                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();
        // Sets the title of the produced video.
        mediaMetadata.put("Title", "Title");
        // Sets the description of the produced video.
        mediaMetadata.put("Description", "Description");
        // Sets the user-defined thumbnail URL of the produced video.
        mediaMetadata.put("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
        // Sets the category ID of the produced video.
        mediaMetadata.put("CateId", null);
        // Sets the tags of the produced video.
        mediaMetadata.put("Tags", "Tag1,Tag2,Test");
        return mediaMetadata.toString();
    }

    public static String buildProduceConfig(){
        JSONObject produceConfig = new JSONObject();
        /*
         A mezzanine file is generated in the production process. You can transcode this mezzanine file to other formats. This process is similar to the transcoding process after a file is uploaded. The TemplateGroupId parameter indicates the transcoding template group ID to be used by the generated mezzanine file of the produced video for transcoding.
         1. This parameter is optional. 
         2. If you do not set this parameter, the default transcoding template group ID is used.
         */
        produceConfig.put("TemplateGroupId", null);
        return produceConfig.toString();
    }

Create an online editing project

For more information about the request and response parameters, see AddEditingProject.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        AddEditingProjectRequest request = new AddEditingProjectRequest();
        // Constructs a timeline of the online editing project.
        request.setTimeline(buildTimeline());
        // Sets the title of the online editing project.
        request.setTitle("Editing Project Title");
        // Sets the description of the online editing project.
        request.setDescription("Editing Project Description");
        // Sets the thumbnail URL of the online editing project.
        request.setCoverURL("http://test.testvod123.com/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());
                }

                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }

    /**
     * The following example shows how to merge two videos.
     */
    public static String buildTimeline(){
        JSONObject timeline = new JSONObject();

        // Specifies video tracks.
        JSONArray videoTracks = new JSONArray();
        JSONObject videoTrack = new JSONObject();

        // Specifies video track clips.
        JSONArray videoTrackClips = new JSONArray();
        JSONObject videoTrackClip1 = new JSONObject();
        videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
        videoTrackClips.add(videoTrackClip1);
        JSONObject videoTrackClip2 = new JSONObject();
        videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
        videoTrackClips.add(videoTrackClip2);

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

        timeline.put("VideoTracks", videoTracks);

        return timeline.toString();
    }

Modify an online editing project

For more information about the request and response parameters, see UpdateEditingProject.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        UpdateEditingProjectRequest request = new UpdateEditingProjectRequest();
        request.setProjectId("YourProjectId");
        // Constructs a timeline of the online editing project.
        request.setTimeline(buildTimeline());
        // Sets the title of the online editing project.
        request.setTitle("Editing Project Title");
        // Sets the description of the online editing project.
        request.setDescription("Editing Project Description");
        // Sets the thumbnail URL of the online editing project.
        request.setCoverURL("http://test.testvod123.com/editingproject/cover/projectid.jpg");

        UpdateEditingProjectResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response ! = null){
                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }

    /**
     * The following example shows how to merge two videos.
     */
    public static String buildTimeline(){
        JSONObject timeline = new JSONObject();

        // Specifies video tracks.
        JSONArray videoTracks = new JSONArray();
        JSONObject videoTrack = new JSONObject();

        // Specifies video track clips.
        JSONArray videoTrackClips = new JSONArray();
        JSONObject videoTrackClip1 = new JSONObject();
        videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
        videoTrackClips.add(videoTrackClip1);
        JSONObject videoTrackClip2 = new JSONObject();
        videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
        videoTrackClips.add(videoTrackClip2);

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

        timeline.put("VideoTracks", videoTracks);

        return timeline.toString();
    }

Delete one or more online editing projects

For more information about the request and response parameters, see DeleteEditingProject.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        DeleteEditingProjectRequest request = new DeleteEditingProjectRequest();
        // Specifies the IDs of the online editing projects to be deleted. Separate multiple online editing project IDs with a comma (,).
        request.setProjectIds("projectid1,projectid2");
        DeleteEditingProjectResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response ! = null){
                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }

Obtain the information about an online editing project

For more information about the request and response parameters, see GetEditingProject.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

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

                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }

Search for online editing projects

For more information about the request and response parameters, see SearchEditingProject.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

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

                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }

Set materials to be edited for an online editing project

For more information about the request and response parameters, see SetEditingProjectMaterials.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        SetEditingProjectMaterialsRequest request = new SetEditingProjectMaterialsRequest();
        // Sets the ID of the online editing project.
        request.setProjectId("projectid");
        // Specifies the materials for the online editing project. Separate multiple material IDs with a comma (,).
        request.setMaterialIds("materialId1,materialId2");

        SetEditingProjectMaterialsResponse response = null;
        try {
            response = client.getAcsResponse(request);
            if (response ! = null){
                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }

Obtain a list of materials to be edited for an online editing project

For more information about the request and response parameters, see GetEditingProjectMaterials.

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

    /**
     * Call example
     */
    public static void main(String[] args) throws Exception {
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

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

                // The GUID generated by Alibaba Cloud for the request.
                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());
        }
    }