Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 83 additions & 4 deletions samples/VideoSynthesisUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public class VideoSynthesisUsage {
*/
public static void basicCall() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
List<String> referenceVideoUrls = new ArrayList<>();
referenceVideoUrls.add("https://cdn.wanx.aliyuncs.com/wanx/1014827220770308/upload-video-cut/cda0f4dc063ec258184263691558af36.mp4");
List<String> referenceUrls = new ArrayList<>();
referenceUrls.add("https://cdn.wanx.aliyuncs.com/wanx/1014827220770308/upload-video-cut/cda0f4dc063ec258184263691558af36.mp4");

List<String> referenceVideoDescription = new ArrayList<>();
referenceVideoDescription.add("这段视频展示一位年轻女性(<cast>)身着灰色长袖上衣与裤子,乌黑长发垂落,面容清秀。她先低头后抬头,目光侧移,继而转身背对再面向镜头,动作流畅自然。背景为素净灰色墙面,环境简约无装饰。镜头由面部特写缓缓拉远至全身,光影柔和,突出人物形态与情绪。");
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.model("wan2.6-r2v")
.prompt(" character1 站在海边,吹着海风,夕阳西下,阳光洒在她的脸上")
.referenceVideoUrls(referenceVideoUrls)
.referenceUrls(referenceUrls)
.referenceVideoDescription(referenceVideoDescription)
.shotType(VideoSynthesis.ShotType.MULTI)
.watermark(Boolean.TRUE)
Expand All @@ -39,6 +39,83 @@ public static void basicCall() throws ApiException, NoApiKeyException, InputRequ
VideoSynthesisResult result = vs.call(param);
System.out.println(result);
}
/**
* Create a video compositing task and wait for the task to complete.
*/
public static void basicCallI2V27() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
final String prompt = "一幅都市奇幻艺术的场景。一个充满动感的涂鸦艺术角色。一个由喷漆所画成的少年,正从一面混凝土墙上活过来。他一边用极快的语速演唱一首英文rap,一边摆着一个经典的、充满活力的说唱歌手姿势。场景设定在夜晚一个充满都市感的铁路桥下。灯光来自一盏孤零零的街灯,营造出电影般的氛围,充满高能量和惊人的细节。视频的音频部分完全由他的rap构成,没有其他对话或杂音。";
final String negativePrompt = "ugly, bad anatomy";
List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
add(VideoSynthesisParam.Media.builder()
.url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png")
.type(VideoSynthesis.MediaType.FIRST_CLIP)
.build());
add(VideoSynthesisParam.Media.builder()
.url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3")
.type(VideoSynthesis.MediaType.DRIVING_AUDIO)
.build());
}};
Comment on lines +49 to +58
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Double-brace initialization should be avoided. It creates an anonymous inner class for each use, which can lead to performance and memory issues. It's better to initialize the list and then add elements to it.

        List<VideoSynthesisParam.Media> media = new ArrayList<>();
        media.add(VideoSynthesisParam.Media.builder()
                .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png")
                .type(VideoSynthesis.MediaType.FIRST_CLIP)
                .build());
        media.add(VideoSynthesisParam.Media.builder()
                .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3")
                .type(VideoSynthesis.MediaType.DRIVING_AUDIO)
                .build());

