A regular template is created based on the timeline of a video editing project and contains multiple materials that are merged in multi-layer mode. A regular template can be used to implement effects such as converting images and text into videos, generating photo albums, designing intro and outro videos, and applying default watermarks. This topic describes how to create and use a regular template.
Create a regular template
Use the IMS console
Log on to the Intelligent Media Services (IMS) console.
In the left-side navigation pane, choose
.On the Video Editing Projects tab, find the video editing project that you want to edit and click Edit in the Actions column. On the page that appears, edit and save the video editing project. Then, click Generate Template to create a regular template. You can also click Export Template in the Actions column on the Video Editing Projects tab to create a regular template.
For more information about how to edit a regular template, see Guidelines for editing a regular template.
Call an API operation
Customize the Config object of a regular template.
The Config object of a regular template is encapsulated based on the Timeline object of an online editing project. The Config object of a custom template provides more flexible features. If you have special requirements, we recommend that you understand the structure of a Config object and configure a custom template. For more information, see Config object of a regular template.
The following sample code shows the Config object of a video merging template. For more information about Config object examples, see Basic template configurations.
{ "VideoTracks": [ { "VideoTrackClips": [ { "Sys_Type" : "ArrayItems", "Sys_ArrayObject" : "$VideoArray", "Sys_Template" : { "MediaId" : "$MediaId" } } ] } ] }
Create a regular template.
Call the AddTemplate operation to create a template and specify the Config object of the template.
AddTemplateRequest request = new AddTemplateRequest(); request.setType("Timeline"); // If you want to create a regular template, set the Type parameter to Timeline. request.setName("Test a regular template"); request.setConfig("{\"VideoTracks\":[{\"VideoTrackClips\":[{\"Sys_Type\":\"ArrayItems\",\"Sys_ArrayObject\":\"$VideoArray\",\"Sys_Template\":{\"MediaId\":\"$MediaId\"}}]}]}"); AddTemplateResponse response = iceClient.addTemplate(request); System.out.println("templateId : " + response.getBody().getTemplate().getTemplateId());
After the template is created, the ID of the template is returned. The template ID can be used for a production task.
Use a regular template
Use the IMS console
Log on to the IMS console.
In the left-side navigation pane, choose
.Use a regular template to perform online editing.
Click the Common Templates tab.
Find the template that you want to use and click Use Template in the Actions column.
In the dialog box that appears, enter a project name and click OK. In the message that appears, click OK or Cancel to determine whether to edit the project now. For more information about how to edit a regular editing project, see the "Video editing" section of the Online editing topic.
Call an API operation
Obtain the template information.
Use the IMS console
If the template is created in the IMS console, find the template on the Common Templates tab of the Template Factory page and click Edit Template in the Actions column. On the page that appears, use the Dynamic material management tab to generate the
ClipsParam
parameter.The value of the ClipsParam parameter consists of keys and the corresponding values. The Named the ID parameter is a key, and the text or media asset ID to be replaced is a value. The following sample code shows the value of the generated
ClipsParam
parameter:{ "1": "The replaced subtitles.", "2": "****20b48fb04483915d4f2cd8ac****", "3": "****20b48fb04483915d4f2cd8ac****", "4": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video1.mp4", "5": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video2.mp4" }
Call an API operation
Call the GetTemplate operation to obtain the template information and specify the template ID that is obtained in Step 2 of the "Call an API operation" section in this topic.
The following sample code shows the value of the
ClipsParam
parameter in the response:{"1":"text","2":"mediaId","3":"mediaId","4":"mediaId","5":"mediaId"}
NoteYou can also use a preset template. The methods of using a preset template are similar to the preceding methods of using a user-created template and are not described in this topic. For more information about preset templates, see Regular templates in the public template library.
Configure the
text
andmediaId
fields in theClipsParam
parameter in the preceding sample code based on your business requirements.{ "1": "The replaced subtitles.", "2": "****20b48fb04483915d4f2cd8ac****", "3": "****20b48fb04483915d4f2cd8ac****", "4": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video1.mp4", "5": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video2.mp4" }
NoteClipsParam
is a production service parameter. You can replace the text field with the specified text and replace the mediaId field with the specified media asset ID or the Object Storage Service (OSS) storage address of a video or an image based on your business requirements. You can create a video that contains text and multimedia elements by configuring both the text and mediaId fields in a production service request.Call the production service.
Call the SubmitMediaProducingJob operation to submit an editing and production task and specify the
TemplateId
andClipsParam
parameters.SubmitMediaProducingJobRequest request = new SubmitMediaProducingJobRequest(); request.setTemplateId("Your TemplateId"); request.setClipsParam("{\"1\":\"The replaced subtitles.\",\"2\":\"****20b48fb04483915d4f2cd8ac****\",\"3\":\"****20b48fb04483915d4f2cd8ac****\",\"4\":\"****20b48fb04483915d4f2cd8ac****\",\"5\":\"****20b48fb04483915d4f2cd8ac****\"}"); request.setOutputMediaConfig("{\"MediaURL\":\"http://your-bucket.oss-cn-shanghai.aliyuncs.com/object.mp4\"}"); SubmitMediaProducingJobResponse response = iceClient.submitMediaProducingJob(request); System.out.println("jobid : " + response.getBody().getJobId());