Wan 画像動画生成モデルは、 開始フレーム画像 と テキストプロンプト からスムーズな動画を生成します。
関連ドキュメント: ユーザーガイド
注記Wan 2.7 - 画像動画生成は、開始フレームからの動画生成、開始・終了フレームからの動画生成、および動画継続生成をサポートしています。このバージョンの利用を推奨します。
Wan 2.6 以前のモデルの 画像動画生成 (開始フレームに基づく) 機能は、開始フレームからの動画生成のみをサポートしています。
可用性
ご利用のモデル、エンドポイント URL、API キーは同じリージョンにある必要があります。リージョン間の呼び出しは失敗します。
- モデルの選択:モデルが利用可能なリージョンを確認します。
- URL の選択:対応するリージョンのエンドポイント URL を選択します。HTTP と DashScope SDK の両方の URL がサポートされています。
- API キーの設定:リージョンの API キーを取得し、環境変数に API キーを設定します。
- SDK のインストール:SDK で呼び出しを行うには、DashScope SDK をインストールします。
注記このトピックのサンプルコードは、シンガポールリージョン用です。
重要Alibaba Cloud Model Studio は、中国 (北京) およびシンガポールリージョン向けにワークスペース固有のドメインをリリースしました。新しい専用ドメインは、推論リクエストに対して優れたパフォーマンスと高い安定性を提供します。新しいドメインへの移行を推奨します:
- 中国 (北京):
https://dashscope.aliyuncs.comからhttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com - シンガポール:
https://dashscope-intl.aliyuncs.comからhttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} は、Alibaba Cloud Model Studio コンソールの [ワークスペース詳細] ページで確認できるワークスペース ID です。既存のドメインも引き続き完全に機能します。
HTTP 呼び出し
画像動画生成タスクは非同期呼び出し (通常 1~5 分) を使用します:タスクの作成 -> 結果のポーリング。
ステップ 1:タスクの作成
シンガポール
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
バージニア
POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
北京
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
フランクフルト
POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
{WorkspaceId} を実際の ワークスペース ID に置き換えてください。
注記
- タスク作成後、返された
task_idを使用して結果をクエリします。task_idは 24 時間有効です。重複タスクを作成しないでください。代わりに、ポーリングを使用して結果を取得してください。 - 初心者向けのガイダンスについては、「Postman または cURL で API を呼び出す」をご参照ください。
リクエストパラメーターヘッダーContent-Type リクエストのコンテンツタイプは Authorization Model Studio API キーでリクエストを認証します。例:Bearer sk-xxxx。 X-DashScope-Async 非同期処理を有効にします。HTTP リクエストは非同期呼び出しのみをサポートします。値は 重要このリクエストヘッダーがない場合、「current user api does not support synchronous calls」というエラーが返されます。 リクエストボディmodel モデル名。利用可能なモデルと料金:モデルの料金。 例:wan2.6-i2v-flash。 input プロンプトを含む入力フィールド。 parameters 解像度、持続時間、インテリジェントなプロンプトリライト、およびウォーターマークのコントロール。 | マルチショットナラティブこの機能は、Wan2.6 シリーズモデルでのみサポートされています。
自動吹き替えこの機能は、Wan2.6 および Wan2.5 シリーズモデルでのみサポートされています。
カスタム音声この機能は、Wan2.6 および Wan2.5 シリーズモデルでのみサポートされています。 動画に BGM やナレーションを指定するには、 無音動画無音動画の生成をサポートしているのは、以下のモデルのみです:
ネガティブプロンプトnegative_prompt パラメーターを使用して、生成される動画に「花」が現れないようにします。 |
レスポンスパラメーターoutput タスクの出力に関する情報。 request_id 追跡とトラブルシューティングのためのユニークなリクエスト識別子。 code エラーコード。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。 message 詳細なエラーメッセージ。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。 | 成功レスポンス
エラーレスポンスタスクの作成に失敗しました。「エラーコード」をご参照ください。 |
ステップ 2:タスク結果のクエリ
シンガポール
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
バージニア
GET https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
中国 (北京)
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
フランクフルト
GET https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
{WorkspaceId} を実際の ワークスペース ID に置き換えてください。
注記
- ポーリングの推奨事項:動画生成には数分かかります。15 秒などの適切な間隔でポーリングメカニズムを使用してください。
- タスク状態の遷移:PENDING → RUNNING → SUCCEEDED または FAILED。
- 結果リンク:タスクが成功すると、24 時間有効な動画 URL が返されます。動画をダウンロードして、OSS などの永続ストレージに保存してください。
task_idの有効期間:24 時間。この期間を過ぎると、クエリはタスクステータスをUNKNOWNとして返します。
リクエストパラメーターヘッダーAuthorization Model Studio API キーでリクエストを認証します。例:Bearer sk-xxxx。 パスパラメーターtask_id タスクの ID。 | タスク結果のクエリ
|
レスポンスパラメーターoutput タスクの出力詳細。 usage タスクの使用量統計。成功したタスクに対してのみカウントされます。 request_id 追跡とトラブルシューティングのためのユニークなリクエスト識別子。 | タスク成功動画 URL は 24 時間のみ有効で、その後自動的に消去されます。生成された動画は速やかに保存してください。 タスク失敗タスクが失敗すると、 タスククエリの期限切れ
|
DashScope SDK 呼び出し
SDK のパラメーター名は、各言語の規則に従い、HTTP API とほぼ一致しています。
画像動画生成タスクは通常 1~5 分かかります。SDK は非同期 HTTP 呼び出しプロセスをラップし、同期呼び出しと非同期呼び出しの両方をサポートします。
処理時間はタスクキューとサービスステータスに依存します。
Python SDK
重要以下のコードを実行する前に、DashScope Python SDK のバージョンが少なくとも1.25.8 であることを確認してください。
古いバージョンでは、「url error, please check url!」などのエラーが発生する可能性があります。更新するには、「SDK のインストール」をご参照ください。
モデルのリージョンに応じて base_http_api_url を設定します:
シンガポール
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
バージニア
dashscope.base_http_api_url = 'https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1'
北京
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
フランクフルト
dashscope.base_http_api_url = 'https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1'
{WorkspaceId} を実際の ワークスペース ID に置き換えてください。
サンプルコード
同期呼び出し
同期呼び出しは、動画生成が完了するまでブロックします。この例では、パブリック URL、Base64 エンコーディング、ローカルファイルパスの 3 つの画像入力方法を示します。
リクエスト例
import base64
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import mimetypes
import dashscope
# 次の URL はシンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 環境変数が設定されていない場合は、次の行を Model Studio の API キーに置き換えてください:api_key="sk-xxx"
# API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- Base64 エンコーディングのヘルパー関数 ---
# フォーマット: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("Unsupported or unrecognized image format")
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}"
"""
画像入力方法:
以下は画像を指定する 3 つの方法です。いずれか 1 つを選択してください。
1. パブリック URL:すでに公開されている画像に最適です。
2. ローカルファイル:ローカルでの開発やテストに適しています。
3. Base64 エンコーディング:非公開の画像や、データを安全に転送する必要がある場合に最適です。
"""
# [方法 1] 公開されている画像 URL を使用する
# 例:公開画像 URL を使用
img_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
# [方法 2] ローカルファイルを使用する (絶対パスと相対パスをサポート)
# フォーマット: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" # 現在のスクリプトのディレクトリからの相対パス
# [方法 3] Base64 エンコードされた画像を使用する
# img_url = encode_file("./img.png")
# 音声 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='A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.',
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()
レスポンス例
video_url は 24 時間有効です。有効期限が切れる前に動画をダウンロードしてください。
{
"status_code": 200,
"request_id": "2794c7a3-fe8c-4dd4-a1b7-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "c15d5b14-07c4-4af5-b862-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2026-01-22 23:24:46.527",
"scheduled_time": "2026-01-22 23:24:46.565",
"end_time": "2026-01-22 23:25:59.978",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise."
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"input_video_duration": 0,
"output_video_duration": 10,
"audio": true,
"SR": 720
}
}
非同期呼び出し
非同期呼び出しはすぐにタスク ID を返します。その後、結果をポーリングするか、完了を待ちます。
リクエスト例
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 次の URL はシンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 環境変数が設定されていない場合は、次の行を Model Studio の API キーに置き換えてください:api_key="sk-xxx"
# API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# 公開されている画像 URL を使用
img_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
# 音声 URL を設定
audio_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
def sample_async_call_i2v():
# 非同期呼び出し、タスク ID を返す
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.',
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("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))
# 非同期タスクの完了を待つ
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()
レスポンス例
- タスク作成レスポンス
{
"status_code": 200,
"request_id": "6dc3bf6c-be18-9268-9c27-xxxxxx",
"code": "",
"message": "",
"output": {
"task_id": "686391d9-7ecf-4290-a8e9-xxxxxx",
"task_status": "PENDING",
"video_url": ""
},
"usage": null
}
- タスククエリレスポンス
video_url は 24 時間有効です。有効期限が切れる前に動画をダウンロードしてください。
{
"status_code": 200,
"request_id": "2794c7a3-fe8c-4dd4-a1b7-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "c15d5b14-07c4-4af5-b862-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2026-01-22 23:24:46.527",
"scheduled_time": "2026-01-22 23:24:46.565",
"end_time": "2026-01-22 23:25:59.978",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise."
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"input_video_duration": 0,
"output_video_duration": 10,
"audio": true,
"SR": 720
}
}
Java SDK
重要以下のコードを実行する前に、DashScope Java SDK のバージョンが少なくとも2.22.6 であることを確認してください。
古いバージョンでは、「url error, please check url!」などのエラーが発生する可能性があります。更新するには、「SDK のインストール」をご参照ください。
モデルのリージョンに応じて baseHttpApiUrl を設定します:
シンガポール
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
バージニア
Constants.baseHttpApiUrl = "https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1";
北京
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
フランクフルト
Constants.baseHttpApiUrl = "https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1";
{WorkspaceId} を実際の ワークスペース ID に置き換えてください。
サンプルコード
同期呼び出し
同期呼び出しは、動画生成が完了するまでブロックします。この例では、パブリック URL、Base64 エンコーディング、ローカルファイルパスの 3 つの画像入力方法を示します。
リクエスト例
// 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 {
// エンドポイントを設定します。この例ではシンガポールリージョンを使用します。他のリージョンについては、https://www.alibabacloud.com/help/ja/model-studio/image-to-video-api-reference をご参照ください
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 環境変数が設定されていない場合は、次の行を Model Studio の API キーに置き換えてください:apiKey="sk-xxx"
// API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 画像入力方法:以下の 3 つのうち 1 つを選択してください。
*
* 1. パブリック URL:すでに公開されている画像に最適です。
* 2. ローカルファイル:ローカルでの開発やテストに適しています。
* 3. Base64 エンコーディング:非公開の画像や、データを安全に転送する必要がある場合に最適です。
*/
// [方法 1] パブリック URL
static String imgUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png";
// [方法 2] ローカルファイルパス (file:// + 絶対パス)
// static String imgUrl = "file://" + "/your/path/to/img.png"; // Linux/macOS
// static String imgUrl = "file://" + "C:/your/path/to/img.png"; // Windows
// [方法 3] Base64 エンコーディング
// static String imgUrl = Image2Video.encodeFile("/your/path/to/img.png");
// 音声 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 {
// パラメーターを設定
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("A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.")
.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 data:{MIME_type};base64,{base64_data} 形式の Base64 文字列。
*/
public static String encodeFile(String filePath) {
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
throw new IllegalArgumentException("File does not exist: " + filePath);
}
// MIME タイプを検出
String mimeType = null;
try {
mimeType = Files.probeContentType(path);
} catch (IOException e) {
throw new IllegalArgumentException("Cannot detect file type: " + filePath);
}
if (mimeType == null || !mimeType.startsWith("image/")) {
throw new IllegalArgumentException("Unsupported or unrecognized image format");
}
// ファイルの内容を読み込んでエンコード
byte[] fileBytes = null;
try{
fileBytes = Files.readAllBytes(path);
} catch (IOException e) {
throw new IllegalArgumentException("Cannot read file content: " + 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);
}
}
レスポンス例
video_url は 24 時間有効です。有効期限が切れる前に動画をダウンロードしてください。
{
"request_id": "87c091bb-7a3c-4904-8501-xxxxxx",
"output": {
"task_id": "413ed6e4-5f3a-4f57-8d58-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
"submit_time": "2026-01-22 23:25:45.729",
"scheduled_time": "2026-01-22 23:25:45.771",
"end_time": "2026-01-22 23:26:44.942"
},
"usage": {
"video_count": 1,
"duration": 10.0,
"input_video_duration": 0.0,
"output_video_duration": 10.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}
非同期呼び出し
非同期呼び出しはすぐにタスク ID を返します。その後、結果をポーリングするか、完了を待ちます。
リクエスト例
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
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.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.util.HashMap;
import java.util.Map;
public class Image2Video {
static {
// エンドポイントを設定します。この例ではシンガポールリージョンを使用します。他のリージョンについては、https://www.alibabacloud.com/help/ja/model-studio/image-to-video-api-reference をご参照ください
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 環境変数が設定されていない場合は、次の行を Model Studio の API キーに置き換えてください:apiKey="sk-xxx"
// API キーの取得:https://www.alibabacloud.com/help/ja/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";
// 音声 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 {
// パラメーターを設定
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("A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.")
.imgUrl(imgUrl)
.audioUrl(audioUrl)
.duration(10)
.parameters(parameters)
.resolution("720P")
.negativePrompt("")
.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 listTask() throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
AsyncTaskListParam param = AsyncTaskListParam.builder().build();
param.setApiKey(apiKey);
VideoSynthesisListResult result = is.list(param);
System.out.println(result);
}
// 単一タスクの結果を取得
public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
// DASHSCOPE_API_KEY が環境変数として設定されている場合、apiKey は null にできます。
VideoSynthesisResult result = is.fetch(taskId, apiKey);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args) {
try {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
レスポンス例
- タスク作成レスポンス
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}
- タスククエリレスポンス
video_url は 24 時間有効です。有効期限が切れる前に動画をダウンロードしてください。
{
"request_id": "87c091bb-7a3c-4904-8501-xxxxxx",
"output": {
"task_id": "413ed6e4-5f3a-4f57-8d58-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
"submit_time": "2026-01-22 23:25:45.729",
"scheduled_time": "2026-01-22 23:25:45.771",
"end_time": "2026-01-22 23:26:44.942"
},
"usage": {
"video_count": 1,
"duration": 10.0,
"input_video_duration": 0.0,
"output_video_duration": 10.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}
制限事項
- データ保持:
task_idと動画 URL は 24 時間保持されます。この期間を過ぎると、クエリやダウンロードはできなくなります。 - コンテンツモデレーション:すべての入力 (プロンプト、画像) と出力動画はコンテンツモデレーションの対象となります。違反があった場合、
IPInfringementSuspectまたはDataInspectionFailedエラーが発生します。「エラーコード」をご参照ください。
既知の制限事項
wan2.6-i2v-flash が円形のオブジェクト (指輪、歯車、時計の文字盤など) の連続回転を生成する際、3 秒あたりで約 1 秒間動画が停止することがあります。この問題を回避するには、代わりに Wan 2.7 - 画像動画生成 モデルを使用してください。
エラーコード
モデル呼び出しでエラーメッセージが返された場合は、「エラーコード」をご参照ください。
よくある質問
Q:特定の縦横比の動画を生成するにはどうすればよいですか?
A: 入力された開始フレーム画像 (img_url) が出力動画の縦横比を決定します。ただし、わずかなずれが生じる可能性があるため、3:4 のような正確な比率は保証されません。
-
なぜずれが生じるのですか?
モデルは入力画像の縦横比をベースラインとして使用し、選択された解像度ティア (
resolution) の総ピクセル数と組み合わせて、最も近い有効な解像度を計算します。動画の幅と高さは 16 の倍数でなければならないため、モデルは最終的な解像度をそれに応じて調整します。その結果、出力の縦横比は正確に 3:4 になるとは限りませんが、非常に近い値になります。- 例えば、750×1000 (縦横比 3:4 = 0.75) の入力画像で
resolutionを「720P」(約 920,000 総ピクセルを目標) に設定すると、816×1104 (縦横比 ≈ 0.739、約 900,000 総ピクセル) の出力が生成されます。
- 例えば、750×1000 (縦横比 3:4 = 0.75) の入力画像で
-
推奨事項:
- 入力を制御する:最良の結果を得るには、すでにご希望の縦横比を持つ開始フレーム画像を使用してください。
- 後処理:厳密な縦横比が必要な場合は、生成後に編集ツールを使用して動画をクロップするか、黒枠を追加してください。
Q:動画ストレージドメインの許可リストを取得するにはどうすればよいですか?
A:モデルによって生成された動画は OSS に保存されます。API は一時的なパブリック URL を返します。このダウンロード URL のファイアウォールホワイトリストを設定するには、次の点にご注意ください:基盤となるストレージは動的に変更される可能性があります。このトピックでは、古い情報によるアクセス問題を避けるため、固定の OSS ドメイン名ホワイトリストは提供していません。セキュリティ制御要件がある場合は、アカウントマネージャーに連絡して最新の OSS ドメイン名リストを入手してください。