Tutorial: Create a face compilation video

Updated at:
Copy as MD

This tutorial walks you through creating face compilation videos with Intelligent Media Services (IMS). You will use face search to locate clips of a specific person, then produce a compilation using Script-to-Video, Timeline editing, or advanced templates.

Background

A face compilation highlights one person's appearances across multiple video clips. This format is common in film production, news reporting, and social media. IMS automates the process by combining face search with video editing capabilities.

Use cases

Use case 1: Athlete highlight reels

Sports event organizers create highlight videos that capture key moments such as sprints or overtakes. These serve event promotion, recaps, and athlete branding.

Use case 2: Personal highlight reels for visitors

Amusement parks create personalized highlight reels capturing visitors on rides. These compilations serve as souvenirs or social media content.

Use case 3: Behind-the-scenes videos for events

Wedding videographers compile behind-the-scenes and travel footage into a curated highlight of the couple's story.

Use case 4: Fan face compilations

Concert organizers compile audience reactions to display on screens during the event or share on social media.

Other applications include personal memoirs, family videos, tourism promotions, and corporate event recaps.

Procedure

Prerequisites

Install the IMS server-side SDK. See Preparations. Skip this step if the SDK is already installed.

Step 1: Find video clips using face search

Use IMS face search to find video clips containing a specific person. See Search for faces in a large volume of media assets.

Step 2: Edit the video clips

The following sections describe three methods for creating a face compilation video, including features, procedures, and SDK examples.

Method 1: Create a video using Script-to-Video

Features
  • Convenient and efficient: Automates face compilation creation. Generate multiple videos in batch with simple configurations.

  • Easy to use: Create high-quality videos with one click, no editing experience required.

Implement using the SDK

View the code sample

package com.example;

import java.util.*;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.Config;

/**
 *  You must add the following Maven dependencies:
 *   <dependency>
 *      <groupId>com.aliyun</groupId>
 *      <artifactId>ice20201109</artifactId>
 *      <version>2.3.0</version>
 *  </dependency>
 *  <dependency>
 *      <groupId>com.alibaba</groupId>
 *      <artifactId>fastjson</artifactId>
 *      <version>1.2.9</version>
 *  </dependency>
 */
public class SubmitFaceEditingJobService {

    static final String regionId = "cn-shanghai";
    static final String bucket = "<your-bucket>";

    /*** Submit a one-click video creation job for a face compilation based on face search results. ****/
    public static void submitBatchEditingJob(String mediaId, SearchMediaClipByFaceResponse response) throws Exception {

        Client iceClient = initClient();

        JSONArray intervals = buildIntervals(response);
        JSONObject editingTimeline = buildEditingTimeline(mediaId, intervals);

        String openingMediaId = "icepublic-9a2df29956582a68a59e244a5915228c";
        String endingMediaId = "icepublic-1790626066bee650ac93bd12622a921c";
        String mainGroupName = "main";
        String openingGroupName = "opening";
        String endingGroupName = "ending";

        JSONObject inputConfig = buildInputConfig(mediaId, mainGroupName, openingMediaId, openingGroupName, endingMediaId, endingGroupName);
        JSONObject editingConfig = buildEditingConfig(mediaId, mainGroupName, intervals, openingMediaId, openingGroupName, endingMediaId, endingGroupName);
        JSONObject outputConfig = new JSONObject();
        outputConfig.put("MediaURL", "https://ice-auto-test.oss-cn-shanghai.aliyuncs.com/testBatch/" + System.currentTimeMillis() + "{index}.mp4");
        outputConfig.put("Width", 1280);
        outputConfig.put("Height", 720);
        outputConfig.put("FixedDuration", 18);
        outputConfig.put("Count", 2);

        SubmitBatchMediaProducingJobRequest request = new SubmitBatchMediaProducingJobRequest();
        request.setInputConfig(inputConfig.toJSONString());
        request.setEditingConfig(editingConfig.toJSONString());
        request.setOutputConfig(outputConfig.toJSONString());

        SubmitBatchMediaProducingJobResponse response = iceClient.submitBatchMediaProducingJob(request);
        System.out.println("JobId: " + response.getBody().getJobId());
    }

