Best practices for AiMiaoBi video mixing

Updated at:

This document describes how to use code to call the AiMiaoBi video mixing feature.

Pain points of traditional video editing

Traditional video editing relies heavily on professional software. This software has a steep learning curve and complex workflows. It requires manual work for tasks such as selecting assets, editing clips, adding transitions, and adding captions. This process is time-consuming and labor-intensive. Traditional methods also make batch processing and automated generation difficult. This is especially inefficient and costly when you need to produce many short videos.

Advantages of video mixing

Video mixing uses AI technology to solve these problems. You do not need to install complex software. It supports one-click automatic editing. The feature can intelligently identify exciting clips, automatically add background music, generate captions, and optimize the video's rhythm. You can also use templates to quickly produce high-quality videos in batches. This process greatly lowers the barrier to video editing and significantly improves content production efficiency. It meets the needs of businesses and individuals for efficient and intelligent video production in the era of short videos.

Supported scenarios and effects of video mixing

Currently, video mixing is ideal for marketing and advertising. It supports three main video editing scenarios:

  1. From a single long video asset: You provide a theme for the script. The system combines the long video and the generated script to create a short video.
  2. From multiple video assets: You provide a theme for the script. The system combines the video assets and the generated script to create a short video.
  3. The model first learns the characteristics of a sample video and its script that you upload. Then, you provide new video assets and a theme for the script. The system combines the learned characteristics, the new assets, and the new script to create a new short video.

Prerequisites

You must use the SDK to use the video mixing feature. The Maven dependency is as follows:

<dependency>
 <groupId>com.aliyun</groupId>
 <artifactId>alibabacloud-aimiaobi20230801</artifactId>
 <version>1.0.68</version>
</dependency>

Important

Important notes before calling the API

  1. Call the APIs in the following order: asyncUploadVideo (upload assets) -> asyncCreateClipsTimeLine (generate editing timeline) -> asyncCreateClipsTask (generate final video).
  2. Periodically call getAutoClipsTaskInfo to retrieve the task status for each stage. You can proceed to the next stage only after the current stage is complete.
  3. The API endpoint for video mixing is: AiMiaoBi - Video Mixing.

API call procedure

Step 1: Upload video assets

  1. Upload the video assets.

NoteThe video assets must meet the following size requirements: A single video asset cannot exceed 200 MB. The total duration of all video assets cannot exceed 20 minutes.

package com.aliyun.sdk.service.aimiaobi20230801;

import com.alibaba.fastjson.JSON;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.aimiaobi20230801.models.AsyncUploadVideoRequest;
import com.aliyun.sdk.service.aimiaobi20230801.models.AsyncUploadVideoResponse;
import com.aliyun.sdk.service.aimiaobi20230801.utils.Util;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import com.aliyun.sdk.service.aimiaobi20230801.models.AsyncUploadVideoRequest.SourceVideos;
import com.aliyun.sdk.service.aimiaobi20230801.models.AsyncUploadVideoRequest.ReferenceVideo;

public class asyncUploadVideo {
    public static void main(String[] args) {
        try{
            String akSwap = "xxxx";
            String skSwap = "xxxx";

            StaticCredentialProvider provider = StaticCredentialProvider.create(
                    Credential.builder()
                            .accessKeyId(akSwap)
                            .accessKeySecret(skSwap)
                            .build()
            );

            AsyncClient client = AsyncClient.builder()
                    .region("cn-beijing")
                    .credentialsProvider(provider)
                    // Service-level configuration
                    .serviceConfiguration(Configuration.create()
                            .setSignatureVersion(SignatureVersion.V3)
                    )
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    .setProtocol("HTTPS")
                                    .setEndpointOverride("aimiaobi.cn-beijing.aliyuncs.com")
                    )
                    .build();

            List<SourceVideos> sourceVideos = new ArrayList<>();

            SourceVideos sv001= SourceVideos.builder()
                    .videoUrl("https://xxx")
                    .videoName("rise_of_kingdoms-cavalry.mp4")
                    .build();
            sourceVideos.add(sv001);

            SourceVideos sv002 = SourceVideos.builder()
                    .videoUrl("https://xxx")
                    .videoName("rise_of_kingdoms-crossbow.mp4")
                    .build();
            sourceVideos.add(sv002);

            SourceVideos sv003 = SourceVideos.builder()
                    .videoUrl("https://xxx")
                    .videoName("rise_of_kingdoms-bai_qi.mp4")
                    .build();
            sourceVideos.add(sv003);

            /*
            ReferenceVideo refVideo = ReferenceVideo .builder()
                    .videoUrl("https://xxx")
                    .videoName("purple_bottle_serum_gen6-reference.mp4")
                    .build();
            */

            AsyncUploadVideoRequest request = AsyncUploadVideoRequest.builder()
                    .workspaceId("llm-xxxx")
                    .splitInterval(1)
                    .sourceVideos(sourceVideos)
                    //.referenceVideo(refVideo)
                    .build();

            CompletableFuture<AsyncUploadVideoResponse> future = client.asyncUploadVideo(request);
            AsyncUploadVideoResponse response = future.get();

            System.out.println("ALL***********************");
            System.out.println("Request header values for a successful request:");
            System.out.println(response.getStatusCode());
            System.out.println(response.getHeaders());
            String jsonStr = JSON.toJSONString(response.getBody());
            System.out.println(jsonStr);
        }catch (Exception ex){
            System.out.println("///////exception happened: " + ex);
        }
    }
}
  1. Confirm that the videos are uploaded successfully. After the upload is complete, you can proceed to Step 2.
