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

Alibaba Cloud Model Studio:Wan image-to-video API リファレンス

最終更新日:Dec 13, 2025

Wan image-to-video モデルは、初回フレーム画像テキストプロンプトからスムーズな動画を生成します。サポートされている機能は次のとおりです。

  • 基本機能:3 秒から 10 秒の動画時間を選択し、480P、720P、または 1080P の動画解像度を指定し、プロンプトの再書き込みを使用し、ウォーターマークを追加できます。

  • 音声機能:音声自動生成を使用するか、カスタム音声ファイルを提供して音声と動画を同期させることができます。(wan2.5 のみサポート)

クイックリンク: オンラインで試す | Wan 公式サイト | 動画エフェクトリスト

説明

Wan 公式サイトで利用可能な機能は、API がサポートする機能と異なる場合があります。このドキュメントでは API の機能について説明し、新機能が追加され次第、速やかに更新されます。

概要

入力初回フレーム画像と音声

出力動画 (wan2.5)

rap-转换自-png

入力音声

入力プロンプト:都市のファンタジーアートのシーン。ダイナミックなグラフィティアートのキャラクター。スプレーで描かれた少年がコンクリートの壁から生き返る。彼は非常に速いペースで英語のラップソングを歌いながら、クラシックでエネルギッシュなラッパーのポーズをとる。シーンは夜の都市の鉄道橋の下。照明は一本の街灯から来ており、高エネルギーと驚くべきディテールに満ちた映画のような雰囲気を醸し出している。動画の音声は彼のラップだけで構成され、他の対話やノイズはない。

説明

呼び出しを行う前に、各リージョンでサポートされているモデルと料金をご確認ください。

前提条件

呼び出しを行う前に、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 モデルでのみサポートされています。音声自動生成はデフォルトで有効になっており、設定は不要です。この機能を明示的に有効にするには、parameters.audio パラメーターを true に設定します。

シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。
次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.5-i2v-preview",
    "input": {
        "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": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
    },
    "parameters": {
        "resolution": "480P",
        "prompt_extend": true,
        "duration": 10,
        "audio": true
    }
}'

音声ファイルの提供

この機能は wan2.5-i2v-preview モデルでのみサポートされています。input.audio_url パラメーターに音声リンクを指定します。

シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。
次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.5-i2v-preview",
    "input": {
        "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": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png",
        "audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
    },
    "parameters": {
        "resolution": "480P",
        "prompt_extend": true,
        "duration": 10
    }
}'

サイレント動画の生成

サイレント動画を生成する方法は、モデルのバージョンによって異なります:

  • wan2.5-i2v-preview モデルの場合、parameters.audio パラメーターを明示的に false に設定する必要があります。

  • wan2.2 以前のバージョンでは、モデルはデフォルトでサイレント動画を生成し、パラメーターは不要です。詳細については、以下のコード例をご参照ください。

シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。
次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-i2v-plus",
    "input": {
        "prompt": "A cat running on the grass",
        "img_url": "https://cdn.translate.alibaba.com/r/wanx-demo-1.png"
    },
    "parameters": {
        "resolution": "480P",
        "prompt_extend": true
    }
}'

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

negative_prompt を使用して、生成される動画に「花」が含まれないようにします。

シンガポールリージョンと北京リージョンの API キーは異なります。詳細については、「API キーの取得」をご参照ください。
次の例では、シンガポールリージョンのベース URL を使用しています。北京リージョンのモデルを使用する場合は、ベース URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis に置き換えてください。
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-i2v-plus",
    "input": {
        "prompt": "A cat running on the grass",
        "negative_prompt": "flowers",
        "img_url": "https://cdn.translate.alibaba.com/r/wanx-demo-1.png"
    },
    "parameters": {
        "resolution": "480P",
        "prompt_extend": true
    }
}'
リクエストヘッダー

Content-Type string (必須)

