Video editing
ApsaraVideo VOD online editing combines audio, video, and text materials into new videos. The following Java SDK examples show how to create and manage online editing projects and submit video production jobs.
API call notes
In this topic, an AccessKey pair is used to initialize a client instance in the code examples.
For detailed descriptions of the API parameters and returned fields, visit the Alibaba Cloud OpenAPI Portal and view the Documentation tab for each API.
This topic provides code examples for only some complex APIs. To obtain SDK code examples for other APIs, go to the Alibaba Cloud OpenAPI Portal. On the Parameter Settings tab on the left, enter the required parameter information and initiate the call. Then, on the SDK Sample tab on the right, select the SDK version and target language to view and download the sample code.
The API calls in this topic use SDK V1.0 as an example. To obtain SDK examples for V2.0, specify the corresponding SDK version when you obtain the sample code from the Alibaba Cloud OpenAPI Portal.

Initialize a client
Before using the SDK, initialize a client as described in Initialization.
Submit a video production job based on a timeline
Call ProduceEditingProjectVideo to submit a video production job based on a timeline.
This approach suits most video production scenarios.
OpenAPI Explorer: ProduceEditingProjectVideo.
Sample code:
Additional timeline editing and composition examples: Video Editing - Usage Examples.
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
Call ProduceEditingProjectVideo to submit a video production job based on an online editing project.
Use this approach when you need fine-grained control over online editing projects.
OpenAPI Explorer: ProduceEditingProjectVideo.
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
Call AddEditingProject to create an online editing project.
OpenAPI Explorer: AddEditingProject.
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
Call UpdateEditingProject to modify an online editing project.
OpenAPI Explorer: UpdateEditingProject.
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
Call DeleteEditingProject to delete an online editing project.
OpenAPI Explorer: DeleteEditingProject.
Query details of an online editing project
Call GetEditingProject to query details of an online editing project.
OpenAPI Explorer: or GetEditingProject.
Query online editing projects
Call SearchEditingProject to search for online editing projects.
OpenAPI Explorer: or SearchEditingProject.
Set materials for an online editing project
Call SetEditingProjectMaterials to set materials for an online editing project.
OpenAPI Explorer: SetEditingProjectMaterials.
Query materials in an online editing project
Call GetEditingProjectMaterials to query materials in an online editing project.
OpenAPI Explorer: GetEditingProjectMaterials.