跳转到主要内容
图生视频

图生视频:首尾帧

根据两帧图片生成过渡视频

  • 视频规格:自定义视频分辨率(wan2.7 支持 720P/1080P;wan2.2 支持 480P/720P/1080P)。时长:wan2.7 为 2-15 秒,wan2.2 固定 5 秒。
  • 音频能力:wan2.7 支持自动配音和自定义音频,实现音视频同步。
  • 其他能力:提示词改写和水印。
快捷入口: API 参考:wan2.7wan2.2 | 提示词指南

快速开始

提示词首帧尾帧输出视频
一个可爱且表情有些忧伤的蓝色小怪物站在雨中。镜头缓慢拉近,定格在小怪物抬头仰望天空的瞬间。
image
image
调用 API 前,请先获取 API Key,然后将 API Key 设置为环境变量
  • curl (wan2.7)
  • curl (wan2.2)
Wan 2.7 的首尾帧视频生成使用与首帧图生视频相同的 wan2.7-i2v 模型。在 media 数组中同时提供 first_framelast_frame 即可。第 1 步:创建任务
curl --location 'https://dashscope.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.7-i2v",
  "input": {
    "prompt": "写实风格,一只小黑猫好奇地仰望天空,镜头从平视角度逐渐升高,最后以俯视角度捕捉到它好奇的眼神。",
    "media": [
      {
        "type": "first_frame",
        "url": "https://wanx.alicdn.com/material/20250318/first_frame.png"
      },
      {
        "type": "last_frame",
        "url": "https://wanx.alicdn.com/material/20250318/last_frame.png"
      }
    ]
  },
  "parameters": {
    "resolution": "720P",
    "duration": 10,
    "prompt_extend": false,
    "watermark": true
  }
}'
第 2 步:通过任务 ID 获取结果{task_id} 替换为上一步 API 调用返回的 task_id 值。
curl -X GET 'https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}' \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
与 wan2.2 的主要区别:wan2.7 使用 resolution(720P/1080P)而非像素尺寸,支持 2-15 秒时长(非固定 5 秒),使用 media 数组而非 first_frame_url/last_frame_url 参数。watermark 默认为 false
使用 SDK 前,请先安装 DashScope SDK
  • Python SDK
  • Java SDK
运行以下代码前,请确保 DashScope Python SDK 版本不低于 1.25.8版本过低可能出现 "url error, please check url!" 错误。安装 SDK
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope

dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
api_key = os.getenv("DASHSCOPE_API_KEY")

print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
                            model="wan2.2-kf2v-flash",
                            prompt="一个可爱且表情有些忧伤的蓝色小怪物站在雨中。镜头缓慢拉近,定格在小怪物抬头仰望天空的瞬间。",
                            first_frame_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/ixdxvt/wan-kf2v-blue-1.png",
                            last_frame_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/nhtdrc/wan-kf2v-blue-2.png",
                            duration=5,  # 固定为 5 秒,请勿修改
                            prompt_extend=True,
                            watermark=True)
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))
示例输出
video_url 在 24 小时后过期,请及时下载视频。
{
  "request_id": "c1209113-8437-424f-a386-xxxxxx",
  "output": {
    "task_id": "966cebcd-dedc-4962-af88-xxxxxx",
    "task_status": "SUCCEEDED",
    "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
         ...
  },
  ...
}

核心能力

说明:根据首帧和尾帧图片生成流畅的过渡视频。

wan2.7-i2v 参数

使用 media 数组并设置 first_framelast_frame 类型。首帧图生视频和首尾帧图生视频共用同一模型和端点。
  • input.prompt:必选。最多 5,000 字符。
  • input.media:必选。数组中包含一个 first_frame 元素和一个 last_frame 元素。
  • input.negative_prompt:可选。最多 500 字符。
  • parameters.resolution:可选。720P1080P(默认:1080P)。
  • parameters.duration:可选。2-15 秒(默认:5)。
  • parameters.prompt_extend:可选。默认:true
  • parameters.watermark:可选。默认:false
  • parameters.seed:可选。取值范围 0 ~ 2147483647。

wan2.2 / wan2.1 参数

  • first_frame_url:必选。首帧图片的 URL。输出视频的宽高比与该图片一致。URL 必须可公开访问(HTTP 或 HTTPS)。图片要求:格式为 JPEG、JPG、PNG(无 alpha 通道)、BMP、WEBP。分辨率每边 360-2000 像素。文件大小不超过 10 MB。
  • last_frame_url:必选。尾帧图片的 URL。URL 必须可公开访问(HTTP 或 HTTPS)。分辨率可以与首帧不同,无需对齐。图片要求:与首帧相同。
  • prompt:可选但建议填写。描述期望视频内容的文本提示词,支持中英文。最多 800 字符,超出部分自动截断。如果首帧和尾帧的主体或场景发生了变化,请描述过渡方式(如镜头运动或主体运动)。
  • negative_prompt:可选。描述不希望在视频中出现的内容,支持中英文。最多 500 字符,超出部分自动截断。
  • seed:可选。用于复现结果的随机种子。取值范围:0 ~ 2147483647。未指定时使用随机种子。由于模型的随机性,结果可能仍有差异。
提示词首帧尾帧输出视频
写实风格,一只小黑猫好奇地仰望天空,镜头从平视角度逐渐升高,最后以俯视角度捕捉到它好奇的眼神。
首帧图片
尾帧图片
  • Python SDK
  • Java SDK
  • curl
请确保 DashScope Python SDK 版本不低于 1.25.8安装 SDK
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope

dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_async_call_kf2v():
  # 异步调用返回 task_id
  rsp = VideoSynthesis.async_call(api_key=api_key,
                  model="wan2.2-kf2v-flash",
                  prompt="写实风格,一只小黑猫好奇地仰望天空,镜头从平视角度逐渐升高,最后以俯视角度捕捉到它好奇的眼神。",
                  first_frame_url="https://wanx.alicdn.com/material/20250318/first_frame.png",
                  last_frame_url="https://wanx.alicdn.com/material/20250318/last_frame.png",
                  duration=5,  # 固定为 5 秒,请勿修改
                  prompt_extend=True,
                  watermark=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))

  # 等待异步任务完成
  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()

输入图片

  • 图片数量:一张首帧图片和一张尾帧图片。
  • 图片格式:JPEG、JPG、PNG(无 alpha 通道)、BMP、WEBP。
  • 图片分辨率:每边 360-2000 像素。
  • 文件大小上限:每张图片 10 MB。
  • 输入方式:图片 URL、本地文件路径。
  • 公开 URL:支持 HTTP 或 HTTPS。示例:https://xxxx/xxx.png