通过提供初始起始图像和文本提示来生成视频。
为了获得最佳效果, 文本提示应该描述图像, 并提供希望视频具有的所需动作和摄像机移动的详细信息。
将下面的图片下载保存为sample-frame-1.png:

修改下面代码的s3_destination_bucket、input_image_path和video_prompt变量并运行:
from random import randint
import json
import boto3
import base64
client = boto3.client(service_name='bedrock-runtime', region_name="us-east-1")
s3_destination_bucket = "xx-videos"  # Change this to a unique bucket name.
# Define the image to use as the input image.
input_image_path = "sample-frame-1.png"  # Must be 1280 x 720
# Load the input image as a Base64 string.
with open(input_image_path, "rb") as f:
    input_image_bytes = f.read()
    input_image_base64 = base64.b64encode(input_image_bytes).decode("utf-8")
inference_params = {
    "taskType": "TEXT_VIDEO",
    "textToVideoParams": {
        "text": "dolly forward", # 向前移动
        "images": [
            {
                "format": "png",  # May be "png" or "jpeg"
                "source": {
                    "bytes": input_image_base64
                }
            }
        ]
    },
    "videoGenerationConfig": {
        "durationSeconds": 6,  # 6 is the only supported value currently.
        "fps": 24,  # 24 is the only supported value currently.
        "dimension": "1280x720",  # "1280x720" is the only supported value currently.
        "seed": randint(
            0, 2147483648
        ),  # A random seed guarantees we'll get a different result each time this code runs.
    },
}
response = client.start_async_invoke(
    modelInput=inference_params,
    modelId="amazon.nova-reel-v1:0",
    outputDataConfig={"s3OutputDataConfig": {"s3Uri": f"s3://{s3_destination_bucket}"}},
)
print(response)
{
    "taskType": "TEXT_VIDEO",
    "textToVideoParams": {
        "text": 字符串,
        "images": ImageSource[] (包含单个ImageSource的列表)
    },
    "videoGenerationConfig": {
        "durationSeconds": 整数,
        "fps": 整数,
        "dimension": 字符串, 
        "seed": 整数
    }
}
等待任务完成:

查看输出视频:
