Wan の画像から動画へモデルは、最初のフレームの画像とテキストプロンプトをもとに滑らかな動画を生成します。
関連ドキュメント: ユーザーガイド
利用範囲
正常に API を呼び出すためには、モデル、エンドポイント URL、API キーがすべて同一リージョンに属している必要があります。クロスリージョンでの呼び出しは失敗します。
モデルの選択: モデルが配置されているリージョンを確認します。
URL の選択: 対応するリージョンのエンドポイント URL を選択します。HTTP URL および DashScope SDK URL の両方がサポートされています。
API キーの設定: 当該リージョン向けのAPI キーを取得し、環境変数として設定します(非推奨。現在は API キー設定に統合済み)。
SDK のインストール: SDK を使用して API を呼び出す場合、DashScope SDK をインストールします。
このトピックのサンプルコードはシンガポールリージョンを対象としています。
HTTP 呼び出し
画像から動画へタスクの完了には通常 1~5 分程度かかるため、API では非同期呼び出しが採用されています。全体の処理フローは、以下の 2 つのコアステップで構成されます:タスクの作成 → 結果のポーリング。
ステップ 1:タスクを作成し、タスク ID を取得
シンガポール
POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
米国 (バージニア)
POST https://dashscope-us.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
北京
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
タスク作成後は、返された
task_idを使用して結果を照会します。task_idの有効期限は 24 時間です。重複したタスクを作成しないでください。代わりにポーリングにより結果を取得してください。初心者向けチュートリアルについては、Postmanをご参照ください。
リクエストパラメーター | マルチショットナラティブこの機能は、wan2.6 モデルのみでサポートされています。
自動ダビングこの機能は、wan2.6 および wan2.5 モデルのみでサポートされています。
音声ファイルを指定するこの機能は、wan2.6 および wan2.5 モデルのみでサポートされています。 動画のバックグラウンド音楽またはナレーションを指定するには、カスタム音声ファイルの URL を 無音動画の生成以下のモデルのみが無音動画の生成をサポートしています:
ネガティブプロンプトの使用ネガティブプロンプトパラメーターを使用して、生成された動画に「花」が含まれないようにします。 |
ヘッダー | |
Content-Type リクエストのコンテンツタイプ。値は必ず | |
Authorization Model Studio API キーを使用した認証資格情報。 例: | |
X-DashScope-Async 非同期処理を有効化します。HTTP リクエストは非同期処理のみをサポートするため、値は必ず 重要 このヘッダーが存在しない場合、「current user api does not support synchronous calls」というエラーが返されます。 | |
リクエスト本文 | |
model モデル名。モデルおよび料金に関する詳細は、「モデル料金」をご参照ください。 例: wan2.6-i2v-flash。 | |
input プロンプトなどの基本的な入力情報。 | |
parameters 解像度、再生時間、プロンプト再書き込み、ウォーターマークなど、動画処理パラメーター。 |
レスポンスパラメーター | 成功時のレスポンス
エラー時のレスポンスタスク作成に失敗しました。問題を解決するには、「エラーコード」をご参照ください。 |
output タスク出力情報。 | |
request_id リクエストの一意の識別子。トレースおよびトラブルシューティングに使用します。 | |
code エラーコード。リクエストが失敗した場合にのみ返されます。「エラーコード」の詳細をご参照ください。 | |
message 詳細なエラーメッセージ。リクエストが失敗した場合にのみ返されます。「エラーコード」の詳細をご参照ください。 |
ステップ 2:タスク ID による結果の照会
シンガポール
GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
米国 (バージニア)
GET https://dashscope-us.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というタスクステータスを返します。
リクエストパラメーター | タスク結果の照会
|
ヘッダー | |
Authorization Model Studio API キーを使用した認証資格情報。 例: | |
URL パスパラメーター | |
task_id 照会対象のタスクの ID。 |
レスポンスパラメーター | タスク成功時動画 URL は 24 時間のみ保持され、その後自動的にパージされます。生成された動画は速やかに保存してください。 タスク失敗時タスクが失敗した場合、 タスク照会の有効期限切れ
|
output タスク出力情報。 | |
usage 出力統計情報。成功した結果に対してのみカウントされます。 | |
request_id リクエストの一意の識別子。トレースおよびトラブルシューティングに使用します。 |
DashScope SDK 呼び出し
SDK のパラメーター名は、HTTP API とほぼ一致します。パラメーター構造は言語固有の規則に合わせて調整されています。
画像から動画へタスクの完了には通常 1~5 分程度かかるため、SDK は HTTP の非同期呼び出しフローをラップし、同期および非同期の両方の呼び出し方法をサポートしています。
実際の処理時間はキューの長さおよびサービスの実行状況に依存します。結果を待つ際は、しばらくお待ちください。
Python SDK 呼び出し
以下のコードを実行する前に、DashScope Python SDK のバージョンが最低でも1.25.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-us.aliyuncs.com/api/v1'
北京
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
サンプルコード
同期呼び出し
同期呼び出しでは、動画の生成および結果の返却が完了するまでブロックされます。この例では、パブリック URL、Base64 エンコーディング、ローカルファイルパスの 3 種類の画像入力方法を示します。
リクエスト例
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'
# 環境変数を設定していない場合、次の行を Model Studio API キーに置き換えてください: api_key="sk-xxx"
# API キーの取得先: https://www.alibabacloud.com/help/zh/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("サポートされていない、または認識できない画像フォーマット")
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. パブリック 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('しばらくお待ちください...')
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('失敗しました。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。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'
# 環境変数を設定していない場合、次の行を Model Studio API キーに置き換えてください: api_key="sk-xxx"
# API キーの取得先: https://www.alibabacloud.com/help/zh/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():
# 非同期呼び出し、task_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('失敗しました。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('失敗しました。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('失敗しました。status_code: %s、code: %s、message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_i2v()レスポンス例
1. タスク作成時のレスポンス例
{
"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
}2. タスク結果照会時のレスポンス例
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 のインストール」に従って SDK を更新してください。
モデルのリージョンに応じて、baseHttpApiUrl を設定します:
シンガポール
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
米国 (バージニア)
Constants.baseHttpApiUrl = "https://dashscope-us.aliyuncs.com/api/v1";
北京
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
サンプルコード
同期呼び出し
同期呼び出しでは、動画の生成および結果の返却が完了するまでブロックされます。この例では、パブリック 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 {
// シンガポールリージョンの URL。URL の取得先: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合、次の行を Model Studio API キーに置き換えてください: apiKey="sk-xxx"
// API キーの取得先: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 画像入力方法: 以下の 3 つのうちいずれかを選択してください。
*
* 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("しばらくお待ちください...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
/**
* ファイルを Base64 文字列にエンコード
* @param filePath ファイルパス
* @return MIME_type と 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);
}
}レスポンス例
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 {
// シンガポールリージョンの URL。URL の取得先: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合、次の行を Model Studio API キーに置き換えてください: api_key="sk-xxx"
// API キーの取得先: https://www.alibabacloud.com/help/zh/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("しばらくお// 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 {
// シンガポールリージョンの URL。URL の取得先: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合、次の行を Model Studio API キーに置き換えてください: apiKey="sk-xxx"
// API キーの取得先: https://www.alibabacloud.com/help/zh/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("しばらくお待ちください...");
// 結果の取得
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);
}
}レスポンス例
1. タスク作成時のレスポンス例
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. タスク結果照会時のレスポンス例
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」などのエラーが返されます。「エラーメッセージ」をご参照ください。
ネットワークアクセス構成: 動画リンクは Alibaba Cloud OSS に保存されます。セキュリティポリシーにより業務システムから外部 OSS リンクにアクセスできない場合は、以下の OSS ドメインをネットワークアクセスホワイトリストに追加してください。
# OSS ドメイン一覧 dashscope-result-bj.oss-cn-beijing.aliyuncs.com dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com dashscope-result-sh.oss-cn-shanghai.aliyuncs.com dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com dashscope-result-zjk.oss-cn-zhangjiakou.aliyuncs.com dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com dashscope-result-hy.oss-cn-heyuan.aliyuncs.com dashscope-result-cd.oss-cn-chengdu.aliyuncs.com dashscope-result-gz.oss-cn-guangzhou.aliyuncs.com dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com
エラーコード
モデル呼び出しが失敗しエラーが返された場合は、「エラーメッセージ」を参照してトラブルシューティングを行ってください。
よくある質問
Q: 特定の縦横比(例: 3:4)で動画を生成するにはどうすればよいですか?
A: 出力動画の縦横比は、入力最初のフレーム画像(img_url)によって決定されます。ただし、厳密な比率(例: 正確な 3:4)は保証されません。若干の偏差が生じる可能性があります。
偏差が生じる理由: モデルは入力画像の比率をベースラインとして使用し、ターゲット総ピクセル数(解像度で設定)に基づいて最も近い有効な解像度を計算します。幅と高さは 16 の倍数である必要があるため、わずかな調整が行われます。そのため、出力比率は正確な 3:4 にはなりませんが、非常に近い値になります。
例: 入力画像 750×1000(縦横比 3:4 = 0.75)、解像度 = "720P"(ターゲット約 920,000 ピクセル)の場合、出力は 816×1104(縦横比 ≈ 0.739、約 900,000 ピクセル)になります。
ベストプラクティス:
入力制御: 目標とする縦横比を持つ画像を最初のフレームとして使用します。
後処理: 厳密な比率が必要な場合は、編集ツールを使用して生成された動画をトリミングまたはパディングします。