Skip to content

Commit 9f277f7

Browse files
mose-zmmose-x.zm
andauthored
support wan2.6 video generation (#162)
Co-authored-by: mose-x.zm <[email protected]>
1 parent 5f830bb commit 9f277f7

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

samples/VideoSynthesisUsage.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@
99
import com.alibaba.dashscope.exception.NoApiKeyException;
1010
import com.alibaba.dashscope.task.AsyncTaskListParam;
1111

12+
import java.util.ArrayList;
13+
import java.util.List;
14+
1215
public class VideoSynthesisUsage {
1316
/**
1417
* Create a video compositing task and wait for the task to complete.
1518
*/
1619
public static void basicCall() throws ApiException, NoApiKeyException, InputRequiredException {
1720
VideoSynthesis vs = new VideoSynthesis();
21+
List<String> referenceVideoUrls = new ArrayList<>();
22+
referenceVideoUrls.add("https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/with_human_voice_11s.mov");
1823
VideoSynthesisParam param =
1924
VideoSynthesisParam.builder()
20-
.model("wan2.5-t2v-preview")
21-
.prompt("一只戴着绿色眼镜的小狗在唱rap")
22-
.audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3")
25+
.model("wan2.6-r2v")
26+
.prompt("一只小猫在月光下奔跑")
27+
.referenceVideoUrls(referenceVideoUrls)
28+
.shotType(VideoSynthesis.ShotType.MULTI)
29+
.watermark(Boolean.TRUE)
30+
.audio(Boolean.TRUE)
2331
.build();
2432
VideoSynthesisResult result = vs.call(param);
2533
System.out.println(result);
@@ -53,6 +61,7 @@ public static void main(String[] args) {
5361
// fetchTask("b451725d-c48f-4f08-9d26-xxx-xxx");
5462
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
5563
System.out.println(e.getMessage());
64+
e.printStackTrace();
5665
}
5766
System.exit(0);
5867
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public static class Resolution {
5454
public static final String DEFAULT = "720P";
5555
}
5656

57+
public static class ShotType {
58+
public static final String MULTI = "multi";
59+
public static final String SINGLE = "single";
60+
}
61+
5762
/**
5863
* Create ApiServiceOption
5964
*

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import com.alibaba.dashscope.utils.PreprocessInputImage;
1313
import com.google.gson.JsonObject;
1414
import java.nio.ByteBuffer;
15+
import java.util.ArrayList;
1516
import java.util.HashMap;
17+
import java.util.List;
1618
import java.util.Map;
1719
import lombok.Builder;
1820
import lombok.Data;
@@ -55,6 +57,13 @@ public class VideoSynthesisParam extends HalfDuplexServiceParam {
5557
/** The input audio url. */
5658
@Builder.Default private String audioUrl = null;
5759

60+
/** list of character reference video file urls uploaded by the user */
61+
@Builder.Default private List<String> referenceVideoUrls = null;
62+
63+
/** For the description information of the picture and sound of the reference video, corresponding to ref video,
64+
* it needs to be in the order of the url. If the quantity is different, an error will be reported */
65+
@Builder.Default private List<String> referenceVideoDescription = null;
66+
5867
/** The extra parameters. */
5968
@GsonExclude @Singular protected Map<String, Object> extraInputs;
6069

@@ -82,6 +91,8 @@ public class VideoSynthesisParam extends HalfDuplexServiceParam {
8291

8392
@Builder.Default private Boolean audio = null;
8493

94+
@Builder.Default private String shotType = null;
95+
8596
/** The inputs of the model. */
8697
@Override
8798
public JsonObject getInput() {
@@ -124,6 +135,14 @@ public JsonObject getInput() {
124135
jsonObject.addProperty(TAIL_FRAME, tailFrame);
125136
}
126137

138+
if (referenceVideoUrls != null && !referenceVideoUrls.isEmpty()) {
139+
jsonObject.add(REFERENCE_VIDEO_URLS, JsonUtils.toJsonArray(referenceVideoUrls));
140+
}
141+
142+
if (referenceVideoDescription != null && !referenceVideoDescription.isEmpty()) {
143+
jsonObject.add(REFERENCE_VIDEO_DESCRIPTION, JsonUtils.toJsonArray(referenceVideoDescription));
144+
}
145+
127146
if (extraInputs != null && !extraInputs.isEmpty()) {
128147
JsonObject extraInputsJsonObject = JsonUtils.parametersToJsonObject(extraInputs);
129148
JsonUtils.merge(jsonObject, extraInputsJsonObject);
@@ -164,6 +183,9 @@ public Map<String, Object> getParameters() {
164183
if (audio != null) {
165184
params.put(AUDIO, audio);
166185
}
186+
if (shotType != null) {
187+
params.put(SHOT_TYPE, shotType);
188+
}
167189
params.putAll(super.getParameters());
168190
return params;
169191
}
@@ -200,6 +222,13 @@ public void checkAndUpload() throws NoApiKeyException, UploadFileException {
200222
inputChecks.put(LAST_FRAME_URL, this.lastFrameUrl);
201223
inputChecks.put(HEAD_FRAME, this.headFrame);
202224
inputChecks.put(TAIL_FRAME, this.tailFrame);
225+
int rvs = 0;
226+
if (this.referenceVideoUrls != null) {
227+
rvs = this.referenceVideoUrls.size();
228+
for (int i = 0; i < rvs; i++) {
229+
inputChecks.put(REFERENCE_VIDEO_URLS + "[" + i + "]", this.referenceVideoUrls.get(i));
230+
}
231+
}
203232

204233
boolean isUpload = PreprocessInputImage.checkAndUploadImage(getModel(), inputChecks, getApiKey());
205234

@@ -212,6 +241,13 @@ public void checkAndUpload() throws NoApiKeyException, UploadFileException {
212241
this.lastFrameUrl = inputChecks.get(LAST_FRAME_URL);
213242
this.headFrame = inputChecks.get(HEAD_FRAME);
214243
this.tailFrame = inputChecks.get(TAIL_FRAME);
244+
if (rvs > 0) {
245+
List<String> newVideos = new ArrayList<>();
246+
for (int i = 0; i < rvs; i++) {
247+
newVideos.add(inputChecks.get(REFERENCE_VIDEO_URLS + "[" + i + "]"));
248+
}
249+
this.referenceVideoUrls = newVideos;
250+
}
215251
}
216252
}
217253

src/main/java/com/alibaba/dashscope/utils/ApiKeywords.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,10 @@ public class ApiKeywords {
191191
public static final String LANGUAGE_TYPE = "language_type";
192192

193193
public static final String IMAGES = "images";
194+
195+
public static final String REFERENCE_VIDEO_URLS = "reference_video_urls";
196+
197+
public static final String REFERENCE_VIDEO_DESCRIPTION = "reference_video_description";
198+
199+
public static final String SHOT_TYPE = "shot_type";
194200
}

0 commit comments

Comments
 (0)