Skip to content

Commit 19bd2be

Browse files
author
mose-x.zm
committed
support wan 2.7
1 parent 1a4170b commit 19bd2be

5 files changed

Lines changed: 354 additions & 37 deletions

File tree

samples/VideoSynthesisUsage.java

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public class VideoSynthesisUsage {
1818
*/
1919
public static void basicCall() throws ApiException, NoApiKeyException, InputRequiredException {
2020
VideoSynthesis vs = new VideoSynthesis();
21-
List<String> referenceVideoUrls = new ArrayList<>();
22-
referenceVideoUrls.add("https://cdn.wanx.aliyuncs.com/wanx/1014827220770308/upload-video-cut/cda0f4dc063ec258184263691558af36.mp4");
21+
List<String> referenceUrls = new ArrayList<>();
22+
referenceUrls.add("https://cdn.wanx.aliyuncs.com/wanx/1014827220770308/upload-video-cut/cda0f4dc063ec258184263691558af36.mp4");
2323

2424
List<String> referenceVideoDescription = new ArrayList<>();
2525
referenceVideoDescription.add("这段视频展示一位年轻女性(<cast>)身着灰色长袖上衣与裤子,乌黑长发垂落,面容清秀。她先低头后抬头,目光侧移,继而转身背对再面向镜头,动作流畅自然。背景为素净灰色墙面,环境简约无装饰。镜头由面部特写缓缓拉远至全身,光影柔和,突出人物形态与情绪。");
2626
VideoSynthesisParam param =
2727
VideoSynthesisParam.builder()
2828
.model("wan2.6-r2v")
2929
.prompt(" character1 站在海边,吹着海风,夕阳西下,阳光洒在她的脸上")
30-
.referenceVideoUrls(referenceVideoUrls)
30+
.referenceUrls(referenceUrls)
3131
.referenceVideoDescription(referenceVideoDescription)
3232
.shotType(VideoSynthesis.ShotType.MULTI)
3333
.watermark(Boolean.TRUE)
@@ -39,6 +39,83 @@ public static void basicCall() throws ApiException, NoApiKeyException, InputRequ
3939
VideoSynthesisResult result = vs.call(param);
4040
System.out.println(result);
4141
}
42+
/**
43+
* Create a video compositing task and wait for the task to complete.
44+
*/
45+
public static void basicCallI2V27() throws ApiException, NoApiKeyException, InputRequiredException {
46+
VideoSynthesis vs = new VideoSynthesis();
47+
final String prompt = "一幅都市奇幻艺术的场景。一个充满动感的涂鸦艺术角色。一个由喷漆所画成的少年,正从一面混凝土墙上活过来。他一边用极快的语速演唱一首英文rap,一边摆着一个经典的、充满活力的说唱歌手姿势。场景设定在夜晚一个充满都市感的铁路桥下。灯光来自一盏孤零零的街灯,营造出电影般的氛围,充满高能量和惊人的细节。视频的音频部分完全由他的rap构成,没有其他对话或杂音。";
48+
final String negativePrompt = "ugly, bad anatomy";
49+
List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
50+
add(VideoSynthesisParam.Media.builder()
51+
.url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png")
52+
.type(VideoSynthesis.MediaType.FIRST_CLIP)
53+
.build());
54+
add(VideoSynthesisParam.Media.builder()
55+
.url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3")
56+
.type(VideoSynthesis.MediaType.DRIVING_AUDIO)
57+
.build());
58+
}};
59+
VideoSynthesisParam param =
60+
VideoSynthesisParam.builder()
61+
.model("wan2.7-i2v")
62+
.prompt(prompt)
63+
.media(media)
64+
.watermark(Boolean.TRUE)
65+
.duration(10)
66+
.negativePrompt(negativePrompt)
67+
.size("1280*720")
68+
.build();
69+
VideoSynthesisResult result = vs.call(param);
70+
System.out.println(result);
71+
}
72+
/**
73+
* Create a video compositing task and wait for the task to complete.
74+
*/
75+
public static void basicCallR2V27() throws ApiException, NoApiKeyException, InputRequiredException {
76+
VideoSynthesis vs = new VideoSynthesis();
77+
final String prompt = "一幅都市奇幻艺术的场景。一个充满动感的涂鸦艺术角色。一个由喷漆所画成的少年,正从一面混凝土墙上活过来。他一边用极快的语速演唱一首英文rap,一边摆着一个经典的、充满活力的说唱歌手姿势。场景设定在夜晚一个充满都市感的铁路桥下。灯光来自一盏孤零零的街灯,营造出电影般的氛围,充满高能量和惊人的细节。视频的音频部分完全由他的rap构成,没有其他对话或杂音。";
78+
final String negativePrompt = "ugly, bad anatomy";
79+
List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
80+
add(VideoSynthesisParam.Media.builder()
81+
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/res240_269.jpg")
82+
.type(VideoSynthesis.MediaType.REFERENCE_IMAGE)
83+
.build());
84+
add(VideoSynthesisParam.Media.builder()
85+
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/man_5K_7_7K_18_4M.JPG")
86+
.referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/2s.wav")
87+
.type(VideoSynthesis.MediaType.REFERENCE_IMAGE)
88+
.build());
89+
add(VideoSynthesisParam.Media.builder()
90+
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/100M.mov")
91+
.referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/mp3_1s.mp3")
92+
.type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
93+
.build());
94+
add(VideoSynthesisParam.Media.builder()
95+
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/29_99s.mp4")
96+
.referenceDescription("这是一个身穿蓝衣的男子<cast>,他有着浓密的络腮胡")
97+
.type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
98+
.build());
99+
add(VideoSynthesisParam.Media.builder()
100+
.url("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/cat_127.mp4")
101+
.referenceVoice("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/wav_10s.wav")
102+
.referenceDescription("这是一只毛绒小猫<cast>,它正在对着镜头微笑")
103+
.type(VideoSynthesis.MediaType.REFERENCE_VIDEO)
104+
.build());
105+
}};
106+
VideoSynthesisParam param =
107+
VideoSynthesisParam.builder()
108+
.model("wan2.7-r2v")
109+
.prompt(prompt)
110+
.media(media)
111+
.watermark(Boolean.TRUE)
112+
.duration(10)
113+
.negativePrompt(negativePrompt)
114+
.size("1280*720")
115+
.build();
116+
VideoSynthesisResult result = vs.call(param);
117+
System.out.println(result);
118+
}
42119

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

