在线AI教程 / AI上云
[Amazon Bedrock] TwelveLabs 的 Pegasus 1.5 现已在 Amazon Bedrock 中提供
人工智能 TwelveLabs 的 Pegasus 1.5 现已在 Amazon Bedrock 中提供 2026 年 10 月 9 日,我们宣布 TwelveLabs’ Pega
人工智能
TwelveLabs 的 Pegasus 1.5 现已在 Amazon Bedrock 中提供
2026 年 10 月 9 日,我们宣布 TwelveLabs’ Pegasus 1.5 在 Amazon Bedrock 上可用。 Pegasus 1.5 是一种视频语言模型,可将长格式视频转换为结构化的带时间戳的元数据。您描述对工作流程重要的时刻,模型会以 JSON 形式返回每个匹配的片段。
视频代表了一类重要且复杂的非结构化数据,但其中大部分仍然无法搜索且未得到充分利用。从这些内容中提取结构化的、可操作的见解历来需要劳动密集型的手动审查或分散的工具链。
在 Pegasus 的早期版本中,您可以将模型指向剪辑,提出问题并获得答案。现在,Pegasus 1.5 可以分析整个视频,找到符合用户定义标准的每个片段,并返回结构化的带时间戳的元数据。它还介绍了视频分割、参考图像的多模式提示以及即时处理。
借助 Amazon Bedrock 上的 Pegasus 1.5,您可以直接从 Amazon Simple Storage Service (Amazon S3) URI 或 base64 字符串分析视频,无需预先索引,并且您的数据保留在 AWS 数据边界内。
在这篇文章中,我们将介绍 Pegasus 1.5 中的新增功能、如何在 Amazon Bedrock 上打包模型以及如何发送您的第一个请求。然后,我们将介绍视频分段、结构化 JSON 输出和多模式提示。
Pegasus 1.5 的新功能
Pegasus 1.5与之前版本相比有以下变化:
基于时间的元数据生成。 您可以定义对您的工作流程重要的片段、事件或特定领域的提示,例如编辑片段、体育赛事、演讲者更换或品牌外观。 Pegasus 1.5 以 JSON 形式返回每个匹配的段,其中包含开始时间和结束时间以及填充的请求字段。 多模式提示。 段定义可以将文本描述与视觉参考相结合。这使得定位特定产品、徽标或人员以及他们在屏幕上所做的事情成为可能。 即时处理。不需要摄取管道或预索引步骤。视频直接从 Amazon S3 发送,结果在响应中返回。 扩展处理能力。 Pegasus 1.5 在单个请求中分析长达两个小时的视频,而 Pegasus 1.2 中为一小时。
Pegasus 1.5 保留并增强了 Pegasus 1.2 成为视频理解强大工具的核心功能,包括:
视频到文本生成:根据视频内容创建详细的文本描述。 精细的视觉理解:分析视频帧内的对象、屏幕文本和数字内容。 时间接地:准确识别视频中特定事件的时间戳。 多模态理解:结合视觉、音频和文本信息进行综合分析。 多语言支持:完全支持英语,部分支持阿拉伯语、中文、法语、德语、意大利语、日语、韩语、葡萄牙语、俄语、西班牙语、泰语和越南语。
Pegasus 1.5 如何在 Amazon Bedrock 上运行
Pegasus 1.5 获取视频和文本提示或一组片段定义,并返回文本或 JSON。您可以使用“InvokeModel” API 在“bedrock-runtime”端点上调用它,或者当您希望响应在生成时进行流式传输时,可以使用“InvokeModelWithResponseStream”来调用它。
设置价值 型号 IDtwelvelabs.pegasus-1-5-v1:0 AWS 区域美国西部(俄勒冈州),us-west-2 推论点播 APIInvokeModel、InvokeModelWithResponseStream
每个请求都以两种分析模式之一运行,通过“analysisMode”字段进行选择:
分析模式分析模式您发送你回来 一般一般(默认)inputPrompt 中的文本提示当您提供模式时,“消息”或 JSON 中的文本答案 基于时间的元数据基于时间的元数据responseFormat 中的段定义包含开始和结束时间以及您要求的字段的“分段”列表
您可以通过两种方式将模型指向视频。 S3 位置 (s3Location) 采用对象的 uri 和 bucketOwner 帐户 ID,适合长格式视频。 Base64 字符串 (base64String) 将视频嵌入请求正文中,最大 25 MB,适合短片。
要按应用程序跟踪成本,请从 Pegasus 1.5 模型创建应用程序推理配置文件,对其进行标记,并通过其 Amazon 资源名称 (ARN) 代替模型 ID 来调用它。
Pegasus 1.5 入门
以下部分概述了如何开始使用 Pegasus 1.5。
先决条件
在开始之前,请确保您拥有:
具有 Amazon Bedrock 访问权限的活跃 AWS 账户。 Python 3.10 或更高版本,安装了适用于 Python 的 AWS 开发工具包 (Boto3)。 “bedrock:InvokeModel”和“bedrock:InvokeModelWithResponseStream”的 AWS Identity and Access Management (IAM) 权限。 在 Amazon Bedrock 控制台 中为 TwelveLabs Pegasus 1.5 启用模型访问。 存储在 Amazon S3 存储桶中的视频,或者您可以内联发送的短片。
以下策略授予 Pegasus 1.5 上的两种调用操作。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": [ "arn:aws:bedrock:us-west-2::foundation-model/twelvelabs.pegasus-1-5-v1:0" ] } ] }
Boto3 使用您常用的 AWS 凭证签署请求。您还可以通过在“AWS_BEARER_TOKEN_BEDROCK”环境变量中设置 Amazon Bedrock API 密钥来进行身份验证。对于生产,更喜欢使用“aws-bedrock-token-generator”包从 IAM 凭证生成的短期密钥,因为它会自动过期。承载令牌身份验证还需要“bedrock:CallWithBearerToken”权限。
发送您的第一个请求
安装 Boto3:
pip install boto3
以下示例分析以常规模式存储在 Amazon S3 中的视频。此示例使用全局跨区域推理 (CRIS) 端点。要改为定位美国地理端点,请替换“全球”。与“我们”。在端点 URL 中。
import boto3 import json from botocore.config import Config
AWS_REGION = "us-west-2" MODEL_ID = "global.twelvelabs.pegasus-1-5-v1:0"
bedrock_runtime = boto3.client( service_name="bedrock-runtime", region_name=AWS_REGION, config=Config(
keep a longer read_timeout for lengthier invocations such as video segmentation
read_timeout=900, retries={"max_attempts": 0}, connect_timeout=10, ), )
Analyze a video stored in Amazon S3
payload = { "inputPrompt": "Summarize this video and identify the key topics discussed.", "mediaSource": { "s3Location": { "uri": "s3://amzn-s3-demo-pegasus-15/your-video.mp4", "bucketOwner": "your-account-id" } }, "temperature": 0.2, "maxOutputTokens": 4096, "includeMetering": True }
response = bedrock_runtime.invoke_model( modelId=MODEL_ID, body=json.dumps(payload) ) result = json.loads(response["body"].read()) print(result["message"])
响应在“message”中携带答案,在“input_tokens”和“output_tokens”中携带令牌计数,在“stopReason”中结束原因生成。 “length”的“stopReason”意味着答案在完成之前就达到了“maxOutputTokens”,因此在依赖输出之前请检查它:
if result["stopReason"] == "length": print("The answer was cut off. Raise maxOutputTokens and try again.") print("Tokens in:", result["input_tokens"], "out:", result["output_tokens"])
普通模式的请求字段:
领域必填描述 输入提示是的有关视频的问题或说明 mediaSource.s3Location.uri需要一个视频源视频的 S3 URI mediaSource.s3Location.bucketOwner与 uri拥有存储桶的 AWS 账户 ID mediaSource.base64String需要一个视频源Base64 编码的视频,最大 25 MB 温度没有输出的随机性,从 0 到 1。默认 0.2 maxOutputTokens没有生成的最大代币数量,从 512 到 98,304 响应格式没有答案必须遵循的 JSON Schema 分析模式没有general(默认)或time_based_metadata
对于短片,您可以内联发送视频,而不是从 S3 发送:
import base64
with open("your-video.mp4", "rb") as f: video_b64 = base64.b64encode(f.read()).decode("utf-8")
payload["mediaSource"] = {"base64String": video_b64} response = bedrock_runtime.invoke_model(modelId=MODEL_ID, body=json.dumps(payload)) print(json.loads(response["body"].read())["message"])
请注意,前面的示例使用可选的“includeMetering”属性。 includeMetering: True 使 Pegasus 1.5 在非流式响应中添加两个计费使用字段:outputTokenCount 和 inputVideoSecond(分析视频的持续时间(以秒为单位))。
流式传输响应
对于交互式应用程序,“InvokeModelWithResponseStream”在生成时以块的形式返回答案。每个块都携带“message”中的下一段文本:
response = bedrock_runtime.invoke_model_with_response_stream( modelId=MODEL_ID, body=json.dumps(payload) ) for event in response["body"]: chunk = json.loads(event["chunk"]["bytes"]) print(chunk.get("message", ""), end="", flush=True) print()
返回结构化 JSON
在一般模式下,您可以将答案限制为 JSON 架构,以便下游代码可以直接解析它。将 responseFormat.type 设置为 json_schema 并将 schema 放在 jsonSchema 下。答案以 JSON 字符串形式到达“message”:
payload = { "inputPrompt": "Analyze this video and return a structured summary.", "mediaSource": { "s3Location": { "uri": "s3://amzn-s3-demo-pegasus-15/your-video.mp4", "bucketOwner": "your-account-id" } }, "temperature": 0, "maxOutputTokens": 2048, "includeMetering": True, "responseFormat": { "type": "json_schema", "jsonSchema": { "type": "object", "properties": { "summary": {"type": "string"}, "key_scenes": {"type": "array", "items": {"type": "string"}}, "setting": {"type": "string"} }, "required": ["summary", "key_scenes", "setting"] } } } response = bedrock_runtime.invoke_model(modelId=MODEL_ID, body=json.dumps(payload)) summary = json.loads(json.loads(response["body"].read())["message"]) print(summary["summary"]) for scene in summary["key_scenes"]: print(" -", scene)
视频分割:将视频转化为结构化数据
基于时间的元数据生成是 Pegasus 1.5 与早期版本最大的不同之处。您无需发送提示,而是发送一个或多个片段定义,模型将返回与每个片段匹配的视频的每个片段。
将“analysisMode”设置为“time_based_metadata”,将“responseFormat.type”设置为“segment_definitions”。这些定义取代了“inputPrompt”,因此请保留该字段。每个定义都有:
id:定义的名称,在它匹配的每个段上返回。 description:匹配的片段是什么样子的。 “fields”:为每个段提取的值,每个值都有一个“name”、一个“type”(“string”、“boolean”、“number”、“integer”、“array”或“timestamp”)和一个“description”。
以下示例标识新闻广播中的每个编辑部分,并返回每个部分的标题、摘要和关键主题:
payload = { "analysisMode": "time_based_metadata", "mediaSource": { "s3Location": { "uri": "s3://amzn-s3-demo-pegasus-15/news-broadcast.mp4", "bucketOwner": "your-account-id" } }, "responseFormat": { "type": "segment_definitions", "segmentTimeFormat": "hh:mm:ss", "segmentDefinitions": [ { "id": "editorial_section", "description": "A distinct editorial section of the broadcast, " "such as a new story, topic, or segment of the program.", "fields": [ {"name": "segment_title", "type": "string", "description": "A descriptive title"}, {"name": "summary", "type": "string", "description": "A brief summary of the segment content"}, {"name": "key_topics", "type": "array", "items": {"type": "string"}, "description": "Main topics discussed"} ] } ] }, "temperature": 0, "maxOutputTokens": 32768, "includeMetering": True } response = bedrock_runtime.invoke_model( modelId=MODEL_ID, contentType="application/json", accept="application/json", body=json.dumps(payload) ) result = json.loads(response["body"].read()) for segment in result["segments"]: print(segment["start_sec"], "-", segment["end_sec"], segment["segment_title"]) print(" ", segment["summary"]) print(" topics:", ", ".join(segment["key_topics"]))
针对体育剪辑进行测试时,前面的示例代码可能会产生如下示例所示的输出。
{ "segments": [ { "start_sec": "00:04:24", "end_sec": "00:05:22", "segment_title": "Substitutions and Added Time", "summary": "The referee announces three minutes of added time, and both teams make substitutions in preparation for a potential penalty shootout.", "key_topics": ["Substitutions", "Added time", "Penalty shootout preparation", "Tactical changes"] }, { "start_sec": "00:05:22", "end_sec": "00:08:57", "segment_title": "Last Gasp Attempts and Final Whistle", "summary": "The final minutes of the match see intense action from both sides, with several close calls before the referee blows the final whistle, ending the game in a 3-3 draw.", "key_topics": ["Final whistle", "Draw"] }, { "start_sec": "00:08:57", "end_sec": "00:09:29", "segment_title": "Match Conclusion and Penalty Shootout Setup", "summary": "The match concludes with a 3-3 draw, leading to a penalty shootout. Players from both teams shake hands and prepare for the decisive moments.", "key_topics": ["Match conclusion", "Penalty shootout", "Player handshakes", "Final"] } ], "definition_errors": [], "input_tokens": 249408, "output_tokens": 802, "stopReason": "stop", "finish_reason": "stop" }
每个段都包含“start_sec”、“end_sec”和您定义的“fields”。 segmentTimeFormat 控制时间的写入方式:seconds 返回可以进行算术运算的数字,而 hh:mm:ss 和 hh:mm:ss.fff 以字符串形式返回可读时间戳。响应还包括一个“definition_errors”列表,在处理每个定义时该列表为空。
单个请求可以包括多个分段定义,例如一个用于编辑部分,另一个用于屏幕上的品牌外观。 Pegasus 1.5 在一个“段”列表中返回所有段的匹配项,并用“_definition_id”标记每个段,以便您可以区分它们。以下示例向前一个请求添加第二个定义并对结果进行分组:
from collections import defaultdict
payload["responseFormat"]["segmentDefinitions"].append({ "id": "brand_appearance", "description": "A shot where a company logo or branded product " "is clearly visible on screen.", "fields": [ {"name": "brand", "type": "string", "description": "The brand shown"}, {"name": "is_prominent", "type": "boolean", "description": "Whether the brand is the main focus of the shot"} ] }) response = bedrock_runtime.invoke_model(modelId=MODEL_ID, body=json.dumps(payload)) result = json.loads(response["body"].read()) by_definition = defaultdict(list) for segment in result["segments"]: by_definition[segment["_definition_id"]].append(segment) for definition_id, segments in by_definition.items(): print(definition_id, len(segments), "segments")
由于架构定义一次,因此可以在整个视频库中应用相同的定义,从而为每个资产生成一致的元数据。
多模式提示:为您的查询添加视觉上下文
Pegasus 1.5 引入了多模式提示,因此您可以在文本提示旁边包含参考图像。当您想要向模型询问更容易显示而不是描述的特定对象、人物或场景时,这非常有用。
例如,您可以提供产品图像并要求模型识别该产品出现在视频中的每个时刻。或者,您可以提供特定徽标的参考图像,并要求模型检测品牌外观及其时间戳。此功能提高了视频分析的精度,并开辟了视觉品牌监控、产品植入分析和图像引导内容搜索等用例。
根据模式的不同,参考图像的附加方式也不同。在一般模式下,将它们放在“promptV2.mediaSources”中,与“promptV2.inputText”中的问题一起。在分段模式(“analysisMode:time_based_metadata”)下,将它们附加到“responseFormat.segmentDefinitions”内每个分段定义的“mediaSources”。然后,定义可以与视觉参考以及文本描述相匹配。每个图像都需要一个“name”、一个“image”的“media_type”以及一个源:一个内联“base64String”或一个带有“uri”和“bucketOwner”的“s3Location”。单个请求最多可以携带 30 个参考图像。
通用模式请求向模型询问参考图像中显示的对象。以下示例有效负载和响应提供了通用模式下的示例。
payload = { "analysisMode": "general", "mediaSource": {"s3Location": {"uri": "s3://...", "bucketOwner": "..."}}, "promptV2": { "inputText": "Does the object in the reference image appear in this video?", "mediaSources": [ {"name": "ref1", "media_type": "image", "base64String": "..."} ] } … }
{ "input_tokens": 144, "output_tokens": 11, "message": "Yes, the green canoe appears in the video.", "stopReason": "stop" }
在分段模式下,参考图像位于定义内,因此 Pegasus 仅返回该产品出现的分段。以下示例有效负载和响应提供了分段模式下的示例。
payload = { "analysisMode": "time_based_metadata", "mediaSource": {"s3Location": {"uri": "s3://...", "bucketOwner": "..."}}, "responseFormat": { "type": "segment_definitions", "segmentTimeFormat": "hh:mm:ss", "segmentDefinitions": [ { "id": "product_appearance", "description": "A shot showing the product in the reference image", "fields": [ {"name": "what", "type": "string", "description": "what is on screen"} ], "mediaSources": [ {"name": "ref1", "media_type": "image", "s3Location": {"uri": "s3://...", "bucketOwner": "..."}} ] } ] } }
{ "segments": [ {"start_sec": "00:00:00", "end_sec": "00:00:02", "what": "A family of four in a green canoe, paddling on a calm river surrounded by towering red rock formations."}, {"start_sec": "00:00:09", "end_sec": "00:00:10", "what": "The family back in the canoe, paddling away from the shore, with the children smiling and enjoying the serene surroundings."} ], "definition_errors": [], "input_tokens": 4498, "output_tokens": 292, "stopReason": "stop", "finish_reason": "stop" }
监控使用情况
Pegasus 1.5 在其模型 ID 下的“AWS/Bedrock”命名空间中发布 Amazon CloudWatch 指标,包括“Initations”、“OutputTokenCount”、“InitationLatency”和“InitationClientErrors”。使用它们来跟踪音量和延迟。当您需要按应用程序细分使用情况时,请将它们与应用程序推理配置文件配对。
用例
Pegasus 1.5 专为管理大量长视频的组织而设计:
新闻和广播档案:团队可以一次定义编辑片段、主题和演讲者变更,然后对以前只能通过文字记录关键字搜索的多年镜头进行编目。 体育广播公司和联盟:检测整个比赛镜头中的比赛、得分事件和其他关键时刻,加快精彩片段的制作。 流媒体应用程序:场景级元数据支持基于时刻的推荐、上下文广告投放和分段级品牌安全审查。
在每种情况下,人员仍然是工作流程的一部分。他们的工作从手动查找和标记每个时刻转变为审查和完善模型生成的元数据。
输入要求
Pegasus 1.5 支持以下视频规格:
持续时间:最多 2 小时。 文件大小:Amazon S3 最大为 2 GB,或者作为 base64 字符串最大为 25 MB。 分辨率:360×360 至 5184×2160。 纵横比:介于 1:1 和 2.4:1 之间,或其倒数。 格式:FFmpeg 支持的格式。
现已推出
TwelveLabs Pegasus 1.5 现已在美国西部(俄勒冈)AWS 区域的 Amazon Bedrock 上推出。检查完整区域列表以获取未来更新,并访问Amazon Bedrock 定价页面以获取定价信息。 Pegasus 1.5 通过 AWS Marketplace 计费,因此其费用显示在您的 AWS 账单以及 TwelveLabs 下的 AWS Cost Explorer 中,而不是 Amazon Bedrock 中。
开始使用:
访问 Amazon Bedrock 上的 TwelveLabs 模型页面 以了解有关模型系列的更多信息。 查看 Pegasus 1.5 模型卡 了解功能支持、区域可用性和示例代码。 通过 AWS re:Post for Amazon Bedrock 或通过您常用的 AWS Support 联系人向我们发送反馈。
我们很高兴看到您在 Amazon Bedrock 中使用 TwelveLabs Pegasus 1.5 构建的内容。
关于作者