VideoSynthesisParam param =
VideoSynthesisParam.builder()
.model("wan2.7-i2v")
.prompt(prompt)
.media(media)
.watermark(Boolean.TRUE)
.duration(10)
.negativePrompt(negativePrompt)
.size("1280*720")
.build();
VideoSynthesisResult result = vs.call(param);
System.out.println(result);
}
/**
* Create a video compositing task and wait for the task to complete.
*/
public static void basicCallR2V27() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
final String prompt = "一幅都市奇幻艺术的场景。一个充满动感的涂鸦艺术角色。一个由喷漆所画成的少年,正从一面混凝土墙上活过来。他一边用极快的语速演唱一首英文rap,一边摆着一个经典的、充满活力的说唱歌手姿势。场景设定在夜晚一个充满都市感的铁路桥下。灯光来自一盏孤零零的街灯,营造出电影般的氛围,充满高能量和惊人的细节。视频的音频部分完全由他的rap构成,没有其他对话或杂音。";
final String negativePrompt = "ugly, bad anatomy";
List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
add(VideoSynthesisParam.Media.builder()
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/res240_269.jpg")
.type(VideoSynthesis.MediaType.REFERENCE_IMAGE)
.build());
add(VideoSynthesisParam.Media.builder()
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/man_5K_7_7K_18_4M.JPG")
.referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/2s.wav")
.type(VideoSynthesis.MediaType.REFERENCE_IMAGE)
.build());
add(VideoSynthesisParam.Media.builder()
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/100M.mov")
.referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/mp3_1s.mp3")
.type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
.build());
add(VideoSynthesisParam.Media.builder()
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/29_99s.mp4")
.referenceDescription("这是一个身穿蓝衣的男子<cast>,他有着浓密的络腮胡")
.type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
.build());
add(VideoSynthesisParam.Media.builder()
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/cat_127.mp4")
.referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/wav_10s.wav")
.referenceDescription("这是一只毛绒小猫<cast>,它正在对着镜头微笑")
.type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
.build());
}};
Comment on lines +79 to +105
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Double-brace initialization should be avoided. It creates an anonymous inner class for each use, which can lead to performance and memory issues. A better approach is to use java.util.Arrays.asList or List.of (for Java 9+) to create the list.

        List<VideoSynthesisParam.Media> media = new ArrayList<>(java.util.Arrays.asList(
            VideoSynthesisParam.Media.builder()
                    .url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/res240_269.jpg")
                    .type(VideoSynthesis.MediaType.REFERENCE_IMAGE)
                    .build(),
            VideoSynthesisParam.Media.builder()
                    .url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/man_5K_7_7K_18_4M.JPG")
                    .referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/2s.wav")
                    .type(VideoSynthesis.MediaType.REFERENCE_IMAGE)
                    .build(),
            VideoSynthesisParam.Media.builder()
                    .url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/100M.mov")
                    .referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/mp3_1s.mp3")
                    .type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
                    .build(),
            VideoSynthesisParam.Media.builder()
                    .url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/29_99s.mp4")
                    .referenceDescription("这是一个身穿蓝衣的男子<cast>,他有着浓密的络腮胡")
                    .type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
                    .build(),
            VideoSynthesisParam.Media.builder()
                    .url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/cat_127.mp4")
                    .referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/wav_10s.wav")
                    .referenceDescription("这是一只毛绒小猫<cast>,它正在对着镜头微笑")
                    .type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
                    .build()
        ));

VideoSynthesisParam param =
VideoSynthesisParam.builder()
.model("wan2.7-r2v")
.prompt(prompt)
.media(media)
.watermark(Boolean.TRUE)
.duration(10)
.negativePrompt(negativePrompt)
.size("1280*720")
.build();
VideoSynthesisResult result = vs.call(param);
System.out.println(result);
}

/**
* List all tasks.
Expand All @@ -63,7 +140,9 @@ public static void fetchTask(String taskId) throws ApiException, NoApiKeyExcepti

public static void main(String[] args) {
try {
basicCall();
// basicCall();
// basicCallI2V27();
basicCallR2V27();
// listTask();
// fetchTask("b451725d-c48f-4f08-9d26-xxx-xxx");
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.*;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Singular;
import lombok.experimental.SuperBuilder;

@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -73,6 +76,8 @@ public class ImageGenerationParam extends HalfDuplexServiceParam {

private Integer maxImages;

private Boolean enableSequential;

@Override
public JsonObject getHttpBody() {
JsonObject requestObject = new JsonObject();
Expand Down Expand Up @@ -149,6 +154,10 @@ public Map<String, Object> getParameters() {
params.put("max_images", maxImages);
}

if (enableSequential != null) {
params.put("enable_sequential", enableSequential);
}

params.putAll(parameters);
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public static class Resolution {
public static class ShotType {
public static final String MULTI = "multi";
public static final String SINGLE = "single";
public static final String AUTO = "auto";
}

public static class MediaType {
public static final String FIRST_FRAME = "first_frame";
public static final String LAST_FRAME = "last_frame";
public static final String REFERENCE_IMAGE = "reference_image";
public static final String REFERENCE_VIDEO = "reference_video";
public static final String REFERENCE_VOICE = "reference_voice";
public static final String VIDEO = "video";
public static final String FIRST_CLIP = "first_clip";
public static final String DRIVING_AUDIO = "driving_audio";
}

/**
Expand Down
Loading
Loading