
# 基于首尾帧生视频
图生视频中的基于首尾帧技术，简单来说就是利用两张静态图片作为起点和终点，通过模型自动补全中间的过程，生成一段流畅的视频。
MaaS支持模型以及相关参数，请参见[支持模型]。
 #### 支持模型
表1三方模型 
| model参数（模型 ID）                    | 支持能力   | 输入输出限制                                                                                                                                                                                                                                                                                                                                                   | 默认限流    |
|:---|:---|:---|:---|
| pixverse/pixverse-v6-kf2v         | 首尾帧生视频 | 输入类型：文本+图片 最大输入限制：文本 5000 字符；图片 20MB，10000px（Base64编码）。 输出视频格式：MP4 输出视频帧率（fps）：24 输出视频最高分辨率：1080p 输出视频时长：1s～15s，可选。 | RPM: 30 |
| vidu/viduq3-pro_start-end2video   | 首尾帧生视频 | 输入类型：文本+图片 最大输入限制：文本 5000 字符；图片 50 MB（Base64编码）。 输出视频格式：MP4 输出视频帧率（fps）：24 输出视频最高分辨率：1080p 输出视频时长：1s～16s，可选。  | RPM: 30 |
| vidu/viduq3-turbo_start-end2video | 首尾帧生视频 | 输入类型：文本+图片 最大输入限制：文本5000 字符；图片50 MB（Base64编码）。 输出视频格式：MP4 输出视频帧率（fps）：24 输出视频最高分辨率：1080p 输出视频时长：1s～16s，可选。  | RPM: 30 |
   