リクエストのコンテンツタイプ。このパラメーターを application/json に設定します。

Authorization string (必須)

リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例:Bearer sk-xxxx。

X-DashScope-Async string (必須)

非同期処理の設定パラメーター。HTTP リクエストは非同期処理のみをサポートします。このパラメーターを enable に設定する必要があります。

重要

このリクエストヘッダーがない場合、「current user api does not support synchronous calls」というエラーメッセージが返されます。

リクエストボディ

model string (必須)

モデル名。例:wan2.2-i2v-plus。

モデルとその料金のリストについては、「モデル」をご参照ください。

input object (必須)

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

プロパティ

prompt string (任意)

生成される動画の望ましい要素や視覚的特徴を記述するテキストプロンプト。

このパラメーターは中国語と英語の両方をサポートします。各漢字または文字は 1 文字としてカウントされます。超過した文字は自動的に切り捨てられます。長さの制限はモデルのバージョンによって異なります:

  • wan2.5-i2v-preview:最大 2,000 文字。

  • wan2.2 以前のモデル:最大 800 文字。

例:草の上を走る子猫。

プロンプトの使用方法に関するヒントについては、「Text-to-video/image-to-video プロンプトガイド」をご参照ください。

negative_prompt string (任意)

動画に表示させたくないコンテンツを記述するネガティブプロンプト。これは動画コンテンツを制約するために使用できます。

このパラメーターは中国語と英語の両方をサポートします。長さは 500 文字に制限されています。超過した文字は自動的に切り捨てられます。

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

img_url string (必須)

初回フレーム画像の URL または Base64 エンコードされたデータ。

画像の制限:

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

  • 画像解像度:幅と高さは 360〜2,000 ピクセルの間である必要があります。

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

入力画像の説明:

  1. パブリックにアクセス可能な URL

    • HTTP または HTTPS プロトコルをサポートします。

    • 例:https://cdn.translate.alibaba.com/r/wanx-demo-1.png

  2. Base64 エンコードされた画像文字列

    • データフォーマット:data:{MIME_type};base64,{base64_data}

    • 例:data:image/png;base64,GDU7MtCZzEbTbmRZ......。(エンコードされた文字列は長すぎるため、一部のみ表示されています。)

    • 詳細については、「入力画像」をご参照ください。

audio_url string (任意)

wan2.5-i2v-preview のみサポート。音声ファイルの URL。モデルはこの音声を使用して動画を生成します。このパラメーターの使用方法の詳細については、「音声設定」をご参照ください。

このパラメーターは HTTP または HTTPS プロトコルをサポートします。

音声の制限:

  • フォーマット:WAV、MP3。

  • 時間:3〜30 秒。

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

  • 大きすぎるファイルの処理:音声の長さが duration の値である 5 秒または 10 秒を超える場合、音声は自動的に最初の 5 秒または 10 秒に切り捨てられます。残りの音声は破棄されます。音声が動画より短い場合、動画の残りの部分は無音になります。例えば、音声が 3 秒で動画が 5 秒の場合、出力動画の最初の 3 秒は音があり、最後の 2 秒は無音になります。

例:https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3。

parameters object (任意)

動画の解像度、動画の時間、プロンプトの再書き込み、ウォーターマークなどの動画処理パラメーター。

プロパティ

resolution string (任意)

重要

resolution パラメーターはコストに直接影響します。同じモデルの場合、コストは 1080P > 720P > 480P となります。呼び出しを行う前に、モデルの料金をご確認ください。

生成される動画の解像度レベルを指定します。この設定は、総ピクセル数で測定される動画の精細度を調整します。モデルは、選択されたレベルに基づいて、動画を類似の総ピクセル数に自動的にスケーリングします。動画のアスペクト比は、入力 `img_url` 画像のアスペクト比と可能な限り一致するように保たれます。詳細については、「よくある質問」セクションをご参照ください。