package com.aliyun.sdk.service.aimiaobi20230801;

import com.alibaba.fastjson.JSON;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.aimiaobi20230801.models.GetAutoClipsTaskInfoRequest;
import com.aliyun.sdk.service.aimiaobi20230801.models.GetAutoClipsTaskInfoResponse;
import com.aliyun.sdk.service.aimiaobi20230801.utils.Util;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.concurrent.CompletableFuture;

public class getAutoClipsTaskInfo {
    public static void main(String[] args) {
        try{
            String akSwap = "xxxx";
            String skSwap = "xxxx";

            StaticCredentialProvider provider = StaticCredentialProvider.create(
                    Credential.builder()
                            .accessKeyId(akSwap)
                            .accessKeySecret(skSwap)
                            .build()
            );

            AsyncClient client = AsyncClient.builder()
                    .region("cn-beijing")
                    .credentialsProvider(provider)
                    // Service-level configuration
                    .serviceConfiguration(Configuration.create()
                            .setSignatureVersion(SignatureVersion.V3)
                    )
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    .setProtocol("HTTPS")
                                    .setEndpointOverride("aimiaobi.cn-beijing.aliyuncs.com")
                    )
                    .build();

            GetAutoClipsTaskInfoRequest request = GetAutoClipsTaskInfoRequest.builder()
                    .workspaceId("llm-xxxx")
                    .taskId("xxxx")
                    .build();

            CompletableFuture<GetAutoClipsTaskInfoResponse> future = client.getAutoClipsTaskInfo(request);
            GetAutoClipsTaskInfoResponse response = future.get();

            System.out.println("ALL***********************");
            System.out.println("Request header values for a successful request:");
            System.out.println(response.getStatusCode());
            System.out.println(response.getHeaders());
            String jsonStr = JSON.toJSONString(response.getBody());
            System.out.println(jsonStr);
        }catch (Exception ex){
            System.out.println("///////exception happened: " + ex);
        }
    }
}

Step 2: Generate the editing timeline

  1. Call the API to generate the editing timeline.
package com.aliyun.sdk.service.aimiaobi20230801;

import com.alibaba.fastjson.JSON;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.aimiaobi20230801.models.AsyncCreateClipsTimeLineRequest;
import com.aliyun.sdk.service.aimiaobi20230801.models.AsyncCreateClipsTimeLineResponse;
import com.aliyun.sdk.service.aimiaobi20230801.utils.Util;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.concurrent.CompletableFuture;

