-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest_video_synthesis.py
More file actions
136 lines (124 loc) · 4.32 KB
/
Copy pathtest_video_synthesis.py
File metadata and controls
136 lines (124 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
from http import HTTPStatus
from dashscope import VideoSynthesis
import os
prompt = "一只小猫在月光下奔跑"
audio_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
reference_urls = [
"https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/with_human_voice_11s.mov",
]
api_key = os.getenv("DASHSCOPE_API_KEY")
def simple_call():
print("----sync call, please wait a moment----")
rsp = VideoSynthesis.call(
api_key=api_key,
model="wan2.6-r2v",
reference_urls=reference_urls,
shot_type="multi",
audio=True,
watermark=True,
prompt=prompt,
)
if rsp.status_code == HTTPStatus.OK:
print("response: %s" % rsp)
else:
print(
"sync_call Failed, status_code: %s, code: %s, message: %s"
% (rsp.status_code, rsp.code, rsp.message),
)
def simple_call_t2v():
print("----sync call, please wait a moment----")
rsp = VideoSynthesis.call(
api_key=api_key,
model="wan2.7-t2v",
audio=True,
watermark=True,
prompt=prompt,
)
if rsp.status_code == HTTPStatus.OK:
print("response: %s" % rsp)
else:
print(
"sync_call Failed, status_code: %s, code: %s, message: %s"
% (rsp.status_code, rsp.code, rsp.message),
)
media_i2v = [
{
"type": VideoSynthesis.MediaType.LAST_FRAME,
"url": "https://wanx.alicdn.com/material/20250318/last_frame.png"
},
{
"type": VideoSynthesis.MediaType.FIRST_FRAME,
"url": "https://wanx.alicdn.com/material/20250318/first_frame.png"
},
{
"url": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/mp3_3s.mp3",
"type": VideoSynthesis.MediaType.DRIVING_AUDIO
}
]
def simple_call_wan27_i2v():
print("----sync call, please wait a moment----")
rsp = VideoSynthesis.call(
api_key=api_key,
model="wan2.7-i2v",
media=media_i2v,
audio=True,
watermark=True,
prompt=prompt,
)
if rsp.status_code == HTTPStatus.OK:
print("response: %s" % rsp)
else:
print(
"sync_call Failed, status_code: %s, code: %s, message: %s"
% (rsp.status_code, rsp.code, rsp.message),
)
media_r2v = [
{
"type": VideoSynthesis.MediaType.REFERENCE_IMAGE,
"url": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/res240_269.jpg"
},
{
"type": VideoSynthesis.MediaType.REFERENCE_IMAGE,
"url": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/image/man_5K_7_7K_18_4M.JPG",
"reference_voice": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/2s.wav"
},
{
"type": VideoSynthesis.MediaType.REFERENCE_VIDEO,
"url": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/100M.mov",
"reference_voice": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/mp3_1s.mp3"
},
{
"type": VideoSynthesis.MediaType.REFERENCE_VIDEO,
"url": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/29_99s.mp4",
"reference_description": "这是一个身穿蓝衣的男子<cast>,他有着浓密的络腮胡"
},
{
"type": VideoSynthesis.MediaType.REFERENCE_VIDEO,
"url": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/video/resources/cast/cat_127.mp4",
"reference_voice": "https://test-data-center.oss-accelerate.aliyuncs.com/wanx/audio/wav_10s.wav",
"reference_description": "这是一只毛绒小猫<cast>,它正在对着镜头微笑"
}
]
def simple_call_wan27_r2v():
print("----sync call, please wait a moment----")
rsp = VideoSynthesis.call(
api_key=api_key,
model="wan2.7-r2v",
media=media_r2v,
audio=True,
watermark=True,
prompt=prompt,
)
if rsp.status_code == HTTPStatus.OK:
print("response: %s" % rsp)
else:
print(
"sync_call Failed, status_code: %s, code: %s, message: %s"
% (rsp.status_code, rsp.code, rsp.message),
)
if __name__ == "__main__":
simple_call()
# simple_call_t2v()
# simple_call_wan27_i2v()
# simple_call_wan27_r2v()