このパラメーターのデフォルト値と有効な値は、`model` パラメーターに依存し、以下のリストで説明されています:

  • wan2.5-i2v-preview:任意の値:480P、720P、1080P。デフォルト値:1080P

  • wan2.2-i2v-flash:任意の値:480P、720P。デフォルト値:720P

  • wan2.2-i2v-plus:任意の値:480P、1080P。デフォルト値:1080P

  • wan2.1-i2v-turbo:任意の値:480P、720P。デフォルト値:720P

  • wan2.1-i2v-plus:任意の値:720P。デフォルト値:720P

例:1080P。

duration integer (任意)

重要

動画時間はコストに直接影響します。課金は秒単位で行われるため、動画時間が長いほどコストが高くなります。呼び出しを行う前に、モデルの料金をご確認ください。

生成される動画の長さ (秒)。このパラメーターの有効な値は、`model` パラメーターに依存します:

  • wan2.5-i2v-preview:任意の値:5、10。デフォルト値:5。

  • wan2.2-i2v-plus:5 秒に固定されており、変更できません。

  • wan2.2-i2v-flash:5 秒に固定されており、変更できません。

  • wan2.1-i2v-plus:5 秒に固定されており、変更できません。

  • wan2.1-i2v-turbo:任意の値:3、4、または 5。デフォルト値:5。

例:5。

prompt_extend boolean (任意)

プロンプトの再書き込みを有効にするかどうかを指定します。有効にすると、大規模言語モデル (LLM) が入力プロンプトを再書き込みします。これにより、短いプロンプトの生成品質が大幅に向上しますが、所要時間が増加します。

  • true (デフォルト)

  • false

例:true。

watermark boolean (任意)

ウォーターマークを追加するかどうかを指定します。ウォーターマークには「AI-generated」というテキストが含まれ、動画の右下隅に配置されます。

  • false (デフォルト)

  • true

例:false。

audio boolean (任意)

wan2.5-i2v-preview のみサポート。音声を追加するかどうかを制御します。

パラメーターの優先順位は `audio_url` が `audio` よりも高いです。このパラメーターは audio_url が空の場合にのみ有効です。このパラメーターの使用方法の詳細については、「音声設定」をご参照ください。

  • true:(デフォルト) 動画に音声を自動的に追加します。

  • false:音声を追加しません。サイレント動画を出力します。

例:true。

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":"Invalid API-key provided.",
    "request_id":"fb53c4ec-1c12-4fc4-a580-xxxxxx"
}

output object

タスクの出力情報。

プロパティ

task_id string

タスク ID。クエリは 24 時間有効です。

task_status string

タスクのステータス。

列挙

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN:タスクが存在しないか、そのステータスを判断できません。

request_id string

一意のリクエスト ID。この ID を使用して問題を追跡し、トラブルシューティングできます。

code string

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

message string

失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

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

リクエストパラメーター

タスク結果のクエリ

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

