All Products
Search
Document Center

Intelligent Media Services:Create and use advanced templates

Last Updated:Dec 05, 2024

Intelligent production allows you to use advanced templates for video editing to achieve advanced effects and complex animation styles. This topic describes how to create and use advanced templates.

Create an advanced template

Use the IMS console

  1. Use VE Exporter to export the AE project as a template file in the ZIP format.

  2. Upload the template file to the Template Factory.

Call an API operation

Call the AddTemplate operation to create a template and specify the OSS URL of the advanced template.

AddTemplateRequest request = new AddTemplateRequest();
request.setType("VETemplate");
request.setName("Advanced template test");
request.setConfig("{\"oss_url\":\"http://your-bucket.oss-cn-shanghai.aliyuncs.com/object.zip\"}");
AddTemplateResponse response = iceClient.addTemplate(request);
System.out.println("templateId : " + response.getBody().getTemplate().getTemplateId());
Note

The value of oss_url in this example is only for reference. You must specify the actual OSS URL.

Use advanced templates

Use the IMS console

For more information about how to use advanced templates to edit videos, see Use advanced templates to edit videos.

Call an API operation

  1. Obtain the template information.

    Call the GetTemplate operation to obtain the template information. Specify the template ID in the TemplateId parameter.

    GetTemplateRequest request = new GetTemplateRequest();
    request.setTemplateId("****20b48fb04483915d4f2cd8ac****");
    GetTemplateResponse response = iceClient.getTemplate(request);
    GetTemplateResponseBody.GetTemplateResponseBodyTemplate template = response.getBody().getTemplate();
    System.out.println("templateId : " + template.getTemplateId());
    System.out.println("clipsParam : " + template.getClipsParam());

    The following output is returned:

    {
        "RequestId":"******11-DB8D-4A9A-875B-275798******",
        "Template":{
            "TemplateId":"****20b48fb04483915d4f2cd8ac****",
            "Name":"Advanced template test",
            "Type":"VETemplate",
            "Status":"Available",
            "ModifiedSource":"OpenAPI",
            "CreateSource":"OpenAPI",
            "Config":"{\"oss_url\":\"http://your-bucket.oss-cn-shanghai.aliyuncs.com/object.zip\"}",
            "ClipsParam":"{\"Text7\":\"text\",\"Text6\":\"text\",\"Text5\":\"text\",\"Text4\":\"text\",\"Text3\":\"text\",\"Text2\":\"text\",\"Text1\":\"text\",\"Text0\":\"text\",\"Media3\":\"mediaId\",\"Media2\":\"mediaId\",\"Media1\":\"mediaId\",\"Media0\":\"mediaId\"}",
            "PreviewMedia":"",
            "CoverURL":""
        }
    }
    Note

    You can also use built-in templates. The method of using built-in templates is similar to the method described in the preceding section. For more information about built-in templates, see Advanced templates.

  2. Replace text and mediaId of the ClipsParam parameter with the actual values.

    {
        "Text0":"Subtitle 0",
        "Text1":"Subtitle 1",
        "Text2":"Subtitle 2",
        "Text3":"Subtitle 3",
        "Text4":"Subtitle 4",
        "Text5":"Subtitle 5",
        "Text6":"Subtitle 6",
        "Text7":"Subtitle 7",
        "Media0":"****20b48fb04483915d4f2cd8ac****",
        "Media1":"****20b48fb04483915d4f2cd8ac****",
        "Media2":"****20b48fb04483915d4f2cd8ac****",
        "Media3":"****20b48fb04483915d4f2cd8ac****"
    }
    Note
    • ClipsParam is a parameter for the production service. You can replace text with subtitles and mediaId with the ID or OSS URL of a media asset, including a video or an image. You can use subtitles and media assets together.

    • If only some fields are specified in the ClipsParam parameter, the subtitles that are not specified are left empty by default, and the default media assets of the template are used.

    • You can set a font for subtitles and an adaptation mode for videos and images. For more information, see Extended features.

  3. Call the production service.

    Call the SubmitMediaProducingJob operation to submit an editing and production job. Specify the TemplateId and ClipsParam parameters.

    SubmitMediaProducingJobRequest request = new SubmitMediaProducingJobRequest();
    request.setTemplateId("****20b48fb04483915d4f2cd8ac****");
    request.setClipsParam("{\"Text7\":\" Subtitle 7\",\"Text6\":\" Subtitle 6\",\"Text5\":\" Subtitle 5\",\"Text4\":\" Subtitle 4\",\"Text3\":\" Subtitle 3\",\"Text2\":" Subtitle 2 "," Text1 ":" Subtitle 1 "," Text0 ":" Subtitle 0 "," Media3 ":"****20b48fb04483915d4f2cd8ac**** "," Media2 ":"****20b48fb04483915d4f2cd8ac**** "," Media1 ":"****20******** "," Media0 ":"****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());