64141
public static void main(String[] args) {
65142
try {
66-
basicCall();
143+
// basicCall();
144+
// basicCallI2V27();
145+
basicCallR2V27();
67146
// listTask();
68147
// fetchTask("b451725d-c48f-4f08-9d26-xxx-xxx");
69148
} catch (ApiException | NoApiKeyException | InputRequiredException e) {

src/main/java/com/alibaba/dashscope/aigc/imagegeneration/ImageGenerationParam.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
import com.alibaba.dashscope.utils.JsonUtils;
88
import com.alibaba.dashscope.utils.ParamUtils;
99
import com.google.gson.JsonObject;
10+
import lombok.Builder;
11+
import lombok.Data;
12+
import lombok.EqualsAndHashCode;
13+
import lombok.Singular;
14+
import lombok.experimental.SuperBuilder;
15+
1016
import java.nio.ByteBuffer;
1117
import java.util.HashMap;
1218
import java.util.List;
1319
import java.util.Map;
14-
import lombok.*;
15-
import lombok.experimental.SuperBuilder;
1620

1721
@EqualsAndHashCode(callSuper = true)
1822
@Data
@@ -73,6 +77,8 @@ public class ImageGenerationParam extends HalfDuplexServiceParam {
7377

7478
private Integer maxImages;
7579

80+
private Boolean enableSequential;
81+
7682
@Override
7783
public JsonObject getHttpBody() {
7884
JsonObject requestObject = new JsonObject();
@@ -149,6 +155,10 @@ public Map<String, Object> getParameters() {
149155
params.put("max_images", maxImages);
150156
}
151157

158+
if (enableSequential != null) {
159+
params.put("enable_sequential", enableSequential);
160+
}
161+
152162
params.putAll(parameters);
153163
return params;
154164
}

src/main/java/com/alibaba/dashscope/aigc/videosynthesis/VideoSynthesis.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public static class Resolution {
5757
public static class ShotType {
5858
public static final String MULTI = "multi";
5959
public static final String SINGLE = "single";
60+
public static final String AUTO = "auto";
61+
}
62+
63+
public static class MediaType {
64+
public static final String FIRST_FRAME = "first_frame";
65+
public static final String LAST_FRAME = "last_frame";
66+
public static final String REFERENCE_IMAGE = "reference_image";
67+
public static final String REFERENCE_VIDEO = "reference_video";
68+
public static final String REFERENCE_VOICE = "reference_voice";
69+
public static final String VIDEO = "video";
70+
public static final String FIRST_CLIP = "first_clip";
71+
public static final String DRIVING_AUDIO = "driving_audio";
6072
}
6173

6274
/**

0 commit comments

Comments
 (0)