All Products
Search
Document Center

ApsaraVideo VOD:Video editing

Last Updated:Aug 22, 2023

This topic provides examples on how to use the API operations of the video editing module. The API operations are encapsulated in ApsaraVideo VOD SDK for Java. You can call the API operations to create, modify, and delete online editing projects. You can also query details of an online editing project and submit a video production job.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

Initialize a client

Before you use the SDK, initialize a client. For more information, see Initialization.

Submit a video production job based on a timeline

You can call the ProduceEditingProjectVideo operation to submit a video production job based on a timeline.

In most cases, a timeline is used to produce videos.

Click ProduceEditingProjectVideo to learn more about this API operation.

Sample code:

Note

For more examples on how to produce videos based on timelines, see the "Examples" section of the Overview topic.

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

   /**
    * Obtain the AccessKey information.
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and 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 production process can generate media source files. You can transcode the generated source files. Specify the TemplateGroupId parameter if you want to transcode the generated source files.
         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();
    }

Submit a video production job based on an online editing project

You can call the ProduceEditingProjectVideo operation to submit a video production job based on an online editing project.

If you have high management requirements for online editing projects, use this method for video production.

Click ProduceEditingProjectVideo to learn more about this API operation.

Sample code:

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

   /**
    * Obtain the AccessKey information.
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and 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 production process can generate media source files. You can transcode the generated source files. Specify the TemplateGroupId parameter if you want to transcode the generated source files.
         1. Not required 
         2. Use default transcode template group id when empty
         */
        produceConfig.put("TemplateGroupId", null);
        return produceConfig.toString();
    }

Create an online editing project

You can call the AddEditingProject operation to create an online editing project.

Click AddEditingProjectVideo to learn more about this API operation.

Sample code:

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

   /**
    * Obtain the AccessKey information.
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and 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();
    }

Modify an online editing project

You can call the UpdateEditingProject operation to modify an online editing project.

Click UpdateEditingProjectVideo to learn more about this API operation.

Sample code:

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

   /**
    * Obtain the AccessKey information.
    */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and 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();
    }

Delete an online editing project

You can call the DeleteEditingProject operation to delete an online editing project.

Click DeleteEditingProjectVideo to learn more about this API operation.

Query details of an online editing project

You can call the GetEditingProject operation to query details of an online editing project.

Click GetEditingProjectVideo to learn more about this API operation.

Query online editing projects

You can call the SearchEditingProject operation to query online editing projects.

Click SearchEditingProjectVideo to learn more about this API operation.

Set materials for an online editing project

You can call the SetEditingProjectMaterials operation to set materials for an online editing project.

Click SetEditingProjectMaterials to learn more about this API operation.

Query materials in an online editing project

You can call the GetEditingProjectMaterials operation to query the materials in an online editing project.

Click GetEditingProjectMaterials to learn more about this API operation.