萬相-文生視頻模型支援文本、映像、音頻多模態輸入產生視頻。wan3.0-video支援最長30秒、自適應寬高比、智能時間長度、480P/720P/1080P解析度、音頻開關、參考音頻,以及傳入參考檔案和網頁連結。
快速開始
| 輸入提示詞 | 輸出視頻(多鏡頭,有聲視頻) |
| 第1個鏡頭大遠景開篇,鏡頭從接近地面的低機位開始向前移動,鏡頭沿草原方向推進,同時向上移動,將視角從貼地逐漸抬升至略高位置,使獵豹從左側進入畫面並與前方逃竄的羚羊共同處於同一追逐路徑中,建立清晰的前後空間關係。第2個鏡頭向下移動回到接近地面高度,並沿獵豹運動方向向右移動,與其保持側向平行關係進行穩定跟隨,主體始終處於畫面中部偏左位置,背景產生連續橫向位移效果,在這一階段鏡頭運動保持穩定一段時間以強化速度感與空間連續性。 第3個鏡頭在維持向右移動的同時,沿獵豹運動路徑內側做小幅弧線移動,使畫面產生輕微繞行變化但始終保持與主體同向。 第4個鏡頭逐漸減緩橫向移動速度並過渡為機位相對穩定,同時執行變焦推進,將視覺焦點逐步壓縮至獵豹與羚羊之間不斷縮短的距離上。 第5個鏡頭再次向前移動並輕微向下移動,貼近地面逼近兩者之間的空間,在獵豹前肢逼近羚羊後方的臨界位置停住,形成強烈壓迫感與張力,同時配合逐漸增強交響配樂、持續加密的鼓點、風聲與踏地聲推進節奏,並在最後階段壓低音樂僅保留環境聲與節奏聲形成短暫停頓。 |
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於
1.25.16,再運行以下代碼。若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY", "YOUR_API_KEY")
print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model='wan3.0-video',
prompt='第1個鏡頭 大遠景開篇,鏡頭從接近地面的低機位開始向前移動,鏡頭沿草原方向推進,同時向上移動,將視角從貼地逐漸抬升至略高位置,使獵豹從左側進入畫面並與前方逃竄的羚羊共同處於同一追逐路徑中,建立清晰的前後空間關係。 第2個鏡頭 向下移動回到接近地面高度,並沿獵豹運動方向向右移動,與其保持側向平行關係進行穩定跟隨,主體始終處於畫面中部偏左位置,背景產生連續橫向位移效果,在這一階段鏡頭運動保持穩定一段時間以強化速度感與空間連續性。 第3個鏡頭 在維持向右移動的同時,沿獵豹運動路徑內側做小幅弧線移動,使畫面產生輕微繞行變化但始終保持與主體同向。 第4個鏡頭 逐漸減緩橫向移動速度並過渡為機位相對穩定,同時執行變焦推進,將視覺焦點逐步壓縮至獵豹與羚羊之間不斷縮短的距離上。 第5個鏡頭 再次向前移動並輕微向下移動,貼近地面逼近兩者之間的空間,在獵豹前肢逼近羚羊後方的臨界位置停住,形成強烈壓迫感與張力,同時配合逐漸增強交響配樂、持續加密的鼓點、風聲與踏地聲推進節奏,並在最後階段壓低音樂僅保留環境聲與節奏聲形成短暫停頓。',
resolution="720P",
ratio="16:9",
duration=15,
watermark=True)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("video_url:", rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
請確保 DashScope Java SDK 版本不低於
2.22.14,再運行以下代碼。若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan3.0-video")
.prompt("第1個鏡頭 大遠景開篇,鏡頭從接近地面的低機位開始向前移動,鏡頭沿草原方向推進,同時向上移動,將視角從貼地逐漸抬升至略高位置,使獵豹從左側進入畫面並與前方逃竄的羚羊共同處於同一追逐路徑中,建立清晰的前後空間關係。 第2個鏡頭 向下移動回到接近地面高度,並沿獵豹運動方向向右移動,與其保持側向平行關係進行穩定跟隨,主體始終處於畫面中部偏左位置,背景產生連續橫向位移效果,在這一階段鏡頭運動保持穩定一段時間以強化速度感與空間連續性。 第3個鏡頭 在維持向右移動的同時,沿獵豹運動路徑內側做小幅弧線移動,使畫面產生輕微繞行變化但始終保持與主體同向。 第4個鏡頭 逐漸減緩橫向移動速度並過渡為機位相對穩定,同時執行變焦推進,將視覺焦點逐步壓縮至獵豹與羚羊之間不斷縮短的距離上。 第5個鏡頭 再次向前移動並輕微向下移動,貼近地面逼近兩者之間的空間,在獵豹前肢逼近羚羊後方的臨界位置停住,形成強烈壓迫感與張力,同時配合逐漸增強交響配樂、持續加密的鼓點、風聲與踏地聲推進節奏,並在最後階段壓低音樂僅保留環境聲與節奏聲形成短暫停頓。")
.duration(15)
.resolution("720P")
.ratio("16:9")
.watermark(true)
.build();
System.out.println("please wait...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan3.0-video",
"input": {
"prompt": "第1個鏡頭 大遠景開篇,鏡頭從接近地面的低機位開始向前移動,鏡頭沿草原方向推進,同時向上移動,將視角從貼地逐漸抬升至略高位置,使獵豹從左側進入畫面並與前方逃竄的羚羊共同處於同一追逐路徑中,建立清晰的前後空間關係。 第2個鏡頭 向下移動回到接近地面高度,並沿獵豹運動方向向右移動,與其保持側向平行關係進行穩定跟隨,主體始終處於畫面中部偏左位置,背景產生連續橫向位移效果,在這一階段鏡頭運動保持穩定一段時間以強化速度感與空間連續性。 第3個鏡頭 在維持向右移動的同時,沿獵豹運動路徑內側做小幅弧線移動,使畫面產生輕微繞行變化但始終保持與主體同向。 第4個鏡頭 逐漸減緩橫向移動速度並過渡為機位相對穩定,同時執行變焦推進,將視覺焦點逐步壓縮至獵豹與羚羊之間不斷縮短的距離上。 第5個鏡頭 再次向前移動並輕微向下移動,貼近地面逼近兩者之間的空間,在獵豹前肢逼近羚羊後方的臨界位置停住,形成強烈壓迫感與張力,同時配合逐漸增強交響配樂、持續加密的鼓點、風聲與踏地聲推進節奏,並在最後階段壓低音樂僅保留環境聲與節奏聲形成短暫停頓。"
},
"parameters": {
"resolution": "720P",
"ratio": "16:9",
"watermark": true,
"duration": 15
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
範例程式碼:wan2.6及早期模型
範例程式碼:wan2.6及早期模型
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於
1.25.16,再運行以下代碼。若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY", "YOUR_API_KEY")
print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model='wan2.6-t2v',
prompt='一段緊張刺激的偵探追查故事,展現電影級敘事能力。第1個鏡頭[0-3秒] 全景:雨夜的紐約街頭,霓虹燈閃爍,一位身穿黑色風衣的偵探快步行走。 第2個鏡頭[3-6秒] 中景:偵探進入一棟老舊建築,雨水打濕了他的外套,門在他身後緩緩關閉。 第3個鏡頭[6-9秒] 特寫:偵探的眼神堅毅專註,遠處傳來警笛聲,他微微皺眉思考。 第4個鏡頭[9-12秒] 中景:偵探在昏暗走廊中小心前行,手電筒照亮前方。 第5個鏡頭[12-15秒] 特寫:偵探發現關鍵線索,臉上露出恍然大悟的表情。',
size="1280*720",
duration=15,
shot_type="multi",
watermark=True)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("video_url:", rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
請確保 DashScope Java SDK 版本不低於
2.22.14,再運行以下代碼。若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-t2v")
.prompt("一段緊張刺激的偵探追查故事,展現電影級敘事能力。第1個鏡頭[0-3秒] 全景:雨夜的紐約街頭,霓虹燈閃爍,一位身穿黑色風衣的偵探快步行走。 第2個鏡頭[3-6秒] 中景:偵探進入一棟老舊建築,雨水打濕了他的外套,門在他身後緩緩關閉。 第3個鏡頭[6-9秒] 特寫:偵探的眼神堅毅專註,遠處傳來警笛聲,他微微皺眉思考。 第4個鏡頭[9-12秒] 中景:偵探在昏暗走廊中小心前行,手電筒照亮前方。 第5個鏡頭[12-15秒] 特寫:偵探發現關鍵線索,臉上露出恍然大悟的表情。")
.duration(15)
.size("1280*720")
.shotType("multi")
.watermark(true)
.build();
System.out.println("please wait...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan2.6-t2v",
"input": {
"prompt": "一段緊張刺激的偵探追查故事,展現電影級敘事能力。第1個鏡頭[0-3秒] 全景:雨夜的紐約街頭,霓虹燈閃爍,一位身穿黑色風衣的偵探快步行走。 第2個鏡頭[3-6秒] 中景:偵探進入一棟老舊建築,雨水打濕了他的外套,門在他身後緩緩關閉。 第3個鏡頭[6-9秒] 特寫:偵探的眼神堅毅專註,遠處傳來警笛聲,他微微皺眉思考。 第4個鏡頭[9-12秒] 中景:偵探在昏暗走廊中小心前行,手電筒照亮前方。 第5個鏡頭[12-15秒] 特寫:偵探發現關鍵線索,臉上露出恍然大悟的表情。"
},
"parameters": {
"size": "1280*720",
"watermark": true,
"duration": 15,
"shot_type":"multi"
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
video_url 有效期間24小時,請及時下載視頻。
Copy
{
"request_id": "c1209113-8437-424f-a386-xxxxxx",
"output": {
"task_id": "966cebcd-dedc-4962-af88-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
}
}
適用範圍
- 各地區支援的模型有所差異,且資源相互獨立。各地區支援的模型請參見百鍊控制台。
- 調用時,確保模型、Endpoint URL 和 API Key 均屬於同一地區,跨地區調用將會失敗。
本文的範例程式碼適用於新加坡地區。
核心能力
製作多鏡頭視頻
支援模型:wan3.0、wan2.7系列、wan2.6系列模型。
功能介紹:模型可自動進行分鏡切換,例如從全景切換到特寫,製作MV等情境。
參數設定:
- wan2.7:無需設定
shot_type,可以在prompt中用自然語言描述鏡頭結構(如使用時間戳分鏡描述)。若prompt中未包含任何鏡頭結構描述,模型將分析語義內容,自行決策輸出單鏡頭或多鏡頭視頻。 - wan2.6:
shot_type必須設為"multi",且prompt_extend必須設為true(開啟智能改寫以最佳化分鏡描述)。
| 輸入提示詞 | 輸出視頻(wan3.0) |
| 展現未來科技與自然和諧共存的美好願景。 第1個鏡頭[0-2秒] 未來城市的空中花園全景,懸浮植物在微風中搖曳。 第2個鏡頭[2-4秒] 機器人園丁正在精心修剪植物,動作精準而優雅。 第3個鏡頭[4-7秒] 陽光透過透明穹頂灑下,照亮整個花園,展現科技與自然的完美融合。 第4個鏡頭[7-10秒] 鏡頭拉遠,展現整個未來城市的壯觀景象,空中花園只是其中的一部分。 | |
| 這是一段以硬核對決為核心的武俠電影片段,在正午烈日照射的石板空地上,兩名男子相對衝刺。一人出掌攻擊,被對手旋身以手臂硬抗,相撞的衝擊力震散地面微塵。隨後兩人在極小空間內拳掌疾速交錯,一人騰空連環重踢,迫使對手雙臂交叉抵擋並向後滑行數米,在石面磨出清晰白痕。最終兩人分立兩端,在劇烈呼吸中死死結定對方。畫面呈現出銳利光影下的寫實動作質感,營造出從強力爆發到肅殺對峙的基調。 |
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於 1.25.16,可參考安裝SDK進行更新。
Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan3.0-video',
prompt='展現未來科技與自然和諧共存的美好願景。 第1個鏡頭[0-2秒] 未來城市的空中花園全景,懸浮植物在微風中搖曳。 第2個鏡頭[2-4秒] 機器人園丁正在精心修剪植物,動作精準而優雅。 第3個鏡頭[4-7秒] 陽光透過透明穹頂灑下,照亮整個花園,展現科技與自然的完美融合。 第4個鏡頭[7-10秒] 鏡頭拉遠,展現整個未來城市的壯觀景象,空中花園只是其中的一部分。',
resolution='720P',
ratio='16:9',
duration=10,
watermark=True,
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
# 等待非同步任務結束
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_t2v()
請確保 DashScope Java SDK 版本不低於 2.22.14,可參考安裝SDK進行更新。
Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan3.0-video")
.prompt("展現未來科技與自然和諧共存的美好願景。 第1個鏡頭[0-2秒] 未來城市的空中花園全景,懸浮植物在微風中搖曳。 第2個鏡頭[2-4秒] 機器人園丁正在精心修剪植物,動作精準而優雅。 第3個鏡頭[4-7秒] 陽光透過透明穹頂灑下,照亮整個花園,展現科技與自然的完美融合。 第4個鏡頭[7-10秒] 鏡頭拉遠,展現整個未來城市的壯觀景象,空中花園只是其中的一部分。")
.resolution("720P")
.ratio("16:9")
.duration(10)
.watermark(true)
.seed(12345)
.build();
// 非同步呼叫
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
//擷取結果
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan3.0-video",
"input": {
"prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \"。",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3"
},
"parameters": {
"resolution": "720P",
"ratio": "16:9",
"duration": 10
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
範例程式碼:wan2.6模型
範例程式碼:wan2.6模型
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於 1.25.16,可參考安裝SDK進行更新。
Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-t2v',
prompt='展現未來科技與自然和諧共存的美好願景。 第1個鏡頭[0-2秒] 未來城市的空中花園全景,懸浮植物在微風中搖曳。 第2個鏡頭[2-4秒] 機器人園丁正在精心修剪植物,動作精準而優雅。 第3個鏡頭[4-7秒] 陽光透過透明穹頂灑下,照亮整個花園,展現科技與自然的完美融合。 第4個鏡頭[7-10秒] 鏡頭拉遠,展現整個未來城市的壯觀景象,空中花園只是其中的一部分。',
size='1280*720',
duration=10,
shot_type='multi',
watermark=True,
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
# 等待非同步任務結束
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_t2v()
請確保 DashScope Java SDK 版本不低於 2.22.14,可參考安裝SDK進行更新。
Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-t2v")
.prompt("展現未來科技與自然和諧共存的美好願景。 第1個鏡頭[0-2秒] 未來城市的空中花園全景,懸浮植物在微風中搖曳。 第2個鏡頭[2-4秒] 機器人園丁正在精心修剪植物,動作精準而優雅。 第3個鏡頭[4-7秒] 陽光透過透明穹頂灑下,照亮整個花園,展現科技與自然的完美融合。 第4個鏡頭[7-10秒] 鏡頭拉遠,展現整個未來城市的壯觀景象,空中花園只是其中的一部分。")
.negativePrompt("")
.size("1280*720")
.duration(10)
.shotType("multi")
.watermark(true)
.seed(12345)
.build();
// 非同步呼叫
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
//擷取結果
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan2.6-t2v",
"input": {
"prompt": "展現未來科技與自然和諧共存的美好願景。 第1個鏡頭[0-2秒] 未來城市的空中花園全景,懸浮植物在微風中搖曳。 第2個鏡頭[2-4秒] 機器人園丁正在精心修剪植物,動作精準而優雅。 第3個鏡頭[4-7秒] 陽光透過透明穹頂灑下,照亮整個花園,展現科技與自然的完美融合。 第4個鏡頭[7-10秒] 鏡頭拉遠,展現整個未來城市的壯觀景象,空中花園只是其中的一部分。"
},
"parameters": {
"size": "1280*720",
"watermark": true,
"duration": 10,
"shot_type": "multi"
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
實現聲畫同步
支援模型:wan3.0、wan2.7系列、wan2.6系列、wan2.5系列模型。
功能介紹:讓視頻畫面中的人物“開口說話”或唱歌,嘴型與音頻匹配。更多樣本請參見視頻聲音產生。
參數設定:
- 傳入音頻檔案:傳入
audio_url。模型會根據音頻檔案對齊口型。 - 自動配音:預設輸出有聲視頻,無需傳入
audio_url。模型會根據畫面自動產生背景音效、音樂或人聲。
| 輸入樣本 | 輸出視頻(有聲視頻) |
| 輸入提示詞:Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.輸入音頻: |
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於 1.25.16,可參考安裝SDK進行更新。
Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan3.0-video',
prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.",
audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
resolution='720P',
ratio='16:9',
duration=10,
watermark=True,
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
# 等待非同步任務結束
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_t2v()
請確保 DashScope Java SDK 版本不低於 2.22.14,可參考安裝SDK進行更新。
Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan3.0-video")
.prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.")
.audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
.resolution("720P")
.ratio("16:9")
.duration(10)
.watermark(true)
.seed(12345)
.build();
// 非同步呼叫
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
//擷取結果
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan3.0-video",
"input": {
"prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \". ",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3"
},
"parameters": {
"resolution": "720P",
"ratio": "16:9",
"watermark": true,
"duration": 10
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
範例程式碼:wan2.6模型
範例程式碼:wan2.6模型
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於 1.25.16,可參考安裝SDK進行更新。
Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-t2v',
prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.",
audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
size='1280*720',
duration=10,
watermark=True,
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
# 等待非同步任務結束
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_t2v()
請確保 DashScope Java SDK 版本不低於 2.22.14,可參考安裝SDK進行更新。
Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-t2v")
.prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.")
.audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
.negativePrompt("")
.size("1280*720")
.duration(10)
.watermark(true)
.seed(12345)
.build();
// 非同步呼叫
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
//擷取結果
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan2.6-t2v",
"input": {
"prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \"。",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3"
},
"parameters": {
"size": "1280*720",
"duration": 10
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
產生無聲視頻
支援模型:wan2.2系列模型、wan2.1系列模型。
功能介紹:適用於無需音訊純視覺展示情境,如動態海報、無聲短視頻等。
參數設定:wan2.2及以下版本模型,預設產生無聲視頻,無需額外配置。
| 輸入提示詞 | 輸出視頻(無聲視頻) |
| 邊緣光,低對比,中近景,日光,左側重構圖,乾淨的單人鏡頭,暖色調,柔光,晴天光,側光,白天,一個年輕的女孩坐在高草叢生的田野中,兩條毛髮蓬鬆的小毛驢站在她身後。女孩大約十一二歲,穿著簡單的碎花裙子,頭髮紮成兩條麻花辮,臉上帶著純真的笑容。她雙腿交叉坐下,雙手輕輕撫弄身旁的野花。小毛驢體型健壯,耳朵豎起,好奇地望著鏡頭方向。陽光灑在田野上,營造出溫暖自然的畫面感。 |
- Python SDK
- Java SDK
- curl
請確保 DashScope Python SDK 版本不低於 1.25.16,可參考安裝SDK進行更新。
Copy
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.2-t2v-plus',
prompt='邊緣光,低對比,中近景,日光,左側重構圖,乾淨的單人鏡頭,暖色調,柔光,晴天光,側光,白天,一個年輕的女孩坐在高草叢生的田野中,兩條毛髮蓬鬆的小毛驢站在她身後。女孩大約十一二歲,穿著簡單的碎花裙子,頭髮紮成兩條麻花辮,臉上帶著純真的笑容。她雙腿交叉坐下,雙手輕輕撫弄身旁的野花。小毛驢體型健壯,耳朵豎起,好奇地望著鏡頭方向。陽光灑在田野上,營造出溫暖自然的畫面感。',
size='832*480',
watermark=True,
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
# 等待非同步任務結束
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_t2v()
請確保 DashScope Java SDK 版本不低於 2.22.14,可參考安裝SDK進行更新。
Copy
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Text2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.2-t2v-plus")
.prompt("邊緣光,低對比,中近景,日光,左側重構圖,乾淨的單人鏡頭,暖色調,柔光,晴天光,側光,白天,一個年輕的女孩坐在高草叢生的田野中,兩條毛髮蓬鬆的小毛驢站在她身後。女孩大約十一二歲,穿著簡單的碎花裙子,頭髮紮成兩條麻花辮,臉上帶著純真的笑容。她雙腿交叉坐下,雙手輕輕撫弄身旁的野花。小毛驢體型健壯,耳朵豎起,好奇地望著鏡頭方向。陽光灑在田野上,營造出溫暖自然的畫面感。")
.size("832*480")
.watermark(true)
.seed(12345)
.build();
// 非同步呼叫
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
//擷取結果
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
步驟1:建立任務擷取任務ID步驟2:根據任務ID擷取結果將
Copy
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan2.2-t2v-plus",
"input": {
"prompt": "邊緣光,低對比,中近景,日光,左側重構圖,乾淨的單人鏡頭,暖色調,柔光,晴天光,側光,白天,一個年輕的女孩坐在高草叢生的田野中,兩條毛髮蓬鬆的小毛驢站在她身後。女孩大約十一二歲,穿著簡單的碎花裙子,頭髮紮成兩條麻花辮,臉上帶著純真的笑容。她雙腿交叉坐下,雙手輕輕撫弄身旁的野花。小毛驢體型健壯,耳朵豎起,好奇地望著鏡頭方向。陽光灑在田野上,營造出溫暖自然的畫面感。"
},
"parameters": {
"size": "832*480",
"watermark": true
}
}'
{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時,並請將{WorkspaceId}替換為真實的業務空間ID。Copy
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
如何傳入音頻
- 音頻數量:1個。
-
輸入方式:
- 公網 URL:支援 HTTP 或 HTTPS 協議。
輸出視頻
- 視頻數量:1個。
- 視頻規格:格式為MP4。具體請參見視頻規格。
- 視頻URL有效期間:24小時。
-
視頻尺寸:
- wan3.0、wan2.7通過
resolution(解析度檔位)和ratio(寬高比)指定; - wan2.6及早期模型通過
size指定。
- wan3.0、wan2.7通過
計費與限流
API文檔
文生視頻API參考常見問題
Q: 從 wan2.7 升級到 wan3.0,代碼需要改哪些地方?
- 模型名稱:將
model從wan2.7-t2v-*改為wan3.0-video。 - 移除 prompt_extend:wan3.0 不支援
prompt_extend參數,需刪除該欄位。 - 時間長度上限提升:wan3.0 支援最長 30 秒(wan2.7 為 15 秒),
duration可設為 2~30 之間的整數。 - 新增參考檔案和網頁輸入:wan3.0 支援在
input.media中傳入type: "file"(docx、ppt、pdf等)或type: "link"(公開網頁連結),模型自動理解內容產生視頻。兩者不可同時輸入。
Q: 控制台產生的視頻有浮水印,如何去除?
- 百鍊控制台的視頻產生介面不提供浮水印開關,無法在控制台關閉浮水印。
- 通過 API 呼叫模型時,將
watermark設定為false,即可產生不帶浮水印的視頻。 - 不傳
watermark參數時,API 預設會為視頻添加浮水印。本文範例程式碼均傳入watermark=true,如需去除浮水印,請改為false。
Q: 購買了 AI 通用節省計劃,為什麼產生的視頻仍有浮水印?
- AI 通用節省計劃僅用於費用抵扣,不改變模型輸出內容,與視頻是否帶浮水印無關。
- 視頻浮水印只由 API 的
watermark參數控制:設定為false可去除浮水印;不傳該參數時,預設添加浮水印。