ApsaraVideo VOD çevrimiçi düzenleme özelliği; ses, video ve metin materyallerini birleştirerek yeni videolar oluşturur. Aşağıdaki Java SDK örnekleri, çevrimiçi düzenleme projelerini oluşturma ve yönetme ile video prodüksiyon işlerini gönderme işlemlerini gösterir.
Kullanım notları
Bu konudaki tüm örnekler, istemci örneğini başlatmak için bir AccessKey çifti kullanır.
İstek ve yanıt parametrelerinin ayrıntıları için Alibaba Cloud OpenAPI Explorer adresini ziyaret edin ve API Documentations sekmesini açın.
Diğer API işlemleri için SDK örneklerini görüntülemek üzere Alibaba Cloud OpenAPI Explorer adresine gidin. Parameters sekmesinde parametreleri belirtin ve çağrıyı başlatın. Ardından kodu görüntülemek ve indirmek için SDK Sample Code sekmesinden SDK sürümünü ve dili seçin.
Bu konudaki örnekler SDK V1.0 kullanır. V2.0 örnekleri için OpenAPI Explorer'da doğru SDK sürümünü seçin.
İstemciyi başlatma
SDK'yı kullanmadan önce, Başlatma bölümünde açıklandığı gibi bir istemci başlatın.
Zaman çizelgesine dayalı video prodüksiyon işi gönderme
Zaman çizelgesine dayalı bir video prodüksiyon işi göndermek için ProduceEditingProjectVideo API'sini çağırın.
Bu yaklaşım çoğu video prodüksiyon senaryosu için uygundur.
OpenAPI Explorer: ProduceEditingProjectVideo.
Örnek kod:
Ek zaman çizelgesi düzenleme ve birleştirme örnekleri için: Video Düzenleme - Kullanım Örnekleri.
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();
}
Çevrimiçi düzenleme projesine dayalı video prodüksiyon işi gönderme
Çevrimiçi bir düzenleme projesine dayalı video prodüksiyon işi göndermek için ProduceEditingProjectVideo API'sini çağırın.
Çevrimiçi düzenleme projeleri üzerinde hassas kontrol gerektiğinde bu yaklaşımı kullanın.
OpenAPI Explorer: ProduceEditingProjectVideo.
Örnek kod:
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();
}
Çevrimiçi düzenleme projesi oluşturma
Bir çevrimiçi düzenleme projesi oluşturmak için AddEditingProject API'sini çağırın.
OpenAPI Explorer: AddEditingProject.
Örnek kod:
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();
}
Çevrimiçi düzenleme projesini değiştirme
Bir çevrimiçi düzenleme projesini değiştirmek için UpdateEditingProject API'sini çağırın.
OpenAPI Explorer: UpdateEditingProject.
Örnek kod:
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();
}
Çevrimiçi düzenleme projesini silme
Bir çevrimiçi düzenleme projesini silmek için DeleteEditingProject API'sini çağırın.
OpenAPI Explorer: DeleteEditingProject.
Çevrimiçi düzenleme projesinin ayrıntılarını sorgulama
Bir çevrimiçi düzenleme projesinin ayrıntılarını sorgulamak için GetEditingProject API'sini çağırın.
OpenAPI Explorer: veya GetEditingProject.
Çevrimiçi düzenleme projelerini sorgulama
Çevrimiçi düzenleme projelerini aramak için SearchEditingProject API'sini çağırın.
OpenAPI Explorer: veya SearchEditingProject.
Çevrimiçi düzenleme projesi için materyal ayarlama
Bir çevrimiçi düzenleme projesi için materyal ayarlamak amacıyla SetEditingProjectMaterials API'sini çağırın.
OpenAPI Explorer: SetEditingProjectMaterials.
Çevrimiçi düzenleme projesindeki materyalleri sorgulama
Bir çevrimiçi düzenleme projesindeki materyalleri sorgulamak için GetEditingProjectMaterials API'sini çağırın.
OpenAPI Explorer: GetEditingProjectMaterials.