すべてのプロダクト
Search
ドキュメントセンター

Alibaba Cloud Model Studio:Wan - 開始フレームと終了フレームの動画生成 API リファレンス

最終更新日:Mar 13, 2026

Wan の開始フレームと終了フレームの動画生成モデルは、開始フレーム画像、終了フレーム画像、およびテキストプロンプトから、スムーズに遷移する動画を生成します。

リファレンスユーザーガイド

適用範囲

API 呼び出しを成功させるには、モデル、エンドポイント URL、API キーが同じリージョンに属している必要があります。リージョン間の呼び出しは失敗します。

説明

このトピックのサンプルコードはシンガポールリージョンに適用されます。

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 の使用」をご参照ください。

リクエストパラメーター

開始フレームと終了フレームの動画生成

開始フレーム、終了フレーム、およびプロンプトに基づいて動画を生成します。

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-kf2v-flash",
    "input": {
        "first_frame_url": "https://wanx.alicdn.com/material/20250318/first_frame.png",
        "last_frame_url": "https://wanx.alicdn.com/material/20250318/last_frame.png",
        "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."
    },
    "parameters": {
        "resolution": "480P",
        "prompt_extend": true
    }
}'

ネガティブプロンプトの使用

negative_prompt パラメーターを使用して、生成される動画に「人物」が含まれないようにします。

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.1-kf2v-plus",
    "input": {
        "first_frame_url": "https://wanx.alicdn.com/material/20250318/first_frame.png",
        "last_frame_url": "https://wanx.alicdn.com/material/20250318/last_frame.png",
        "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.",
        "negative_prompt": "people"
    },
    "parameters": {
        "resolution": "720P",
        "prompt_extend": true
    }
}'
リクエストヘッダー

Content-Type string (必須)

リクエストのコンテンツタイプです。 application/json が必須です。

Authorization string (必須)

Model Studio API キーを使用した認証情報。

例: Bearer sk-xxxx

X-DashScope-Async string (必須)

非同期処理を有効にします。HTTP リクエストは非同期処理のみをサポートしているため、値は enable である必要があります。

重要

このヘッダーを含めない場合、「current user api does not support synchronous calls」というエラーが返されます。

リクエストボディ

model string (必須)

モデル名。例: wan2.2-kf2v-flash。

詳細については、「モデルリストと価格」をご参照ください。

input object (必須)

プロンプトなどの基本的な入力情報。

プロパティ

prompt string (任意)

テキストプロンプト。中国語と英語をサポートします。最大長:800 文字。各漢字または英字は 1 文字としてカウントされます。制限を超えたテキストは自動的に切り捨てられます。

開始フレームと終了フレームの間で被写体やシーンが大幅に変化する場合は、カメラの動き (カメラが左に移動) や被写体の動き (人物が前方に走る) などの遷移を記述してください。

例:小さな黒猫が興味深そうに空を見上げます。カメラは目線の高さから徐々に上昇し、最終的にトップダウンビューでその好奇心に満ちた視線を捉えます。

プロンプトのベストプラクティスについては、「text-to-video および image-to-video のプロンプトガイド」をご参照ください。

negative_prompt string (任意)

動画に含めたくないコンテンツを記述するネガティブプロンプト。これにより、出力を制約できます。

中国語と英語をサポートします。最大長:500 文字。制限を超えたテキストは自動的に切り捨てられます。

例:低解像度、エラー、最低品質、低品質、変形、余分な指、悪いプロポーション。

first_frame_url string (必須)

開始フレーム画像の URL。出力動画のアスペクト比はこの画像と一致します。

URL はパブリックにアクセス可能で、HTTP または HTTPS をサポートしている必要があります。

画像要件:

  • フォーマット:JPEG、JPG、PNG (アルファチャンネルはサポートされていません)、BMP、または WEBP。

  • 解像度:幅と高さは 240~8000 ピクセルの間である必要があります。

  • ファイルサイズ:10 MB 以下。

last_frame_url string (必須)

終了フレーム画像の URL。

URL はパブリックにアクセス可能で、HTTP または HTTPS をサポートしている必要があります。

画像要件:

  • フォーマット:JPEG、JPG、PNG (アルファチャンネルはサポートされていません)、BMP、または WEBP。

  • 画像解像度:画像の幅と高さは 240~8000 ピクセルの間である必要があります。終了フレームの解像度は、開始フレームの解像度と一致する必要はありません。

  • ファイルサイズ:10 MB 以下。

parameters object (任意)

動画処理パラメーター。

プロパティ

resolution string (任意)

重要

解像度はコストに直接影響します。同じモデルの場合:1080P > 720P > 480P。呼び出す前にモデルの価格を確認してください。

生成される動画の解像度レベル。これは解像度 (総ピクセル数) のみを調整し、アスペクト比は変更しません。動画のアスペクト比は、first_frame_url で指定された開始フレーム画像と一致します

デフォルト値と利用可能な値は、model パラメーターによって異なります:

  • wan2.2-kf2v-flash:オプションは 480P、720P、1080P です。デフォルトは 720P です。

  • wan2.1-kf2v-plus:オプションは 720P です。デフォルトは 720P です。

例:720P。

duration integer (任意)

重要

持続時間はコストに直接影響します。課金は秒単位で行われます。呼び出す前にモデルの価格を確認してください。

生成される動画の持続時間 (秒)。この値は 5 に固定されており、変更できません。モデルは常に 5 秒の動画を生成します。

prompt_extend bool (任意)

