Analyze videos
Use the TwelveLabs Pegasus 1.2 model to analyze videos and generate text based on their content.
Model specifications
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
boto3library. - 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 contentmediaSource: The video source, which contains either:base64String: Your base64-encoded video for inline processings3Location: 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”).
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:
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.