public class asyncCreateClipsTimeLine {
    public static void main(String[] args) {
        try{
            String akSwap = "xxxx";
            String skSwap = "xxxx";

            StaticCredentialProvider provider = StaticCredentialProvider.create(
                    Credential.builder()
                            .accessKeyId(akSwap)
                            .accessKeySecret(skSwap)
                            .build()
            );

            AsyncClient client = AsyncClient.builder()
                    .region("cn-beijing")// Region ID
                    .credentialsProvider(provider)
                    // Service-level configuration
                    .serviceConfiguration(Configuration.create()
                            .setSignatureVersion(SignatureVersion.V3)
                    )
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    .setProtocol("HTTPS")
                                    .setEndpointOverride("aimiaobi.cn-beijing.aliyuncs.com")
                    )
                    .build();

            AsyncCreateClipsTimeLineRequest request = AsyncCreateClipsTimeLineRequest.builder()
                    .workspaceId("llm-xxxx")
                    .taskId("xxxx")
                    .processPrompt("The voiceover is a promotional ad for the game 'Rise of Kingdoms'. Do not show the text 'Rise of Kingdoms' in the middle of the video. The final scene of the video must show the text 'Rise of Kingdoms'.")
                    //.processModel("qwen-plus-latest")
                    .customContent("Some friends asked what unit on an ancient battlefield could counter infantry. The answer is cavalry! In the game 'Rise of Kingdoms', the Han Iron Cavalry led by Huo Qubing and the Tiger and Leopard Cavalry commanded by Cao Cao not only have a 10% march speed bonus but also a 30% attack bonus, making them an invincible force against infantry on the battlefield. Then, friends asked if there is any unit in 'Rise of Kingdoms' that can counter cavalry. Of course, there is. The repeating crossbowmen led by Zhuge Liang are fast and deadly. They can effectively suppress cavalry from a distance. Before the cavalry can even charge, they are shot down by Zhuge Liang's crossbows. Repeating crossbows are definitely the most effective unit for killing cavalry. Although cavalry and crossbowmen each have their strengths, they struggle when outnumbered. But you might not know that there is a hero in 'Rise of Kingdoms' who excels at fighting against the odds. He is the God of Slaughter, Bai Qi. The more enemies Bai Qi's troops kill, the higher their normal damage becomes. Bai Qi can also comprehensively enhance the attack and defense of low-health troops, turning them into a true battlefield meat grinder. The more enemies, the stronger they get. Want to experience all this? Come and have a blast in 'Rise of Kingdoms'.")
                    .build();

            CompletableFuture<AsyncCreateClipsTimeLineResponse> future = client.asyncCreateClipsTimeLine(request);
            AsyncCreateClipsTimeLineResponse response = future.get();

            System.out.println("ALL***********************");
            System.out.println("Request header values for a successful request:");
            System.out.println(response.getStatusCode());
            System.out.println(response.getHeaders());
            String jsonStr = JSON.toJSONString(response.getBody());
            System.out.println(jsonStr);
        }catch (Exception ex){
            System.out.println("///////exception happened: " + ex);
        }
    }
}
  1. Confirm that the editing timeline is generated. After the timeline is generated, you can proceed to Step 3.
package com.aliyun.sdk.service.aimiaobi20230801;

import com.alibaba.fastjson.JSON;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.aimiaobi20230801.models.GetAutoClipsTaskInfoRequest;
import com.aliyun.sdk.service.aimiaobi20230801.models.GetAutoClipsTaskInfoResponse;
import com.aliyun.sdk.service.aimiaobi20230801.utils.Util;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.concurrent.CompletableFuture;

public class getAutoClipsTaskInfo {
    public static void main(String[] args) {
        try{
            String akSwap = "xxxx";
            String skSwap = "xxxx";

            StaticCredentialProvider provider = StaticCredentialProvider.create(
                    Credential.builder()
                            .accessKeyId(akSwap)
                            .accessKeySecret(skSwap)
                            .build()
            );

            AsyncClient client = AsyncClient.builder()
                    .region("cn-beijing")
                    .credentialsProvider(provider)
                    // Service-level configuration
                    .serviceConfiguration(Configuration.create()
                            .setSignatureVersion(SignatureVersion.V3)
                    )
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    .setProtocol("HTTPS")
                                    .setEndpointOverride("aimiaobi.cn-beijing.aliyuncs.com")
                    )
                    .build();

            GetAutoClipsTaskInfoRequest request = GetAutoClipsTaskInfoRequest.builder()
                    .workspaceId("llm-xxxx")
                    .taskId("xxxx")
                    .build();

            CompletableFuture<GetAutoClipsTaskInfoResponse> future = client.getAutoClipsTaskInfo(request);
            GetAutoClipsTaskInfoResponse response = future.get();

            System.out.println("ALL***********************");
            System.out.println("Request header values for a successful request:");
            System.out.println(response.getStatusCode());
            System.out.println(response.getHeaders());
            String jsonStr = JSON.toJSONString(response.getBody());
            System.out.println(jsonStr);
        }catch (Exception ex){
            System.out.println("///////exception happened: " + ex);
        }
    }
}

Step 3: Generate the final video

  1. Generate the new video.
