Analyze videos

Use the TwelveLabs Pegasus 1.2 model to analyze videos and generate text based on their content.

Model specifications

SpecificationsDetails
Model IDtwelvelabs.pegasus-1-2-v1:0
Regional availabilityUS West (Oregon), US East (N. Virginia), Europe (Ireland), Asia Pacific (Seoul) via cross-region inference
InputVideo
Input methodsS3 URI or base64 encoded string
OutputText

Input requirements

  • Format: Video files
  • Maximum duration: 1 hour
  • Maximum file size: 2 GB (S3) or 36 MB (base64)

Pricing

For details on pricing, see the Amazon Bedrock pricing page.

Prerequisites

Before you start, ensure you have the following:

  • An AWS account with access to a region where the TwelveLabs models are supported.
  • An AWS IAM principal with sufficient Amazon Bedrock permissions. For details on setting permissions, see the Identity and access management for Amazon Bedrock page.
  • S3 permissions to read input files.
  • The AWS CLI and configured with your credentials.
  • Python 3.7 or later with the boto3 library.
  • Access to the model you want to use. Navigate to the AWS Console > Bedrock > Model Access page and request access. Note that the availability of the models varies by region.

Analyze videos

Pegasus supports base64 encoded strings and S3 URIs for video input. The base64 method has a 36MB file size limit. This guide uses S3 URIs.

Note

Your S3 bucket and the model must be in the same region. If regions don’t match, the API returns a ValidationException error.

You use the InvokeModel API to analyze videos and generate text. This API processes your request synchronously and returns the generated text directly in the response.

The InvokeModel API requires two parameters:

  • modelId: The inference profile ID for the model.
  • body: A JSON-encoded string containing your input parameters.

The body contains:

  • inputPrompt: A string that guides the model on the desired format or content
  • mediaSource: The video source, which contains either:
    • base64String: Your base64-encoded video for inline processing
    • s3Location: The S3 location for videos stored in S3

Example

The example code below demonstrates how to use Pegasus to analyze videos and generate text based on their content.

Ensure you replace the following placeholders with your values:

  • <YOUR_REGION>: with your region (example: “eu-west-1”).
  • <YOUR_ACCOUNT_ID>: with your AWS account ID (example: “123456789012”).
  • <YOUR_BUCKET_NAME>: with the name of your S3 bucket (example: “my-video-bucket”).
  • <YOUR_VIDEO_FILE>: with the name of your video file (example: “my_video.mp4”).
  • <YOUR_PROMPT>: with a string that guides the model on the desired format or content (example: “Summarize this video”).
Python
1import boto3
2import json
3import base64
4
5REGION = "<YOUR_REGION>"
6INFERENCE_PROFILE_ID = "eu.twelvelabs.pegasus-1-2-v1:0"
7INPUT_PROMPT = "<YOUR_PROMPT>"
8ACCOUNT_ID = "<YOUR_ACCOUNT_ID>"
9BUCKET = "<YOUR_BUCKET_NAME>"
10FILE_NAME = "<YOUR_VIDEO_FILE>"
11
12bedrock = boto3.client(service_name="bedrock-runtime", region_name=REGION)
13body = json.dumps({
14 "inputPrompt": INPUT_PROMPT,
15 "mediaSource": {
16 "s3Location": {
17 "uri": f"s3://{BUCKET}/{FILE_NAME}",
18 "bucketOwner": ACCOUNT_ID
19 }
20 }
21})
22
23response = bedrock.invoke_model(
24 body=body,
25 modelId=INFERENCE_PROFILE_ID,
26 contentType="application/json",
27 accept="application/json"
28)
29
30response_body = json.loads(response.get("body").read())
31print(response_body)

Use the generated text

After generating text from your videos, you can integrate the output into various applications and workflows.

The typical workflow is as follows:

1

Generate text from your video.

2

Parse and format the generated text based on your needs.

3

Store the text with video metadata in your database.

4

Index the text for search capabilities.

5

Display or process the text in your application.

You can use Pegasus-generated text to:

  • Populate content management systems with video descriptions and metadata.
  • Enable text-based search across your video library.
  • Generate automated reports for compliance or documentation.
  • Create accessible content with transcriptions and descriptions.
  • Feed downstream AI workflows such as translation or sentiment analysis.
  • Trigger automated actions based on video content analysis.

Request parameters and response fields

For a complete list of request parameters and response fields, see the TwelveLabs Pegasus 1.2 page in the Amazon Bedrock documentation.