Extended features

Set the adaptation mode of videos and images

Use the .adapt_type field to set the scaling mode for videos and images. Valid values:

  • 0: The material is scaled.

  • 1: The material keeps its aspect ratio and fills the given dimension in the center.

  • 2: The material keeps its aspect ratio, but is scaled to fit within the given dimension in the center.

  • 3: The material is scaled to fill the given dimension, regardless of the aspect ratio.

{
    "Text7":"Subtitle 7",
    "Text6":"Subtitle 6",
    "Text5":"Subtitle 5",
    "Text4":"Subtitle 4",
    "Text3":"Subtitle 3",
    "Text2":"Subtitle 2",
    "Text1":"Subtitle 1",
    "Text0":"Subtitle 0",
    "Media3":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object01.jpg",
    "Media2":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object02.jpg",
    "Media1":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object03.jpg",
    "Media0":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object04.jpg",
    "Media3.adapt_type":0,
    "Media2.adapt_type":1,
    "Media1.adapt_type":2,
    "Media0.adapt_type":3
}

Modify the font of subtitles

Use the .font_file field to set the font of subtitles. You can also set the OSS URL to use custom fonts. For more information about fonts.

{
    "Text7.font_file":"SimSun",
    "Text6.font_file":"Yuanti",
    "Text5.font_file":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-font1.ttf",
    "Text4.font_file":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-font2.ttf",
    "Text7":"Subtitle 7",
    "Text6":"Subtitle 6",
    "Text5":"Subtitle 5",
    "Text4":"Subtitle 4",
    "Text3":"Subtitle 3",
    "Text2":"Subtitle 2",
    "Text1":"Subtitle 1",
    "Text0":"Subtitle 0",
    "Media3":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object01.jpg",
    "Media2":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object02.jpg",
    "Media1":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object03.jpg",
    "Media0":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object04.jpg"
}

Other settings

The ClipsParam parameter also supports the following settings to edit materials:

{
  // Media asset
  "Media1": "a8f5f167f44f4964e6c998dee827110c",
  "Media1.loop": 1, // This setting applies to videos and GIFs. 0: uses the default loop logic of the engine. 1: loops the material. 2: does not loop the material.
  "Media1.volume": 0.5, //This setting applies to videos. You must specify a value greater than or equal to 0. Valid values: 0 to 1. Default value: 0.
  "Media1.adapt_type": 0, // The adaptation mode. 0: The material is not scaled. 1: The material keeps its aspect ratio and fills the given dimension in the center. 2: The material keeps its aspect ratio, but is scaled to fit within the given dimension in the center. 3: The material is scaled to fill the given dimension, regardless of the aspect ratio. 4: uses the matrix specified by the transform field. Default value: 1.
  "Media1.transform": [a,c,e,b,d,f], //The row matrix in the [scale, skewX, transX, skewY, scaleY, transY] format. The matrix is the local coordinate system of the original image. A unit matrix is used by default.
  "Media1.clip_start": 0.0, // Optional. The start time of video cropping. The value of clip_end must be greater than the value of clip_start.
  "Media1.clip_end": 10.0, // The end time of video cropping. A value greater than 0 indicates that video cropping is required. A value less than or equal to 0 indicates that video cropping is not required at the end of the video.
  
  // Subtitles
  "Text1":"Test subtitles",
  "Text1.adapt": true, // Specifies whether to enable text adaptation. This parameter is valid only for text of the text box type. By default, the adaptation method in the template is used.
  "Text1.fill": "#FFFFFF", // The fill color of the text.
  "Text1.stroke": "#FFFFFF", //The color of the text outline.
  "Text1.stroke_width": 0.0, // The width of the text outline.
  "Text1.stroke_over_fill": false, // Specifies whether the outline color is above the fill color.
  "Text1.size": 10, // The text size in pixels.
  "Text1.font_file": "SimSun" // The name of the font family.
}