    public Client initClient() throws Exception {
        // An Alibaba Cloud account's AccessKey grants full access to all APIs. We recommend using a RAM user for API calls and daily operations.
        // This example shows how to store your AccessKey ID and AccessKey Secret in environment variables. For more information, see https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-access-credentials.
        com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();

        Config config = new Config();
        config.setCredential(credentialClient);

        // If you need to hard-code your AccessKey ID and AccessKey Secret, use the following code. However, we strongly recommend that you do not store your AccessKey ID and AccessKey Secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
        // config.accessKeyId = "
Implement using the console

To create videos in the console, skip Step 1 and follow these steps.

Step 1: In the left-side navigation pane of the console, click Intelligent Batch Video Production. On the Script-to-Video tab, click Create Task. Select a generation mode. Both Global Scripts and Segmented Scripts mode are supported. This example uses Segmented Scripts mode.

Step 2: In the Script Node Configuration section, click Add Material. In the Add Material panel that appears, select face search and upload a face image to find matching materials

Step 3: In the results, click View for a specific result to see the matched video clips. Then, click Import Matched Clips and OK. The matched materials are then added to the script node.

Step 4: To adjust the video clips matched by face search, hover over the material and click the settings icon. In the dialog box that appears, you can adjust the in and out points in the Trimming section. Skip this step if no adjustments are needed.

Follow the standard Script-to-Video procedure to configure the title, background music, stickers and logos, and synthesis settings, then submit the task.

Method 2: Create a video using Timeline editing

Features
  • Customizable video content: Control every edit point, effect, transition, and audio track. Combine and adjust materials to produce unique videos.

  • High flexibility: Adjust the editing plan, clip order, effects, and audio at any time to meet diverse creative needs.

Steps

Use the face search results from Step 1 to edit the face compilation video through the Timeline configuration of SubmitMediaProducingJob. See the SDK call example section. For advanced editing such as effects, transitions, or audio processing, see Basic parameters for video editing and Timeline configuration.

SDK call example

View the code sample

View a sample Timeline parameter

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 54.106018,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 56.126015
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 271.47302,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 277.393
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 326.03903,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 331.959
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 372.20602,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 375.126
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 383.03903,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 388.959
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 581.339,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 587.25903
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****",
          "In": 602.339,
          "Effects": [
            {
              "Type": "Volume",
              "Gain": 0
            }
          ],
          "Out": 607.293
        }
      ]
    }
  ],
  "AudioTracks": [
    {
      "AudioTrackClips": [
        {
          "LoopMode": true,
          "MediaId": "icepublic-0c4475c3936f3a8743850f2da942ceee"
        }
      ]
    }
  ]
}

Method 3: Use advanced templates

Features
  • Efficient and high-quality: Populate ready-made templates with your materials to quickly create videos. Design custom templates for a unique style.

  • Consistent video style: Templates ensure a professional style, helping even inexperienced users create appealing videos.

Steps

Use the face search results from Step 1 with an advanced template and the ClipsParam parameter of SubmitMediaProducingJob to create a face compilation video. See the SDK call example section. This example uses the public template IceSys_VETemplate_s100241 with clips from face search results. To use your own template, see User guide: How to use an advanced template.

SDK call example

View the code sample

package com.example;

import java.util.*;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.Config;

/**
 *  You must add the following Maven dependencies:
 *   <dependency>
 *      <groupId>com.aliyun</groupId>
 *      <artifactId>ice20201109</artifactId>
 *      <version>2.3.0</version>
 *  </dependency>
 *  <dependency>
 *      <groupId>com.alibaba</groupId>
 *      <artifactId>fastjson</artifactId>
 *      <version>1.2.9</version>
 *  </dependency>
 */
public class SubmitFaceEditingJobService {

    static final String regionId = "cn-shanghai";
    static final String bucket = "<your-bucket>";

    /*** Submit a face compilation editing job based on face search results. ****/
    public static void submitEditingJob(String mediaId, SearchMediaClipByFaceResponse response) throws Exception {

        Client iceClient = initClient();
        JSONArray intervals = buildIntervals(response);

        // Submit an advanced template job. This example uses the public template IceSys_VETemplate_s100241 and configures video clips based on face search results.
        JSONObject clipParams = buildClipParams(mediaId, intervals);

        SubmitMediaProducingJobRequest request2 = new SubmitMediaProducingJobRequest();
        request2.setTemplateId("IceSys_VETemplate_s100241");
        request2.setClipsParam(clipParams.toJSONString());
        request2.setOutputMediaTarget("oss-object");
        outputConfig = new JSONObject();
        outputConfig.put("MediaURL",
                         "https://" + bucket + ".oss-" + regionId + "/testTemplate/" + System.currentTimeMillis() + ".mp4");
        request2.setOutputMediaConfig(outputConfig.toJSONString());

        SubmitMediaProducingJobResponse response2 = iceClient.submitMediaProducingJob(request2);
        System.out.println("JobId: " + response2.getBody().getJobId());
    }

    public Client initClient() throws Exception {
        // An Alibaba Cloud account's AccessKey grants full access to all APIs. We recommend using a RAM user for API calls and daily operations.
        // This example shows how to store your AccessKey ID and AccessKey Secret in environment variables. For more information, see https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-access-credentials.
        com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();

        Config config = new Config();
        config.setCredential(credentialClient);

        // If you need to hard-code your AccessKey ID and AccessKey Secret, use the following code. However, we strongly recommend that you do not store your AccessKey ID and AccessKey Secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
        // config.accessKeyId = "

View a sample clipParams parameter

{
	"Media0": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media0.clip_start": 54.066017,
	"Media1": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media1.clip_start": 67.33301,
	"Media2": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media2.clip_start": 271.47302,
	"Media3": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media3.clip_start": 326.03903,
	"Media4": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media4.clip_start": 372.20602,
	"Media5": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media5.clip_start": 383.03903,
	"Media6": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media6.clip_start": 581.339,
	"Media7": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media7.clip_start": 587.25903,
	"Media8": "b5a003f0cd3f71ed919fe7e7c45b****",
	"Media8.clip_start": 602.339
}

Examples

Video created using Timeline editing

This video is a face compilation of the athlete in the white jersey with the number 5.

Video created using an advanced template

The transitions and speed effects in the final video are from the template.

Video created using Script-to-Video (SDK)

This video is a face compilation of the athlete in the white jersey with the number 5.

Video created using Script-to-Video (console)

This video is a face compilation of the athlete in the white jersey with the number 17.

References