Wan の開始フレームと終了フレームの動画生成モデルは、開始フレーム画像、終了フレーム画像、およびテキストプロンプトから、スムーズに遷移する動画を生成します。
リファレンス: ユーザーガイド
適用範囲
API 呼び出しを成功させるには、モデル、エンドポイント URL、API キーが同じリージョンに属している必要があります。リージョン間の呼び出しは失敗します。
-
モデルの選択:ご利用のモデルのリージョンを確認します。
-
URL の選択:ご利用のリージョンのエンドポイント URL を選択します。HTTP URL と DashScope SDK URL の両方がサポートされています。
-
API キーの設定:ご利用のリージョンを選択して API キーを取得し、その後 API キーを環境変数として設定します。
-
SDK のインストール:SDK を使用して API を呼び出す場合は、DashScope SDK をインストールします。
このトピックのサンプルコードはシンガポールリージョンに適用されます。
HTTP 呼び出し
image-to-video タスクは通常 1~5 分かかるため、API は非同期呼び出しを使用します。完全なプロセスには、タスクの作成 → 結果のポーリングという 2 つのコアステップがあります。
ステップ 1:タスクを作成し、task_id を取得する
シンガポール
POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis
北京
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis
タスクが作成された後、返された
task_idを使用して結果をクエリします。task_idの有効期限は 24 時間です。重複タスクを作成しないでください。代わりに、ポーリングを使用して結果を取得してください。初心者向けのチュートリアルについては、「Postman または cURL の使用」をご参照ください。
リクエストパラメーター |
開始フレームと終了フレームの動画生成開始フレーム、終了フレーム、およびプロンプトに基づいて動画を生成します。
ネガティブプロンプトの使用negative_prompt パラメーターを使用して、生成される動画に「人物」が含まれないようにします。
|
リクエストヘッダー |
|
|
Content-Type リクエストのコンテンツタイプです。 |
|
|
Authorization Model Studio API キーを使用した認証情報。 例: |
|
|
X-DashScope-Async 非同期処理を有効にします。HTTP リクエストは非同期処理のみをサポートしているため、値は 重要 このヘッダーを含めない場合、「current user api does not support synchronous calls」というエラーが返されます。 |
|
リクエストボディ |
|
|
model モデル名。例: wan2.2-kf2v-flash。 詳細については、「モデルリストと価格」をご参照ください。 |
|
|
input プロンプトなどの基本的な入力情報。 |
|
|
parameters 動画処理パラメーター。 |
レスポンスパラメーター |
成功レスポンス
エラーレスポンスタスクの作成に失敗しました。「エラーコード」を参照して問題を解決してください。 |
|
output タスクの出力情報。 |
|
|
request_id リクエストの一意の識別子。問題の追跡とトラブルシューティングに使用します。 |
|
|
code エラーコード。リクエストが失敗した場合にのみ返されます。詳細については、「エラーコード」をご参照ください。 |
|
|
message 詳細なエラーメッセージ。リクエストが失敗した場合にのみ返されます。詳細については、「エラーコード」をご参照ください。 |
ステップ 2:task_id で結果をクエリする
シンガポール
GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
北京
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
ポーリングの推奨事項:動画の生成には数分かかる場合があります。15 秒などの適切なクエリ間隔でポーリングメカニズムを使用して、結果を取得してください。
タスクステータスの遷移:PENDING → RUNNING → SUCCEEDED または FAILED。
結果の URL:タスクが成功すると、動画の URL が返されます。URL は 24 時間有効です。URL を取得した後、すぐに動画をダウンロードし、Object Storage Service (OSS) などの永続的なストレージサービスに保存する必要があります。
task_id の有効期間:24 時間。この期間を過ぎると、結果をクエリできなくなり、API はタスクステータスとして
UNKNOWNを返します。
リクエストパラメーター |
タスク結果のクエリ
API キーはリージョン固有です。詳細については、「API キードキュメント」をご参照ください。 北京リージョンのモデルの場合、base_url を |
リクエストヘッダー |
|
|
Authorization Model Studio API キーを使用した認証情報。 例: |
|
パスパラメーター |
|
|
task_id クエリするタスクの ID。 |
レスポンスパラメーター |
タスク成功動画 URL は 24 時間のみ保持され、その後自動的にパージされます。生成された動画は速やかに保存してください。
タスク失敗タスクが失敗すると、
タスククエリの期限切れ
|
|
output タスクの出力情報。 |
|
|
usage 使用量の統計。成功した結果のみをカウントします。 |
|
|
request_id リクエストの一意の識別子。問題の追跡とトラブルシューティングに使用します。 |
DashScope SDK の呼び出し
SDK のパラメーター名は、HTTP API のパラメーター名と一致します。パラメーターの構造は、言語固有の規則に従ってカプセル化されています。
image-to-video タスクは通常 1~5 分かかるため、SDK は HTTP 非同期呼び出しロジックをラップし、同期呼び出しと非同期呼び出しの両方をサポートします。
実際の処理時間は、キューの長さとサービスのパフォーマンスによって異なります。結果が出るまでお待ちください。
Python SDK の呼び出し
以下のコードを実行する前に、DashScope Python SDK のバージョンが少なくとも 1.23.8 であることを確認してください。
古いバージョンでは、「url error, please check url!」などのエラーが発生する可能性があります。SDK を更新するには、「SDK インストールガイド」をご参照ください。
モデルのリージョンに基づいて base_http_api_url を設定します:
シンガポール
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
北京
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
サンプルコード
同期呼び出し
この例では、パブリック URL とローカルファイルパスの 2 つの画像入力方法を使用した同期呼び出しを示します。
リクエスト例
import os
from http import HTTPStatus
# dashscope sdk >= 1.23.4
from dashscope import VideoSynthesis
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 環境変数から DashScope API キー (Model Studio API キー) を取得
api_key = os.getenv("DASHSCOPE_API_KEY")
# ========== 画像入力方法 (いずれかを選択) ==========
# [方法 1] パブリック画像 URL を使用
first_frame_url = "https://wanx.alicdn.com/material/20250318/first_frame.png"
last_frame_url = "https://wanx.alicdn.com/material/20250318/last_frame.png"
# [方法 2] ローカルファイルパスを使用 (file:// + ファイルパス)
# 絶対パスを使用
# first_frame_url = "file://" + "/path/to/your/first_frame.png" # Linux/macOS
# last_frame_url = "file://" + "C:/path/to/your/last_frame.png" # Windows
# または相対パスを使用
# first_frame_url = "file://" + "./first_frame.png" # 実際のパスを使用してください
# last_frame_url = "file://" + "./last_frame.png" # 実際のパスを使用してください
def sample_sync_call_kf2v():
print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model="wan2.2-kf2v-flash",
prompt="Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
first_frame_url=first_frame_url,
last_frame_url=last_frame_url,
resolution="720P",
prompt_extend=True)
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_sync_call_kf2v()
レスポンス例
video_url は 24 時間有効です。この時間内に必ず動画をダウンロードしてください。
{
"status_code": 200,
"request_id": "a37fafc3-907c-96f3-95a6-5b2a8268a3fd",
"code": null,
"message": "",
"output": {
"task_id": "4dba0092-da13-42b2-afb1-0f7b8a0f4643",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com/xxx.mp4?xxxxx",
"submit_time": "2025-05-23 15:50:12.404",
"scheduled_time": "2025-05-23 15:50:12.443",
"end_time": "2025-05-23 15:54:56.502",
"orig_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
"actual_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view. The cat's yellow eyes are bright and expressive, its ears are pricked up, and its whiskers are clearly visible. The background is a simple, light-colored wall, which highlights the cat's black fur and focused expression. A close-up shot emphasizes the change in the cat's gaze and posture."
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}
非同期呼び出し
この例では、非同期呼び出しを示します。すぐに task_id が返されます。その後、結果をポーリングするか、完了を待つ必要があります。
リクエスト例
import os
from http import HTTPStatus
# dashscope sdk >= 1.23.4
from dashscope import VideoSynthesis
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 環境変数から DashScope API キー (Model Studio API キー) を取得
api_key = os.getenv("DASHSCOPE_API_KEY")
# ========== 画像入力方法 (いずれかを選択) ==========
# [方法 1] パブリック画像 URL を使用
first_frame_url = "https://wanx.alicdn.com/material/20250318/first_frame.png"
last_frame_url = "https://wanx.alicdn.com/material/20250318/last_frame.png"
# [方法 2] ローカルファイルパスを使用 (file:// + ファイルパス)
# 絶対パスを使用
# first_frame_url = "file://" + "/path/to/your/first_frame.png" # Linux/macOS
# last_frame_url = "file://" + "C:/path/to/your/last_frame.png" # Windows
# または相対パスを使用
# first_frame_url = "file://" + "./first_frame.png" # 実際のパスを使用してください
# last_frame_url = "file://" + "./last_frame.png" # 実際のパスを使用してください
def sample_async_call_kf2v():
print('please wait...')
rsp = VideoSynthesis.async_call(api_key=api_key,
model="wan2.2-kf2v-flash",
prompt="Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
first_frame_url=first_frame_url,
last_frame_url=last_frame_url,
resolution="720P",
prompt_extend=True)
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))
# タスクステータスを含むタスク情報を取得します。
status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status) # タスクステータスを確認
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(status.status_code, status.code, status.message))
# タスクが完了するのを待ちます。fetch を定期的に呼び出し、完了ステータスにあるか確認します。
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_kf2v()
レスポンス例
1. タスク作成のレスポンス
{
"status_code": 200,
"request_id": "c86ff7ba-8377-917a-90ed-xxxxxx",
"code": "",
"message": "",
"output": {
"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
"task_status": "PENDING",
"video_url": ""
},
"usage": null
}
2. タスク結果クエリのレスポンス
video_url は 24 時間有効です。この時間内に必ず動画をダウンロードしてください。
{
"status_code": 200,
"request_id": "efa545b3-f95c-9e3a-a3b6-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?xxxxx",
"submit_time": "2025-02-12 11:03:30.701",
"scheduled_time": "2025-02-12 11:06:05.378",
"end_time": "2025-02-12 11:12:18.853",
"orig_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
"actual_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view. The cat's fur is jet black and shiny, its eyes are large and bright with golden pupils. It looks up with its ears pricked, appearing exceptionally focused. After the camera moves up, the cat turns to look directly at the camera, its eyes full of curiosity and alertness. The background is simple, highlighting the cat's detailed features. A close-up shot with soft, natural light."
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}
Java SDK の呼び出し
以下のコードを実行する前に、DashScope Java SDK のバージョンが少なくとも 2.20.9 であることを確認してください。
古いバージョンでは、「url error, please check url!」などのエラーが発生する可能性があります。SDK を更新するには、「SDK インストールガイド」をご参照ください。
サンプルコード
同期呼び出し
この例では、パブリック URL とローカルファイルパスの 2 つの画像入力方法を使用した同期呼び出しを示します。
リクエスト例
// Copyright (c) Alibaba, Inc. and its affiliates.
// dashscope sdk >= 2.20.1
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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
import java.util.Map;
public class Kf2vSyncIntl {
static {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数から DashScope API キー (Model Studio API キー) を取得
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 画像入力方法 (いずれかを選択):
*
* [方法 1] パブリック URL
*/
static String firstFrameUrl = "https://wanx.alicdn.com/material/20250318/first_frame.png";
static String lastFrameUrl = "https://wanx.alicdn.com/material/20250318/last_frame.png";
/**
* [方法 2] ローカルファイルパス (file:// + 絶対パス または file:/// + 絶対パス)
*/
// static String firstFrameUrl = "file://" + "/your/path/to/first_frame.png"; // Linux/macOS
// static String lastFrameUrl = "file:///" + "C:/path/to/your/img.png"; // Windows
public static void syncCall() {
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("resolution", "720P");
VideoSynthesis videoSynthesis = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.2-kf2v-flash")
.prompt("Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.")
.firstFrameUrl(firstFrameUrl)
.lastFrameUrl(lastFrameUrl)
.parameters(parameters)
.build();
VideoSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = videoSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
} catch (InputRequiredException e) {
throw new RuntimeException(e);
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
syncCall();
}
}
レスポンス例
video_url は 24 時間有効です。この時間内に必ず動画をダウンロードしてください。
{
"request_id": "e6bb4517-c073-9c10-b748-dedb8c11bb41",
"output": {
"task_id": "984784fe-83c1-4fc4-88c7-52c2c1fa92a2",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com/xxx.mp4?xxxxx"
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}
非同期呼び出し
この例では、非同期呼び出しを示します。すぐに task_id が返されます。その後、結果をポーリングするか、完了を待つ必要があります。
リクエスト例
// Copyright (c) Alibaba, Inc. and its affiliates.
// dashscope sdk >= 2.20.1
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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
import java.util.Map;
public class Kf2vAsync {
static {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数から DashScope API キー (Model Studio API キー) を取得
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 画像入力方法 (いずれかを選択)
*
* [方法 1] パブリック URL
*/
static String firstFrameUrl = "https://wanx.alicdn.com/material/20250318/first_frame.png";
static String lastFrameUrl = "https://wanx.alicdn.com/material/20250318/last_frame.png";
/**
* [方法 2] ローカルファイルパス (file:// + 絶対パス または file:/// + 絶対パス)
*/
// static String firstFrameUrl = "file://" + "/your/path/to/first_frame.png"; // Linux/macOS
// static String lastFrameUrl = "file:///" + "C:/path/to/your/img.png"; // Windows
public static void asyncCall(){
// パラメーターを設定
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("resolution", "720P");
VideoSynthesis videoSynthesis = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.2-kf2v-flash")
.prompt("Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.")
.firstFrameUrl(firstFrameUrl)
.lastFrameUrl(lastFrameUrl)
.parameters(parameters)
.build();
VideoSynthesisResult result = null;
try {
System.out.println("---async call, please wait a moment----");
result = videoSynthesis.asyncCall(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
} catch (InputRequiredException e) {
throw new RuntimeException(e);
}
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
System.out.println("taskId=" + taskId);
try {
result = videoSynthesis.wait(taskId, apiKey);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
System.out.println(JsonUtils.toJson(result.getOutput()));
}
public static void main(String[] args){
asyncCall();
}
}
レスポンス例
1. タスク作成のレスポンス
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}
2. タスク結果クエリのレスポンス
video_url は 24 時間有効です。この時間内に必ず動画をダウンロードしてください。
{
"request_id": "1625235c-c13e-93ec-aff7-xxxxxxxx",
"output": {
"task_id": "464a5e46-79a6-46fd-9823-xxxxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?xxxxxx"
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}
制限事項
-
データ保持:
task_idおよびvideo_urlは 24 時間保持されます。有効期限が切れた後、それらを照会またはダウンロードできません。 -
音声サポート:このサービスは無音の動画のみを生成します。音声出力はサポートされていません。音声を生成するには、音声合成サービスを使用してください。
-
Content Moderation:Content Moderation は、すべての入力プロンプト、画像、および出力動画をレビューします。コンテンツが当社のポリシーに違反する場合、システムは「IPInfringementSuspect」または「DataInspectionFailed」エラーを返します。詳細については、「エラーメッセージ」をご参照ください。
エラーコード
モデルの呼び出しが失敗し、エラーメッセージが返された場合は、「エラーメッセージ」を参照してトラブルシューティングを行ってください。
よくある質問
Q:3:4 のような特定のアスペクト比で動画を生成するにはどうすればよいですか?
A:出力動画のアスペクト比は、開始フレーム画像 (first_frame_url) によって決まります。ただし、厳密な 3:4 のような正確な比率は保証されず、わずかに異なる場合があります。
-
なぜずれが生じるのですか?
モデルは、入力画像のアスペクト比をベースラインとして使用し、解像度設定で指定された総ピクセル数に基づいて最も近い有効な解像度を自動的に計算します。動画のディメンションは 16 の倍数でなければならないため、モデルは最終的な解像度を微調整します。その結果、出力のアスペクト比は正確に 3:4 にならない場合がありますが、非常に近くなります。
-
例:入力画像 750 × 1000 (アスペクト比 3:4 = 0.75)、解像度を「720P」に設定 (目標総ピクセル数 ≈ 920,000);実際の出力は 816 × 1104 (アスペクト比 ≈ 0.739、総ピクセル数 ≈ 900,000)。
-
-
ベストプラクティス:
-
入力の制御:目標にできるだけ近いアスペクト比の開始フレーム画像を使用します。
-
後処理:正確な比率が必要な場合は、編集ツールを使用して生成された動画をトリミングするか、黒帯を追加します。
-
Q:動画ストレージのドメイン名ホワイトリストを取得するにはどうすればよいですか?
A:モデルによって生成された動画は OSS に保存されます。API は一時的なパブリック URL を返します。このダウンロード URL のファイアウォールホワイトリストを設定するには、次の点にご注意ください:基盤となるストレージは動的に変更される可能性があります。このトピックでは、古い情報によるアクセス問題を避けるため、固定の OSS ドメイン名ホワイトリストは提供していません。セキュリティ管理要件がある場合は、アカウントマネージャーに連絡して最新の OSS ドメイン名リストを取得してください。