シンガポールリージョンと北京リージョンの API キーは異なります。API キーを作成してください。
以下の `base_url` はシンガポールリージョン用です。北京リージョンのモデルの場合は、`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 (必須)

リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例:Bearer sk-xxxx。

URL パスパラメーター

task_id string (必須)

タスク ID。

レスポンスパラメーター

タスク成功

動画 URL は 24 時間のみ保持され、この期間を過ぎると自動的にパージされます。生成された動画は速やかに保存する必要があります。

{
    "request_id": "2ca1c497-f9e0-449d-9a3f-xxxxxx",
    "output": {
        "task_id": "af6efbc0-4bef-4194-8246-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-09-25 11:07:28.590",
        "scheduled_time": "2025-09-25 11:07:35.349",
        "end_time": "2025-09-25 11:17:11.650",
        "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 full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
        "video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxx",
        "actual_prompt": "A boy made of spray paint emerges from a concrete wall and begins to sing an English rap at a very fast pace, his lips moving quickly, his head nodding slightly, and his eyes looking directly at the camera. He gives a thumbs-up to the wall with his right hand and puts his left hand on his hip, moving his body back and forth to the rhythm. The audio is his continuous English rap, 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": {
        "duration": 10,
        "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+08:00 タイムゾーンです。フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。

scheduled_time string

タスクが実行を開始した時間。時間は UTC+08:00 タイムゾーンです。フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。

end_time string

タスクが完了した時間。時間は UTC+08:00 タイムゾーンです。フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。

video_url string

動画の URL。このパラメーターは、task_status が SUCCEEDED の場合にのみ返されます。

リンクは 24 時間有効です。この URL を使用して動画をダウンロードできます。動画は H.264 エンコーディングの MP4 フォーマットです。

orig_prompt string

元の入力プロンプト。これは prompt リクエストパラメーターに対応します。

actual_prompt string

プロンプトの再書き込みが有効な場合、このパラメーターは使用された実際の最適化されたプロンプトを返します。この機能が無効な場合、このパラメーターは返されません。

code string

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

message string

失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

usage object

出力情報の統計。成功した結果のみがカウントされます。

プロパティ

video_duration integer

このフィールドは現在、2.1 モデルによってのみ返されます。生成された動画の長さ (秒)。列挙値:3、4、5。

課金式:コスト = 動画時間 (秒) × 単価。

video_ratio string

このフィールドは現在、2.1 モデルによってのみ返されます。生成された動画のアスペクト比。値は「standard」に固定されています。

duration integer

このフィールドは現在、2.2 以降のモデルによってのみ返されます。生成された動画の長さ (秒)。列挙値:5、10。

課金式:コスト = 動画時間 (秒) × 単価。

SR integer

このフィールドは現在、2.2 以降のモデルによってのみ返されます。生成された動画の解像度。列挙値:480、720、1080。

video_count integer

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

request_id string

一意のリクエスト 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 エンコーディング

サンプルコード

import base64
import mimetypes


# --- 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}"


if __name__ == "__main__":
    print(encode_file("./image_demo_input.png"))
  • 例: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_urlparameters.audio パラメーターを使用して音声の動作を制御できます。優先順位:audio_url > audio。3 つのモードがサポートされています:

  1. サイレント動画の生成

    1. パラメーター設定:`audio_url` を渡さず、`audio` を `false` に設定します。

    2. シナリオ:後で独自の音声や音楽を追加する予定の純粋な視覚コンテンツに役立ちます。

  2. 音声の自動生成

    1. パラメーター設定:`audio_url` を渡さず、`audio` を `true` に設定します。

    2. 効果の説明:モデルは、プロンプトと視覚コンテンツに基づいて、一致する背景音声または音楽を自動的に生成します。

  3. カスタム音声の使用

    1. パラメーター設定:`audio_url` を渡します。この場合、`audio` パラメーターは無視されます。

    2. 効果の説明:動画コンテンツは、唇の動きやリズムなど、音声コンテンツと整合します。

課金とレート制限

  • モデルの無料クォータと料金については、「モデル」をご参照ください。

  • モデルのレート制限の詳細については、「Wan シリーズ」をご参照ください。

  • 課金の説明:

    • 正常に生成された動画の秒単位の時間に基づいて課金されます。クエリ結果 API が task_status として SUCCEEDED を返し、動画が正常に生成された場合にのみ料金が発生します。

    • モデル呼び出しの失敗や処理エラーは、料金が発生したり、無料クォータを消費したりすることはありません。

エラーコード

モデル呼び出しが失敗し、エラーメッセージが返された場合は、「エラーメッセージ」で詳細をご確認ください。

よくある質問

動画関連の質問については、「よくある質問」をご参照ください。

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 機能の例

機能

入力初回フレーム画像

入力プロンプト

出力動画

サイレント動画

image

草の上を走る猫