Wan image-to-video モデルは、初回フレーム画像とテキストプロンプトからスムーズな動画を生成します。サポートされている機能は次のとおりです。
基本機能:3 秒から 10 秒の動画時間を選択し、480P、720P、または 1080P の動画解像度を指定し、プロンプトの再書き込みを使用し、ウォーターマークを追加できます。
音声機能:音声自動生成を使用するか、カスタム音声ファイルを提供して音声と動画を同期させることができます。(wan2.5 のみサポート)
クイックリンク: オンラインで試す | Wan 公式サイト | 動画エフェクトリスト
Wan 公式サイトで利用可能な機能は、API がサポートする機能と異なる場合があります。このドキュメントでは API の機能について説明し、新機能が追加され次第、速やかに更新されます。
概要
入力初回フレーム画像と音声 | 出力動画 (wan2.5) |
入力音声: | |
入力プロンプト:都市のファンタジーアートのシーン。ダイナミックなグラフィティアートのキャラクター。スプレーで描かれた少年がコンクリートの壁から生き返る。彼は非常に速いペースで英語のラップソングを歌いながら、クラシックでエネルギッシュなラッパーのポーズをとる。シーンは夜の都市の鉄道橋の下。照明は一本の街灯から来ており、高エネルギーと驚くべきディテールに満ちた映画のような雰囲気を醸し出している。動画の音声は彼のラップだけで構成され、他の対話やノイズはない。 | |
呼び出しを行う前に、各リージョンでサポートされているモデルと料金をご確認ください。
前提条件
呼び出しを行う前に、API キーを作成し、次にAPI キーを環境変数としてエクスポートする必要があります。SDK を使用して呼び出しを行うには、DashScope SDK をインストールします。
北京リージョンとシンガポールリージョンでは、API キーとリクエストエンドポイントが異なります。これらを相互に交換して使用しないでください。リージョンをまたいだ呼び出しは、認証失敗やサービスエラーの原因となります。
HTTP
image-to-video タスクは完了までに時間がかかり、通常 1〜5 分を要します。このため、API は非同期呼び出しを使用します。このプロセスには、タスクを作成し、結果をポーリングするという 2 つのコアステップが含まれます。手順は次のとおりです:
実際の所要時間は、キュー内のタスク数とサービスの実行状況によって異なります。結果が出るまでしばらくお待ちください。
ステップ 1:タスクを作成してタスク ID を取得
シンガポール:POST https://dashscope-intl.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 時間有効です。重複したタスクを作成しないでください。ポーリングを使用して結果を取得してください。
リクエストパラメーター | 音声自動生成この機能は wan2.5-i2v-preview モデルでのみサポートされています。音声自動生成はデフォルトで有効になっており、設定は不要です。この機能を明示的に有効にするには、 シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。 次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。 音声ファイルの提供この機能は wan2.5-i2v-preview モデルでのみサポートされています。 シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。 次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。 サイレント動画の生成サイレント動画を生成する方法は、モデルのバージョンによって異なります:
シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。 次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。 ネガティブプロンプトの使用negative_prompt を使用して、生成される動画に「花」が含まれないようにします。 シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。 次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。 |
リクエストヘッダー | |
Content-Type リクエストのコンテンツタイプ。このパラメーターを | |
Authorization リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例:Bearer sk-xxxx。 | |
X-DashScope-Async 非同期処理の設定パラメーター。HTTP リクエストは非同期処理のみをサポートします。このパラメーターを 重要 このリクエストヘッダーがない場合、「current user api does not support synchronous calls」というエラーメッセージが返されます。 | |
リクエストボディ | |
model モデル名。例:wan2.2-i2v-plus。 モデルとその料金のリストについては、「モデル」をご参照ください。 | |
input プロンプトなどの基本的な入力情報。 | |
parameters 動画の解像度、動画の時間、プロンプトの再書き込み、ウォーターマークなどの動画処理パラメーター。 |
レスポンスパラメーター | 成功応答task_id を保存して、タスクのステータスと結果をクエリします。 エラー応答タスクの作成に失敗しました。詳細については、「エラーメッセージ」を参照して問題を解決してください。 |
output タスクの出力情報。 | |
request_id 一意のリクエスト ID。この ID を使用して問題を追跡し、トラブルシューティングできます。 | |
code 失敗したリクエストのエラーコード。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。 | |
message 失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。 |
ステップ 2:タスク 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。
結果リンク:タスクが成功すると、動画リンクが返されます。リンクは 24 時間有効です。リンクを取得したら、すぐに動画をダウンロードし、Object Storage Service (OSS) などの永続ストレージサービスに保存してください。
task_id の有効期間:24 時間。この期間を過ぎると、結果をクエリできなくなり、API はタスクステータスとして
UNKNOWNを返します。
リクエストパラメーター | タスク結果のクエリ
シンガポールリージョンと北京リージョンの API キーは異なります。API キーを作成してください。 以下の `base_url` はシンガポールリージョン用です。北京リージョンのモデルの場合は、`base_url` を `https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx` に置き換えてください。 |
リクエストヘッダー | |
Authorization リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例:Bearer sk-xxxx。 | |
URL パスパラメーター | |
task_id タスク ID。 |
レスポンスパラメーター | タスク成功動画 URL は 24 時間のみ保持され、この期間を過ぎると自動的にパージされます。生成された動画は速やかに保存する必要があります。 タスク失敗タスクが失敗した場合、task_status は FAILED に設定され、エラーコードとメッセージが提供されます。詳細については、「エラーメッセージ」を参照して問題を解決してください。 タスククエリの期限切れtask_id は 24 時間有効です。この期間を過ぎると、クエリは失敗し、以下のエラーメッセージが返されます。 |
output タスクの出力情報。 | |
usage 出力情報の統計。成功した結果のみがカウントされます。 | |
request_id 一意のリクエスト ID。この ID を使用して問題を追跡し、トラブルシューティングできます。 |
DashScope SDK
SDK のパラメーター名は、ほとんどが HTTP API と一致しています。パラメーター構造は、プログラミング言語の機能に基づいてカプセル化されています。
image-to-video タスクは完了までに時間がかかり、通常 1〜5 分を要するため、SDK は基盤層で非同期 HTTP 呼び出しプロセスをカプセル化し、同期および非同期の呼び出し方法の両方をサポートします。
実際の所要時間は、キュー内のタスク数とサービスの実行状況によって異なります。結果が出るまでしばらくお待ちください。
Python SDK
Python SDK は、パブリック URL、Base64 エンコードされた文字列、ローカルファイルパス (絶対パスまたは相対パス) の 3 つの画像入力方法をサポートしています。これらの方法のいずれかを選択できます。詳細については、「入力画像」をご参照ください。
潜在的な実行時エラーを避けるために、DashScope Python SDK の最新バージョンをインストールすることを推奨します。詳細については、「SDK のインストールまたはアップグレード」をご参照ください。
サンプルコード
同期
同期呼び出しは、動画生成が完了し、結果が返されるまでブロックして待機します。この例では、パブリック URL、Base64 エンコーディング、ローカルファイルパスの 3 つの画像入力方法を示します。
リクエスト例
import base64
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import mimetypes
import dashscope
# 以下はシンガポールリージョンの URL です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
# シンガポールリージョンと北京リージョンの API キーは異なります。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("Unsupported or unknown 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. パブリック 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.5-i2v-preview',
prompt='A scene of urban fantasy art. A dynamic graffiti art character. A boy painted with spray paint comes to life from a concrete wall. He sings an English rap song at a very fast pace while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single streetlight, creating a cinematic atmosphere 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="480P",
duration=10,
# audio=True,
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": "55194b9a-d281-4565-8ef6-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "e2bb35a2-0218-4969-8c0d-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2025-10-28 13:45:48.620",
"scheduled_time": "2025-10-28 13:45:57.378",
"end_time": "2025-10-28 13:48:05.361",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy painted with spray paint comes to life from a concrete wall. He sings an English rap song at a very fast pace while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single streetlight, creating a cinematic atmosphere of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
"actual_prompt": "A boy made of spray paint emerges from a concrete wall, stands still, and begins to sing an English rap, his mouth opening and closing, his head nodding to the rhythm, and his eyes focused. He gives a thumbs-up with his right hand, puts his left hand on his hip, and moves his body rhythmically in place. The background is a night scene under a railway bridge, lit by a single streetlight. The audio is his rap performance, with the lyrics: 'Skyscrapers loom, shadows kiss the pavement. Dreams stack high, but the soul's in the basement. Pocket full of lint, chasing gold like it's sacred. Every breath a gamble, the odds never patient.'"
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"SR": 480
}
}非同期
この例では、非同期呼び出しを示します。このメソッドはすぐにタスク ID を返し、タスクが完了するまでポーリングまたは待機する必要があります。
リクエスト例
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# 以下はシンガポールリージョンの URL です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
# シンガポールリージョンと北京リージョンの API キーは異なります。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.5-i2v-preview',
prompt='A scene of urban fantasy art. A dynamic graffiti art character. A boy painted with spray paint comes to life from a concrete wall. He sings an English rap song at a very fast pace while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single streetlight, creating a cinematic atmosphere 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="480P",
duration=10,
# audio=True,
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()レスポンス例
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": "55194b9a-d281-4565-8ef6-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "e2bb35a2-0218-4969-8c0d-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2025-10-28 13:45:48.620",
"scheduled_time": "2025-10-28 13:45:57.378",
"end_time": "2025-10-28 13:48:05.361",
"orig_prompt": "都会のファンタジーアートのシーン。ダイナミックなグラフィティアートのキャラクター。スプレーペイントで描かれた少年がコンクリートの壁から現れ、生き生きと動き出します。彼はクラシックでエネルギッシュなラッパーのポーズをとりながら、非常に速いペースで英語のラップソングを歌います。シーンは夜の都会の鉄道橋の下に設定されています。照明は一本の街灯から来ており、高いエネルギーと驚くほどのディテールに満ちた映画のような雰囲気を醸し出しています。ビデオの音声は彼のラップだけで構成されており、他のセリフやノイズはありません。",
"actual_prompt": "スプレーペイントでできた少年がコンクリートの壁から現れ、静止し、英語のラップを歌い始めます。口を開閉させ、リズムに合わせて頭をうなずき、目は一点に集中しています。彼は右手で親指を立て、左手を腰に当て、その場でリズミカルに体を動かします。背景は、一本の街灯に照らされた鉄道橋の下の夜景です。音声は彼のラップパフォーマンスで、歌詞は次のとおりです: 'Skyscrapers loom, shadows kiss the pavement. Dreams stack high, but the soul's in the basement. Pocket full of lint, chasing gold like it's sacred. Every breath a gamble, the odds never patient.'"
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"SR": 480
}
}Java SDK
Java SDK は、パブリック URL、Base64 エンコードされた文字列、ローカルファイルパス (絶対パスのみ) の 3 つの画像入力方法をサポートしています。これらの方法のいずれかを選択できます。詳細については、「入力画像」をご参照ください。
潜在的な実行時エラーを避けるために、DashScope Java SDK の最新バージョンをインストールすることを推奨します。詳細については、「SDK のインストールまたはアップグレード」をご参照ください。
サンプルコード
同期
同期呼び出しは、動画生成が完了し、結果が返されるまでブロックして待機します。この例では、パブリック 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 {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
// 上記はシンガポールリージョンの URL です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:apiKey="sk-xxx"
// シンガポールリージョンと北京リージョンの API キーは異なります。API キーの取得:https://www.alibabacloud.com/help/zh/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.5-i2v-preview")
.prompt("A scene of urban fantasy art. A dynamic graffiti art character. A boy painted with spray paint comes to life from a concrete wall. He sings an English rap song at a very fast pace while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single streetlight, creating a cinematic atmosphere 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)
//.audio(true)
.duration(10)
.parameters(parameters)
.resolution("480P")
.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 unknown 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": "f1bfb531-6e13-4e17-8e93-xxxxxx",
"output": {
"task_id": "9ddebba6-f784-4f55-b845-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxx"
},
"usage": {
"video_count": 1
}
}非同期
この例では、非同期呼び出しを示します。このメソッドはすぐにタスク 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://dashscope.aliyuncs.com/api/v1 に置き換えてください
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
// シンガポールリージョンと北京リージョンの API キーは異なります。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.5-i2v-preview")
.prompt("A scene of urban fantasy art. A dynamic graffiti art character. A boy painted with spray paint comes to life from a concrete wall. He sings an English rap song at a very fast pace while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single streetlight, creating a cinematic atmosphere 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)
//.audio(true)
.duration(10)
.parameters(parameters)
.resolution("480P")
.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);
}
}レスポンス例
1. タスク作成時のレスポンス例
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. タスク結果クエリのレスポンス例
`video_url` は 24 時間有効です。動画を速やかにダウンロードしてください。
{
"request_id": "f1bfb531-6e13-4e17-8e93-xxxxxx",
"output": {
"task_id": "9ddebba6-f784-4f55-b845-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxx"
},
"usage": {
"video_count": 1
}
}制限事項
データ保持:task_id と動画 URL は 24 時間のみ保持されます。この期間を過ぎると、クエリやダウンロードはできません。
音声サポート:wan2.5 モデルは、音声自動生成またはカスタム音声ファイルを含む音声付き動画をサポートします。wan2.2 以前のバージョンはサイレント動画のみを出力します。必要に応じて、音声合成を使用して音声を生成できます。
コンテンツ審査:入力プロンプトと動画、および出力動画はコンテンツ審査の対象となります。非準拠のコンテンツは、「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
主要パラメーターの説明
入力画像
img_url パラメーターは入力画像を指定し、以下の 3 つの入力方法をサポートします:
方法 1:パブリック URL
HTTP/HTTPS をサポートするパブリックにアクセス可能なアドレス。
例:
https://example.com/images/cat.png。
方法 2:Base64 エンコーディング
例:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDg......(長さの制限により、スニペットのみ表示)。呼び出しを行う際は、完全な文字列を渡してください。エンコーディングフォーマット:
data:{MIME_type};base64,{base64_data}フォーマットを使用します。ここで:{base64_data}:画像ファイルの Base64 エンコードされた文字列。
{MIME_type}:画像のメディアタイプ。ファイル形式に対応している必要があります。
画像フォーマット
MIME タイプ
JPEG
image/jpeg
JPG
image/jpeg
PNG
image/png
BMP
image/bmp
WEBP
image/webp
方法 3:ローカルファイルパス (SDK のみ)
Python SDK:絶対パスと相対パスの両方をサポートします。ファイルパスのルールは次のとおりです:
システム
渡されるファイルパス
例 (絶対パス)
例 (相対パス)
Linux または macOS
file://{ファイルの絶対パスまたは相対パス}
file:///home/images/test.png
file://./images/test.png
Windows
file://D:/images/test.png
file://./images/test.png
Java SDK:ファイルの絶対パスのみをサポートします。ファイルパスのルールは次のとおりです:
システム
渡されるファイルパス
例 (絶対パス)
Linux または macOS
file://{ファイルの絶対パス}
file:///home/images/test.png
Windows
file:///{ファイルの絶対パス}
file:///D:/images/test.png
音声設定
サポートされるモデル:wan2.5-i2v-preview。
音声設定:input.audio_url と parameters.audio パラメーターを使用して音声の動作を制御できます。優先順位:audio_url > audio。3 つのモードがサポートされています:
サイレント動画の生成
パラメーター設定:`audio_url` を渡さず、`audio` を `false` に設定します。
シナリオ:後で独自の音声や音楽を追加する予定の純粋な視覚コンテンツに役立ちます。
音声の自動生成
パラメーター設定:`audio_url` を渡さず、`audio` を `true` に設定します。
効果の説明:モデルは、プロンプトと視覚コンテンツに基づいて、一致する背景音声または音楽を自動的に生成します。
カスタム音声の使用
パラメーター設定:`audio_url` を渡します。この場合、`audio` パラメーターは無視されます。
効果の説明:動画コンテンツは、唇の動きやリズムなど、音声コンテンツと整合します。
課金とレート制限
エラーコード
モデル呼び出しが失敗し、エラーメッセージが返された場合は、「エラーメッセージ」で詳細をご確認ください。
よくある質問
動画関連の質問については、「よくある質問」をご参照ください。
Q:特定のアスペクト比 (例:3:4) の動画を生成するにはどうすればよいですか?
A:出力動画のアスペクト比は入力初回フレーム画像 (img_url) によって決まりますが、厳密な 3:4 のような正確な比率を保証することはできません。
仕組み:モデルは入力画像のアスペクト比をベースラインとして使用し、それを 480P、720P、1080P などの resolution パラメーターに基づいてサポートされている解像度に適合させます。出力解像度は、幅と高さが 16 で割り切れるという技術的要件を満たす必要があるため、最終的なアスペクト比にはわずかなずれが生じることがあります。たとえば、0.75 から 0.739 への調整などです。これは正常な動作です。
例:入力画像が 750 × 1000 (アスペクト比 3:4 = 0.75) で、`resolution` が「720P」(目標総ピクセル数約 920,000) に設定されている場合、実際の出力は 816 × 1104 (アスペクト比 ≈ 0.739、総ピクセル数約 900,000) となります。
resolution パラメーターは主に動画の精細度 (総ピクセル数) を制御することに注意してください。最終的な動画のアスペクト比は、依然として入力画像に基づいており、必要な微調整のみが行われます。
ベストプラクティス:目標のアスペクト比に厳密に一致させるには、その比率の入力画像を使用し、出力動画をトリミングまたはパディングして後処理します。たとえば、動画編集ツールを使用して出力動画を目標の比率にトリミングしたり、黒枠やぼかし背景を追加してパディングしたりできます。
付録
基本的な image-to-video 機能の例
機能 | 入力初回フレーム画像 | 入力プロンプト | 出力動画 |
サイレント動画 |
| 草の上を走る猫 |