プロンプトリライトを有効にします。有効にすると、大規模言語モデルが入力プロンプトを書き換えます。これにより、短いプロンプトの結果が向上しますが、処理時間が増加します。

  • true (デフォルト):プロンプトリライトを有効にします。

  • false:プロンプトリライトを無効にします。

例:true。

watermark bool (任意)

画像の右下隅に「AI-generated」と表示されるウォーターマークを追加します。

  • false (デフォルト):ウォーターマークを追加しません。

  • true:ウォーターマークを追加します。

例:false。

seed integer (任意)

乱数シード。0 から 2147483647 までの整数である必要があります。

指定しない場合、ランダムなシードが生成されます。固定シードを使用すると再現性が向上しますが、モデルのランダム性により結果が異なる場合があります。

例: 12345

レスポンスパラメーター

成功レスポンス

task_id を保存して、タスクのステータスと結果をクエリします。

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

エラーレスポンス

タスクの作成に失敗しました。「エラーコード」を参照して問題を解決してください。

{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

タスクの出力情報。

プロパティ

task_id string

タスクの ID。最大 24 時間、タスクのクエリに使用できます。

task_status string

タスクのステータス。

列挙

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN:タスクが存在しないか、ステータスが不明

request_id string

リクエストの一意の識別子。問題の追跡とトラブルシューティングに使用します。

code string

エラーコード。リクエストが失敗した場合にのみ返されます。詳細については、「エラーコード」をご参照ください。

message string

詳細なエラーメッセージ。リクエストが失敗した場合にのみ返されます。詳細については、「エラーコード」をご参照ください。

ステップ 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 を返します。

リクエストパラメーター

タスク結果のクエリ

86ecf553-d340-4e21-xxxxxxxxx を実際の task_id に置き換えてください。

API キーはリージョン固有です。詳細については、「API キードキュメント」をご参照ください。
北京リージョンのモデルの場合、base_url を https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
リクエストヘッダー

Authorization string (必須)

Model Studio API キーを使用した認証情報。

例: Bearer sk-xxxx

パスパラメーター

task_id string (必須)

クエリするタスクの ID。

レスポンスパラメーター

タスク成功

動画 URL は 24 時間のみ保持され、その後自動的にパージされます。生成された動画は速やかに保存してください。

{
    "request_id": "ec016349-6b14-9ad6-8009-xxxxxx",
    "output": {
        "task_id": "3f21a745-9f4b-4588-b643-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-04-18 10:36:58.394",
        "scheduled_time": "2025-04-18 10:37:13.802",
        "end_time": "2025-04-18 10:45:23.004",
        "video_url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/xxx.mp4?xxxxx",
        "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 fur is smooth, and its whiskers are clearly visible. The background is a simple light-colored wall, highlighting the cat's black silhouette. A close-up shot emphasizes the changes in the cat's expression and the details of its eyes."
    },
    "usage": {
        "video_duration": 5,
        "video_count": 1,
        "SR": 480
    }
}

タスク失敗

タスクが失敗すると、task_status はエラーコードとメッセージとともに FAILED にセットされます。問題を解決するには、「エラーコード」をご参照ください。

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size is not match xxxxxx"
    }
}

タスククエリの期限切れ

task_id は 24 時間有効です。この期間を過ぎると、クエリは失敗し、以下のエラーメッセージを返します。

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

タスクの出力情報。

プロパティ

task_id string

タスクの ID。最大 24 時間、タスクのクエリに使用できます。

task_status string

タスクのステータス。

列挙

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN:タスクが存在しないか、ステータスが不明

ポーリング中のステータス遷移:

  • PENDING → RUNNING → SUCCEEDED または FAILED

  • 最初のクエリは通常 PENDING または RUNNING を返します

  • SUCCEEDED ステータスには、レスポンスに生成された動画 URL が含まれます

  • FAILED ステータスでは、エラーメッセージを確認して再試行する必要があります

submit_time string

タスクが送信された時刻。時刻は UTC+8 です。フォーマット:YYYY-MM-DD HH:mm:ss.SSS

scheduled_time string

タスクが実行を開始した時刻。時刻は UTC+8 です。フォーマット:YYYY-MM-DD HH:mm:ss.SSS

end_time string

タスクが完了した時刻。時刻は UTC+8 です。フォーマット:YYYY-MM-DD HH:mm:ss.SSS

video_url string

生成された動画の URL。 task_status が SUCCEEDED の場合にのみ返されます。

URL は 24 時間有効です。H.264 エンコーディングの MP4 形式で動画をダウンロードするために使用します。

orig_prompt string

元の入力プロンプト。これは prompt リクエストパラメーターの値です。

actual_prompt string

プロンプトリライトが有効な場合に使用された、実際に最適化されたプロンプトを返します。この機能が無効な場合は返されません。

code string

エラーコード。リクエストが失敗した場合にのみ返されます。詳細については、「エラーコード」をご参照ください。

message string

詳細なエラーメッセージ。リクエストが失敗した場合にのみ返されます。詳細については、「エラーコード」をご参照ください。

usage object

使用量の統計。成功した結果のみをカウントします。

プロパティ

video_duration integer

動画の持続時間 (秒)。値:5。課金式:コスト = 動画の持続時間 (秒) × 単価。

video_count integer

生成された動画の数。1 に固定されています。

video_ratio string

2.1 モデルによってのみ返されます。動画のアスペクト比。standard に固定されています。

SR integer

2.2 モデルによってのみ返されます。動画の解像度レベル。値:480、720、または 1080。

request_id string

リクエストの一意の識別子。問題の追跡とトラブルシューティングに使用します。

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 ドメイン名リストを取得してください。