萬相-圖生視頻模型支援多模態輸入(文本/映像/音頻),可產生最長15秒、解析度為1080P的視頻。
-
基礎設定:支援整數級視頻時間長度(2~15 秒)、指定視頻解析度(480P/720P/1080P)、智能改寫prompt、添加浮水印。
-
音頻能力:支援自動配音或上傳音頻,實現聲畫同步。(wan2.5、wan2.6支援)
-
多鏡頭敘事:可產生包含多個鏡頭的視頻,鏡頭切換時保持主體一致。(僅wan2.6支援)
快速開始
|
輸入提示詞 |
輸入首幀映像 |
輸出視頻(多鏡頭,有聲視頻) |
|
鏡頭從海龜下方緩緩上移,海龜悠然遊動,腹部細節清晰可見。 |
|
在調用前,先擷取API Key與API Host,再配置API Key到環境變數(準備下線,併入配置 API Key)。通過SDK進行調用,請安裝DashScope SDK。
Python SDK
請確保 DashScope Python SDK 版本不低於 1.25.8,再運行以下代碼。
若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.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-i2v-flash',
prompt='鏡頭從海龜下方緩緩上移,海龜悠然遊動,腹部細節清晰可見。',
img_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260121/zlpocv/wan-i2v-haigui.webp",
resolution="720P",
duration=10,
shot_type="multi",
prompt_extend=True,
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))
Java SDK
請確保 DashScope Java SDK 版本不低於 2.22.6,再運行以下代碼。
若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。
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 Image2Video {
static {
// 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.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 image2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("鏡頭從海龜下方緩緩上移,海龜悠然遊動,腹部細節清晰可見。")
.imgUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260121/zlpocv/wan-i2v-haigui.webp")
.duration(10)
.resolution("720P")
.shotType("multi")
.promptExtend(true)
.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 {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
curl
步驟1:建立任務擷取任務ID
curl --location 'https://dashscope-intl.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-i2v-flash",
"input": {
"prompt": "鏡頭從海龜下方緩緩上移,海龜悠然遊動,腹部細節清晰可見。",
"img_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260121/zlpocv/wan-i2v-haigui.webp"
},
"parameters": {
"resolution": "720P",
"prompt_extend": true,
"watermark": true,
"duration": 10,
"shot_type":"multi"
}
}'
步驟2:根據任務ID擷取結果
將{task_id}完整替換為上一步介面返回的task_id的值。
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"輸出樣本
video_url 有效期間24小時,請及時下載視頻。{
"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 均屬於同一地區,跨地區調用將會失敗。
支援的模型:
全球
在全球部署模式下,存取點與資料存放區均位於美國(維吉尼亞)地區,模型推理計算資源在全球範圍內動態調度。
模型名稱 | 能力支援 | 輸入模態 | 輸出視頻規格 |
wan2.6-i2v | 有聲視頻 多鏡頭敘事、聲畫同步 | 文本、映像、音頻 | 解析度檔位:720P、1080P 視頻時間長度:5s、10s 、15s 固定規格:30fps、MP4 (H.264編碼) |
國際
在國際部署模式下,存取點與資料存放區均位於新加坡地區,模型推理計算資源在全球範圍內動態調度(不含中國內地)。
模型名稱 | 能力支援 | 輸入模態 | 輸出視頻規格 |
wan2.6-i2v-flash | 有聲視頻、無聲視頻 多鏡頭敘事、聲畫同步 | 文本、映像、音頻 | 解析度檔位:720P、1080P 視頻時間長度:[2s, 15s](整數) 固定規格:30fps、MP4 (H.264編碼) |
wan2.6-i2v | 有聲視頻 多鏡頭敘事、聲畫同步 | 文本、映像、音頻 | 解析度檔位:720P、1080P 視頻時間長度:[2s, 15s](整數) 固定規格:30fps、MP4 (H.264編碼) |
wan2.5-i2v-preview | 有聲視頻 聲畫同步 | 文本、映像、音頻 | 解析度檔位:480P、720P、1080P 視頻時間長度:5s、10s 固定規格:30fps、MP4 (H.264編碼) |
wan2.2-i2v-flash | 無聲視頻 較2.1模型速度提升50% | 文本、映像 | 解析度檔位:480P、720P、1080P 視頻時間長度:5s 固定規格:30fps、MP4 (H.264編碼) |
wan2.2-i2v-plus | 無聲視頻 較2.1模型穩定性與成功率全面提升 | 文本、映像 | 解析度檔位:480P、1080P 視頻時間長度:5s 固定規格:30fps、MP4 (H.264編碼) |
wan2.1-i2v-plus | 無聲視頻 | 文本、映像 | 解析度檔位:720P 視頻時間長度:5s 固定規格:30fps、MP4 (H.264編碼) |
wan2.1-i2v-turbo | 無聲視頻 | 文本、映像 | 解析度檔位:480P、720P 視頻時間長度:3s、4s、5s 固定規格:30fps、MP4 (H.264編碼) |
美國
在美國部署模式下,存取點與資料存放區均位於美國(維吉尼亞)地區,模型推理計算資源僅限於美國境內。
模型名稱 | 能力支援 | 輸入模態 | 輸出視頻規格 |
wan2.6-i2v-us | 有聲視頻 多鏡頭敘事、聲畫同步 | 文本、映像、音頻 | 解析度檔位:720P、1080P 視頻時間長度:5s、10s 、15s 固定規格:30fps、MP4 (H.264編碼) |
中國內地
在中國內地部署模式下,存取點與資料存放區均位於北京地區,模型推理計算資源僅限於中國內地。
模型名稱 | 能力支援 | 輸入模態 | 輸出視頻規格 |
wan2.6-i2v-flash | 有聲視頻、無聲視頻 多鏡頭敘事、聲畫同步 | 文本、映像、音頻 | 解析度檔位:720P、1080P 視頻時間長度:[2s, 15s](整數) 固定規格:30fps、MP4 (H.264編碼) |
wan2.6-i2v | 有聲視頻 多鏡頭敘事、聲畫同步 | 文本、映像、音頻 | 解析度檔位:720P、1080P 視頻時間長度:[2s, 15s](整數) 固定規格:30fps、MP4 (H.264編碼) |
wan2.5-i2v-preview | 有聲視頻 聲畫同步 | 文本、映像、音頻 | 解析度檔位:480P、720P、1080P 視頻時間長度:5s、10s 固定規格:30fps、MP4 (H.264編碼) |
wan2.2-i2v-flash | 無聲視頻 較2.1模型速度提升50% | 文本、映像 | 解析度檔位:480P、720P、1080P 視頻時間長度:5s 固定規格:30fps、MP4 (H.264編碼) |
wan2.2-i2v-plus | 無聲視頻 較2.1模型穩定性與成功率全面提升 | 文本、映像 | 解析度檔位:480P、1080P 視頻時間長度:5s 固定規格:30fps、MP4 (H.264編碼) |
wanx2.1-i2v-plus | 無聲視頻 | 文本、映像 | 解析度檔位:720P 視頻時間長度:5s 固定規格:30fps、MP4 (H.264編碼) |
wanx2.1-i2v-turbo | 無聲視頻 | 文本、映像 | 解析度檔位:480P、720P 視頻時間長度:3s、4s、5s 固定規格:30fps、MP4 (H.264編碼) |
本文的範例程式碼適用於新加坡地區。
核心能力
製作多鏡頭視頻
支援模型:wan2.6系列模型。
功能介紹:模型可自動進行分鏡切換,例如從全景切換到特寫,適合製作MV等情境。
參數設定:
-
shot_type: 必須設為"multi"。 -
prompt_extend: 必須設為true(開啟智能改寫以最佳化分鏡描述)。
|
輸入提示詞 |
輸入首幀映像 |
輸出視頻(wan2.6,多鏡頭視頻) |
|
一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由rap構成,沒有其他對話或雜音。 |
輸入音頻: |
Python SDK
請確保 DashScope Python SDK 版本不低於 1.25.8,可參考安裝SDK進行更新。import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.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_i2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由rap構成,沒有其他對話或雜音。',
img_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png",
audio_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3",
resolution="720P",
duration=10,
shot_type="multi", # 多鏡頭
prompt_extend=True,
watermark=True,
negative_prompt="",
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_i2v()
Java SDK
請確保 DashScope Java SDK 版本不低於 2.22.6,可參考安裝SDK進行更新。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 Image2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.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");
//設定輸入映像url
static String imgUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png";
// 設定音頻audio url
static String audioUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3";
public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由rap構成,沒有其他對話或雜音。")
.imgUrl(imgUrl)
.audioUrl(audioUrl)
.shotType("multi")
.duration(10)
.resolution("720P")
.negativePrompt("")
.promptExtend(true)
.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 {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
curl
步驟1:建立任務擷取任務ID
curl --location 'https://dashscope-intl.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-i2v-flash",
"input": {
"prompt": "一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由他的rap構成,沒有其他對話或雜音。",
"img_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
},
"parameters": {
"resolution": "720P",
"prompt_extend": true,
"duration": 10,
"shot_type":"multi"
}
}'
步驟2:根據任務ID擷取結果
將{task_id}完整替換為上一步介面返回的task_id的值。
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"實現聲畫同步
支援模型:wan2.5和wan2.6系列模型。
功能介紹:讓照片中的人物“開口說話”或唱歌,嘴型與音頻匹配。更多樣本請參見視頻聲音產生。
參數設定:
-
傳入音頻檔案:傳入
audio_url。模型會根據音頻檔案對齊口型。 -
自動配音:無需傳入
audio_url,預設輸出有聲視頻。模型會根據畫面自動產生背景音效、音樂或人聲。
|
輸入提示詞 |
輸入首幀映像 |
輸出視頻(有聲視頻) |
|
一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由rap構成,沒有其他對話或雜音。 |
輸入音頻: |
Python SDK
請確保 DashScope Python SDK 版本不低於 1.25.8,可參考安裝SDK進行更新。import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.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_i2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由rap構成,沒有其他對話或雜音。',
img_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png",
audio_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3",
resolution="720P",
duration=10,
prompt_extend=True,
watermark=True,
negative_prompt="",
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_i2v()
Java SDK
請確保 DashScope Java SDK 版本不低於 2.22.6,可參考安裝SDK進行更新。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 Image2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.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");
//設定輸入映像url
static String imgUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png";
// 設定音頻audio url
static String audioUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3";
public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由rap構成,沒有其他對話或雜音。")
.imgUrl(imgUrl)
.audioUrl(audioUrl)
.duration(10)
.resolution("720P")
.negativePrompt("")
.promptExtend(true)
.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 {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
curl
步驟1:建立任務擷取任務ID
傳入音頻檔案
curl --location 'https://dashscope-intl.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.5-i2v-preview",
"input": {
"prompt": "一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由他的rap構成,沒有其他對話或雜音。",
"img_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
},
"parameters": {
"resolution": "480P",
"prompt_extend": true,
"duration": 10
}
}'
自動配音
curl --location 'https://dashscope-intl.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.5-i2v-preview",
"input": {
"prompt": "一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由他的rap構成,沒有其他對話或雜音。",
"img_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
},
"parameters": {
"resolution": "480P",
"prompt_extend": true,
"duration": 10
}
}'
步驟2:根據任務ID擷取結果
將{task_id}完整替換為上一步介面返回的task_id的值。
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"產生無聲視頻
支援模型:wan2.6-i2v-flash、wan2.2系列模型、wan2.1系列模型。
功能介紹:適用於無需音訊純視覺展示情境,如動態海報、無聲短視頻等。
參數設定:
-
wan2.6-i2v-flash:預設產生有聲視頻。若需產生無聲視頻,必須顯式設定audio=false。即使傳入audio_url,只要audio=false,輸出仍為無聲視頻,並按無聲視頻計費。 -
wan2.2及以下版本模型:預設產生無聲視頻,無需額外配置。
|
提示詞 |
輸入首幀映像 |
輸出視頻(無聲視頻) |
|
一隻貓在草地上奔跑 |
|
Python SDK
請確保 DashScope Python SDK 版本不低於 1.25.8,可參考安裝SDK進行更新。import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下為新加坡地區URL,各地區的URL不同,擷取URL:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.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_i2v():
# 非同步呼叫,返回一個task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='一隻貓在草地上奔跑',
img_url="https://cdn.translate.alibaba.com/r/wanx-demo-1.png",
audio=False, # 必須顯式設定為False,表示輸出無聲視頻
resolution="720P",
duration=5,
prompt_extend=True,
watermark=True,
negative_prompt="",
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_i2v()
Java SDK
請確保 DashScope Java SDK 版本不低於 2.22.6,可參考安裝SDK進行更新。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 Image2Video {
static {
// 以下為新加坡地區url,各地區的url不同,擷取url:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.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 image2video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("一隻貓在草地上奔跑")
.imgUrl("https://cdn.translate.alibaba.com/r/wanx-demo-1.png")
.audio(false) /*必須顯式設定為false,表示輸出無聲視頻*/
.duration(10)
.resolution("720P")
.negativePrompt("")
.promptExtend(true)
.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 {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
curl
步驟1:建立任務擷取任務ID
wan2.6-i2v-flash
curl --location 'https://dashscope-intl.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-i2v-flash",
"input": {
"prompt": "一隻貓在草地上奔跑",
"img_url": "https://cdn.translate.alibaba.com/r/wanx-demo-1.png"
},
"parameters": {
"audio": false,
"resolution": "720P",
"prompt_extend": true,
"watermark": true,
"duration": 5
}
}'
wan2.2及以下版本模型
curl --location 'https://dashscope-intl.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-i2v-plus",
"input": {
"prompt": "一隻貓在草地上奔跑",
"img_url": "https://cdn.translate.alibaba.com/r/wanx-demo-1.png"
},
"parameters": {
"resolution": "480P",
"prompt_extend": true
}
}'
步驟2:根據任務ID擷取結果
將{task_id}完整替換為上一步介面返回的task_id的值。
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
如何傳入映像和音頻
傳入映像
-
映像個數:1個。
-
輸入方式:映像URL、本地檔案路徑、Base 64 編碼字串。
範例程式碼:三種輸入方式
Python SDK
import base64
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import mimetypes
import dashscope
# 以下為新加坡地區url,擷取url:https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- 輔助函數:用於 Base 64 編碼 ---
# 格式為 data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("不支援或無法識別的映像格式")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return f"data:{mime_type};base64,{encoded_string}"
"""
映像輸入方式說明:
以下提供了三種圖片輸入方式,
1. 使用公網URL - 適合已有公開可訪問的圖片
2. 使用本地檔案 - 適合本地開發測試
3. 使用Base64編碼 - 適合私人圖片或需要加密傳輸的情境
"""
# 【方式一】使用公網可訪問的圖片URL
# 樣本:使用一個公開的圖片URL
img_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
# 【方式二】使用本地檔案(支援絕對路徑和相對路徑)
# 格式要求:file:// + 檔案路徑
# 樣本(絕對路徑):
# img_url = "file://" + "/path/to/your/img.png" # Linux/macOS
# img_url = "file://" + "/C:/path/to/your/img.png" # Windows
# 樣本(相對路徑):
# img_url = "file://" + "./img.png" # 相對當前執行檔案的路徑
# 【方式三】使用Base64編碼的圖片
# img_url = encode_file("./img.png")
# 設定音頻audio url
audio_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
def sample_call_i2v():
# 同步調用,直接返回結果
print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由他的rap構成,沒有其他對話或雜音。',
img_url=img_url,
audio_url=audio_url,
resolution="720P",
duration=10,
prompt_extend=True,
watermark=False,
negative_prompt="",
seed=12345)
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))
if __name__ == '__main__':
sample_call_i2v()Java SDK
// Copyright (c) Alibaba, Inc. and its affiliates.
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;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class Image2Video {
static {
// 以下為新加坡地區url,擷取url: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
// 擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 映像輸入方式說明:三選一即可
*
* 1. 使用公網URL - 適合已有公開可訪問的圖片
* 2. 使用本地檔案 - 適合本地開發測試
* 3. 使用Base64編碼 - 適合私人圖片或需要加密傳輸的情境
*/
//【方式一】公網URL
static String imgUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png";
//【方式二】本地檔案路徑(file://+絕對路徑)
// static String imgUrl = "file://" + "/your/path/to/img.png"; // Linux/macOS
// static String imgUrl = "file://" + "/C:/your/path/to/img.png"; // Windows
//【方式三】Base64編碼
// static String imgUrl = Image2Video.encodeFile("/your/path/to/img.png");
// 設定音頻audio url
static String audioUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3";
public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
// 設定parameters參數
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("一幅都市奇幻藝術的情境。一個充滿動感的塗鴉藝術角色。一個由噴漆所畫成的少年,正從一面混凝土牆上活過來。他一邊用極快的語速演唱一首英文rap,一邊擺著一個經典的、充滿活力的饒舌歌手姿勢。情境設定在夜晚一個充滿都市感的鐵路橋下。燈光來自一盞孤零零的街燈,營造齣電影般的氛圍,充滿高能量和驚人的細節。視頻的音頻部分完全由他的rap構成,沒有其他對話或雜音。")
.imgUrl(imgUrl)
.audioUrl(audioUrl)
.duration(10)
.parameters(parameters)
.resolution("720P")
.negativePrompt("")
.build();
System.out.println("please wait...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
/**
* 將檔案編碼為Base64字串
* @param filePath 檔案路徑
* @return Base64字串,格式為 data:{MIME_type};base64,{base64_data}
*/
public static String encodeFile(String filePath) {
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
throw new IllegalArgumentException("檔案不存在: " + filePath);
}
// 檢測MIME類型
String mimeType = null;
try {
mimeType = Files.probeContentType(path);
} catch (IOException e) {
throw new IllegalArgumentException("無法檢測檔案類型: " + filePath);
}
if (mimeType == null || !mimeType.startsWith("image/")) {
throw new IllegalArgumentException("不支援或無法識別的映像格式");
}
// 讀取檔案內容並編碼
byte[] fileBytes = null;
try{
fileBytes = Files.readAllBytes(path);
} catch (IOException e) {
throw new IllegalArgumentException("無法讀取檔案內容: " + filePath);
}
String encodedString = Base64.getEncoder().encodeToString(fileBytes);
return "data:" + mimeType + ";base64," + encodedString;
}
public static void main(String[] args) {
try {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}傳入音頻
-
音頻個數:1個。
-
輸入方式:
-
公網 URL:支援 HTTP 或 HTTPS 協議。
-
輸出視頻
-
視頻個數:1個。
-
輸出視頻規格:不同模型支援的輸出規格有所差異,請參見適用範圍。
-
輸出視頻URL有效期間:24小時。
-
輸出視頻尺寸:由輸入映像和設定的解析度
resolution決定。-
模型將盡量保持輸入映像的寬高比不變,縮放至總像素數接近目標值。因編碼規範,長寬必須被16整除,模型會自動微調尺寸。
-
例如:輸入映像750×1000(寬高比 3:4 = 0.75),設定 resolution = "720P"(目標總像素約 92 萬)。最終輸出可能為 816 × 1104(寬高比 ≈ 0.739,總像素 ≈ 90 萬),且長寬均為 16 的倍數。
-
計費與限流
API文檔
常見問題
Q: 為什麼不能直接設定視頻寬高比(如 16:9)?
A:當前 API 不支援直接指定視頻寬高比。您只能通過 resolution 參數設定視頻的解析度。
resolution 控制的是視頻的總像素數量,而非固定比例。模型會優先保留輸入首幀映像的原始寬高比(近似),並在此基礎上進行微調,以滿足視頻編碼要求(即長和寬均需為 16 的整數倍)。
Q: 為什麼運行SDK代碼時出現 “url error, please check url!” 錯誤?
A:請確保:
-
DashScope Python SDK 版本不低於
1.25.8。 -
DashScope Java SDK 版本不低於
2.22.6。
若版本過低,可能會觸發 “url error, please check url!” 的錯誤。請參考升級SDK進行更新。