#### 前提条件
- 已在"模型推理 \> 在线推理 \> 预置服务"页签开通预置服务。详情请见[开通MaaS预置服务](https://support.huaweicloud.com/model-call-maas/model-call-052.html)。
- 已获取API Key。详情请见[在MaaS管理API Key](https://support.huaweicloud.com/model-call-maas/model-call-049.html)。

- 已获取模型服务的model参数值。详情请见[支持模型]。
 
#### 使用限制
- 任务数据（如任务状态、视频URL等）仅保留24小时，超时后会被自动清除。请您务必及时保存生成的视频。
- 不同模型的限制值不同，具体限制值请以MaaS控制台"在线推理\>预置服务"页面的模型限流列为准。
  - TPM：每分钟处理的Tokens数（输入+输出）。
  
  - RPM：每分钟处理的请求数。
   
- 目前三方服务仅支持个人用户开通。
 
#### API说明
模型调用的完整参数列表请见[生数科技创建首尾帧生成视频任务](https://support.huaweicloud.com/model-call-maas/model-call-075.html)以及[爱诗科技创建首尾帧生成视频任务](https://support.huaweicloud.com/model-call-maas/model-call-081.html)。
#### 创建首尾帧生视频（生数科技）
此处以使用ViduQ3-Pro KF2V模型通过Python脚本和Curl命令生成视频为例，展示基于首尾帧图像和文本提示词生成视频的基本用法。
1. 创建视频生成任务。
- [Python]
  ```
  import requests
  import json
  if __name__ == '__main__':
      url = "https://api.modelarts-maas.com/v1/video/generations"  # API地址
      api_key = "MAAS_API_KEY"  # 把 MAAS_API_KEY 替换成已获取的API Key
      # Send request.
      headers = {
          'Content-Type': 'application/json',
          'Authorization': f'Bearer {api_key}'
      }
      data = {
    "model": "vidu/viduq3-pro_start-end2video",
    "input": {
  "prompt": "蓝天白云下的郊外草原，微风拂动青草，羊群缓慢走动，远处有连绵青山。",
  "media": [
    {
  "type": "first_frame",
  "url": "https://example/first_frame.jpg"
    },
    {
  "type": "last_frame",
  "url": "https://example/last_frame.jpg"
    }
  ]
    },
    "parameters": {
  "size": "1280*720",
  "duration": 5,
  "audio": True
    }
  }
      response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
      # Print result.
      print(response.status_code)
      print(response.text)
  ```
  响应示例
  ```
  {
    "task_id" : "962939796957712385"
  }
  ```
- [Curl]
  ```
  curl -X POST "https://api.modelarts-maas.com/v1/video/generations" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $MAAS_API_KEY" \
    -d '{
    "model": "vidu/viduq3-pro_start-end2video",
    "input": {
  "prompt": "蓝天白云下的郊外草原，微风拂动青草，羊群缓慢走动，远处有连绵青山。",
  "media": [
    {
  "type": "first_frame",
  "url": "https://example/first_frame.jpg"
    },
    {
  "type": "last_frame",
  "url": "https://example/last_frame.jpg"
    }
  ]
    },
    "parameters": {
  "size": "1280*720",
  "duration": 5,
  "audio": true
    }
  }'
  ```
  响应示例
  ```
  {
    "task_id" : "962939796957712385"
  }
  ```
2. 根据视频生成任务id获取视频。
![](https://support.huaweicloud.com/model-call-maas/public_sys-resources/note_3.0-zh-cn.png)
视频生成为异步接口，您需要先创建视频生成任务，再通过视频生成任务的ID去查询视频生成结果。视频生成过程耗时较长，查询结果时请您耐心等待。
- [Python]
  ```
  import requests 
  import json
  if __name__ == '__main__': 
      url = "https://api.modelarts-maas.com/v1/video/generations/task_id" # API地址。请将task_id替换为实际的ID，您可以通过创建视频生成任务API获取。
      api_key = "MAAS_API_KEY"  # 把yourApiKey替换成已获取的API Key  
      # Send request. 
      headers = { 
          'Content-Type': 'application/json', 
          'Authorization': f'Bearer {api_key}'  
      } 
      response = requests.get(url, headers=headers, verify=False) 
      # Print result. 
      print(response.status_code) 
      print(response.text)
  ```
  **响应示例**
  ```
  {
    "task_id" : "962939796957712385",
    "status" : "succeeded",
    "error" : null,
    "content" : {
      "result_url" : "https://example.com/example.mp4"
    },
    "usage" : {
      "duration" : 5,
      "size" : "1280*720",
      "audio" : true,
      "shot_type" : "single"
    },
    "created_at" : 1780281309530,
    "updated_at" : 1780281338634
  }
  ```
- [Curl]
  ```
  curl -X GET 'https://api.modelarts-maas.com/v1/video/generations/task_id' \ 
    -H "Content-Type: application/json" \ 
    -H "Authorization: Bearer $MAAS_API_KEY"
  ```
  **响应示例**
  ```
  {
    "task_id" : "962939796957712385",
    "status" : "succeeded",
    "error" : null,
    "content" : {
      "result_url" : "https://example.com/example.mp4"
    },
    "usage" : {
      "duration" : 5,
      "size" : "1280*720",
      "audio" : true,
      "shot_type" : "single"
    },
    "created_at" : 1780281309530,
    "updated_at" : 1780281338634
  }
  ```
#### 创建首尾帧生视频（爱诗科技）
此处以使用PixVerse V6 KF2V模型通过Python脚本和Curl命令生成视频为例，展示基于首尾帧图像和文本提示词生成视频的基本用法。
- [Python]
  ```
  import requests
  import json
  if __name__ == '__main__':
      url = "https://api.modelarts-maas.com/v1/video/generations"  # API地址
      api_key = "MAAS_API_KEY"  # 把 MAAS_API_KEY 替换成已获取的API Key
      # Send request.
      headers = {
          'Content-Type': 'application/json',
          'Authorization': f'Bearer {api_key}'
      }
      data = {
    "model": "pixverse/pixverse-v6-kf2v",
    "input": {
  "prompt": "蓝天白云下的郊外草原，微风拂动青草，羊群缓慢走动，远处有连绵青山。",
  "media": [
    {
  "type": "first_frame",
  "url": "https://example/first_frame.jpg"
    },
    {
  "type": "last_frame",
  "url": "https://example/last_frame.jpg"
    }
  ]
    },
    "parameters": {
  "resolution": "720p",
  "duration": 5,
  "audio": False
    }
  }
      response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
      # Print result.
      print(response.status_code)
      print(response.text)
  ```
  响应示例
  ```
  {
      "task_id": "408914860220871",
      "resolution": "720p",
      "duration": 5,
      "audio": false
  }
  ```
- [Curl]
  ```
  curl -X POST "https://api.modelarts-maas.com/v1/video/generations" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $MAAS_API_KEY" \
    -d '{
    "model": "pixverse/pixverse-v6-kf2v",
    "input": {
  "prompt": "蓝天白云下的郊外草原，微风拂动青草，羊群缓慢走动，远处有连绵青山。",
  "media": [
    {
  "type": "first_frame",
  "url": "https://example/first_frame.jpg"
    },
    {
  "type": "last_frame",
  "url": "https://example/last_frame.jpg"
    }
  ]
    },
    "parameters": {
  "resolution": "720p",
  "duration": 5,
  "audio": false
    }
  }'
  ```
  响应示例
  ```
  {
      "task_id": "408914860220871",
      "resolution": "720p",
      "duration": 5,
      "audio": false
  }
  ```
2. 根据视频生成任务id获取视频。
![](https://support.huaweicloud.com/model-call-maas/public_sys-resources/note_3.0-zh-cn.png)
视频生成为异步接口，您需要先创建视频生成任务，再通过视频生成任务的ID去查询视频生成结果。视频生成过程耗时较长，查询结果时请您耐心等待。
- [Python]
  ```
  import requests 
  import json
  if __name__ == '__main__': 
      url = "https://api.modelarts-maas.com/v1/video/generations/task_id" # API地址。请将task_id替换为实际的ID，您可以通过创建视频生成任务API获取。
      api_key = "MAAS_API_KEY"  # 把yourApiKey替换成已获取的API Key  
      # Send request. 
      headers = { 
          'Content-Type': 'application/json', 
          'Authorization': f'Bearer {api_key}'  
      } 
      response = requests.get(url, headers=headers, verify=False) 
      # Print result. 
      print(response.status_code) 
      print(response.text)
  ```
  **响应示例**
  ```
  {
      "task_id": "408914860220871",
      "status": "succeeded",
      "error": {
          "code": 0,
          "message": ""
      },
      "content": {
          "result_url": "https://example.com/example.mp4"
      },
      "usage": {
          "duration": 5,
          "audio": false,
          "resolution": "720p"
      },
      "created_at": 1781787813000,
      "updated_at": 1781787832000
  }
  ```
- [Curl]
  ```
  curl -X GET 'https://api.modelarts-maas.com/v1/video/generations/task_id' \ 
    -H "Content-Type: application/json" \ 
    -H "Authorization: Bearer $MAAS_API_KEY"
  ```
  **响应示例**
  ```
  {
      "task_id": "408914860220871",
      "status": "succeeded",
      "error": {
          "code": 0,
          "message": ""
      },
      "content": {
          "result_url": "https://example.com/example.mp4"
      },
      "usage": {
          "duration": 5,
          "audio": false,
          "resolution": "720p"
      },
      "created_at": 1781787813000,
      "updated_at": 1781787832000
  }
  ```