package com.aliyun.sdk.service.aimiaobi20230801;

import com.alibaba.fastjson.JSON;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.aimiaobi20230801.models.*;
import com.aliyun.sdk.service.aimiaobi20230801.utils.Util;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.ArrayList;
import java.util.List;

import java.util.concurrent.CompletableFuture;

public class asyncCreateClipsTask {
    public static void main(String[] args) {
        try{
            String akSwap = "xxx";
            String skSwap = "xxx";

            StaticCredentialProvider provider = StaticCredentialProvider.create(
                    Credential.builder()
                            .accessKeyId(akSwap)
                            .accessKeySecret(skSwap)
                            .build()
            );

            AsyncClient client = AsyncClient.builder()
                    .region("cn-beijing")// Region ID
                    .credentialsProvider(provider)
                    // Service-level configuration
                    .serviceConfiguration(Configuration.create()
                            .setSignatureVersion(SignatureVersion.V3)
                    )
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    .setProtocol("HTTPS")
                                    .setEndpointOverride("aimiaobi.cn-beijing.aliyuncs.com")
                    )
                    .build();

            List<AsyncCreateClipsTaskRequest.ColorWords> colorWords = new ArrayList<>();
            AsyncCreateClipsTaskRequest.ColorWords cw = AsyncCreateClipsTaskRequest.ColorWords.builder()
                    .y(0.1F)
                    .x(0.1F)
                    .content("Glacier moisturizing lotion, hydrate anytime")
                    .effectColorStyle("CS0002-000007")
                    .fontSize(120)
                    .timelineIn(0)
                    .timelineOut(5)
                    .build();
            colorWords.add(cw);
            AsyncCreateClipsTaskRequest request = AsyncCreateClipsTaskRequest.builder()
                    .workspaceId("llm-xxx")
                    .taskId("xxx")
                    //.colorWords(colorWords)
                    .build();

            CompletableFuture<AsyncCreateClipsTaskResponse> future = client.asyncCreateClipsTask(request);
            AsyncCreateClipsTaskResponse response = future.get();

            System.out.println("ALL***********************");
            System.out.println("Request header values for a successful request:");
            System.out.println(response.getStatusCode());
            System.out.println(response.getHeaders());
            String jsonStr = JSON.toJSONString(response.getBody());
            System.out.println(jsonStr);
        }catch (Exception ex){
            System.out.println("///////exception happened: " + ex);
        }
    }
}
  1. Verify that the new video has been edited.
package com.aliyun.sdk.service.aimiaobi20230801;

import com.alibaba.fastjson.JSON;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.aimiaobi20230801.models.GetAutoClipsTaskInfoRequest;
import com.aliyun.sdk.service.aimiaobi20230801.models.GetAutoClipsTaskInfoResponse;
import com.aliyun.sdk.service.aimiaobi20230801.utils.Util;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.concurrent.CompletableFuture;

public class getAutoClipsTaskInfo {
    public static void main(String[] args) {
        try{
            String akSwap = "xxxx";
            String skSwap = "xxxx";

            StaticCredentialProvider provider = StaticCredentialProvider.create(
                    Credential.builder()
                            .accessKeyId(akSwap)
                            .accessKeySecret(skSwap)
                            .build()
            );

            AsyncClient client = AsyncClient.builder()
                    .region("cn-beijing")
                    .credentialsProvider(provider)
                    // Service-level configuration
                    .serviceConfiguration(Configuration.create()
                            .setSignatureVersion(SignatureVersion.V3)
                    )
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    .setProtocol("HTTPS")
                                    .setEndpointOverride("aimiaobi.cn-beijing.aliyuncs.com")
                    )
                    .build();

            GetAutoClipsTaskInfoRequest request = GetAutoClipsTaskInfoRequest.builder()
                    .workspaceId("llm-xxxx")
                    .taskId("xxxx")
                    .build();

            CompletableFuture<GetAutoClipsTaskInfoResponse> future = client.getAutoClipsTaskInfo(request);
            GetAutoClipsTaskInfoResponse response = future.get();

            System.out.println("ALL***********************");
            System.out.println("Request header values for a successful request:");
            System.out.println(response.getStatusCode());
            System.out.println(response.getHeaders());
            String jsonStr = JSON.toJSONString(response.getBody());
            System.out.println(jsonStr);
        }catch (Exception ex){
            System.out.println("///////exception happened: " + ex);
        }
    }
}