Skip to main content
This example demonstrates how to use the video recording tools to capture and analyze video content playing on a mobile device screen.
This example is available on GitHub: video_transcription_example.py

What This Example Does

1

Opens a video app

Navigates to YouTube or another video platform
2

Starts screen recording

Begins capturing the device screen in the background
3

Plays video content

Lets the video play for a specified duration
4

Stops and analyzes

Stops recording and uses Gemini to analyze the video content

Prerequisites

Video recording tools require additional setup:
  1. ffmpeg must be installed on your system (for video compression)
  2. A video-capable Gemini model must be configured in utils.video_analyzer

Install ffmpeg

Supported Video Analyzer Models

The video_analyzer utility requires a video-capable Gemini model:

Video Recording Tools

When video recording is enabled, the agent has access to two tools:

start_video_recording

Starts a background screen recording on the mobile device.
  • Recording continues until stop_video_recording is called
  • No duration limit - recording runs as long as needed
  • Audio: Not captured (video only)
On Android, the native screenrecord command has a 3-minute limit, but mobile-use automatically handles this by segmenting and concatenating recordings seamlessly. You don’t need to worry about this limit.

stop_video_recording

Stops the current screen recording and analyzes the video content.
str
default:"Describe what happened in the video."
Specifies what to extract from the video. Examples:
  • "Describe what actions are shown on screen"
  • "What happens after each 10 seconds of the video?"
  • "List all UI elements and buttons that appear"

Complete Code

video_transcription_example.py

Code Breakdown

1. Configure video_analyzer in LLMConfigUtils

The key configuration is adding video_analyzer to your LLMConfigUtils:
The video_analyzer is optional in LLMConfigUtils. It’s only required when using video recording tools.

2. Enable Video Recording Tools

Use the builder method to enable video tools:
Calling with_video_recording_tools() will raise FFmpegNotInstalledError if ffmpeg is not installed.

3. Use Recording in Task Goals

The agent can now use recording tools in natural language goals:

Configuration File Approach

You can also configure video_analyzer in a JSONC config file:
llm-config.video.jsonc
Then use it:

How It Works

Android’s native screenrecord command has a 3-minute hard limit. To work around this, mobile-use:
  1. Automatically restarts recording before each 3-minute segment ends
  2. Saves each segment locally
  3. Concatenates all segments using ffmpeg when you stop recording
Result: You can record for as long as you need - the segmentation is handled transparently.

Use Cases

Custom Analysis Prompts

The stop_video_recording tool accepts a prompt parameter for custom analysis:

Troubleshooting

Error: ffmpeg is required for video recording but is not installedSolution: Install ffmpeg using your system’s package manager:
  • macOS: brew install ffmpeg
  • Linux: apt install ffmpeg or dnf install ffmpeg
  • Windows: Download from ffmpeg.org
Error: with_video_recording_tools() requires 'video_analyzer' in utilsSolution: Add video_analyzer to your profile’s LLMConfigUtils:
Warning: Concatenation failed, using last segment onlyCause: ffmpeg failed to merge video segments (Android only).Solution: Ensure ffmpeg is properly installed and working. The recording will still succeed but may only contain the last 3-minute segment.
Error: Recording stopped but analysis failedPossible causes:
  • Video file too large (>14MB after compression)
  • Gemini API rate limits
  • Invalid video format
Solution: Try shorter recordings or check your Google API quota.

Best Practices

Keep Recordings Short

Shorter recordings (under 2 minutes) process faster and more reliably

Use Specific Prompts

Tell the agent exactly what to extract: “list all buttons shown” vs “describe the workflow”

Configure Fallbacks

Always set a fallback model for video_analyzer in case of API issues

Test ffmpeg First

Verify ffmpeg works before running: ffmpeg -version

Next Steps

Agent Profiles

Learn more about configuring video_analyzer

AgentConfigBuilder

Full builder reference including with_video_recording_tools()