Skip to main content
Glama

extractKeyframes

Extract keyframe images from downloaded videos at regular intervals to analyze visual content without classification. Specify interval, format, and dimensions for raw frame output.

Instructions

Extract keyframe images from a locally downloaded video at regular intervals using ffmpeg. Requires the video to be downloaded first via downloadAsset. Does NOT do visual search or classification — produces raw frame images.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
videoIdOrUrlYesVideo ID or URL (must have a local video asset)
intervalSecNoExtract one frame every N seconds (default 30)
maxFramesNoMaximum frames to extract (default 20)
imageFormatNoOutput image format (default jpg)
widthNoImage width in pixels, height auto-scaled (default 640)

Implementation Reference

  • The extractKeyframes method in ThumbnailExtractor class, which performs the keyframe extraction by calculating timestamps, creating output directories, and running ffmpeg commands via extractFrames.
    async extractKeyframes(options: ExtractKeyframesOptions): Promise<ExtractKeyframesResult> {
      const startMs = Date.now();
      const intervalSec = options.intervalSec ?? 30;
      const maxFrames = options.maxFrames ?? 20;
      const imageFormat = options.imageFormat ?? "jpg";
      const width = options.width ?? 1280;
    
      // Resolve video file path
      const videoPath = options.videoPath ?? this.findVideoFile(options.videoId);
      if (!videoPath || !existsSync(videoPath)) {
        throw new Error(
          `No local video file found for ${options.videoId}. Download the video first with downloadAsset.`,
        );
      }
    
      const videoProbe = await this.probeVideo(videoPath);
      const durationSec = videoProbe.durationSec;
      if (!durationSec || durationSec <= 0) {
        throw new Error(`Could not determine duration for ${videoPath}`);
      }
    
      // Calculate timestamps
      const timestamps: number[] = [];
      for (let t = 0; t < durationSec && timestamps.length < maxFrames; t += intervalSec) {
        timestamps.push(t);
      }
    
      if (timestamps.length === 0) {
        return {
          videoId: options.videoId,
          framesExtracted: 0,
          assets: [],
          durationMs: Date.now() - startMs,
        };
      }
    
      // Create output directory
      const framesDir = join(this.store.videoDir(options.videoId), "keyframes");
      mkdirSync(framesDir, { recursive: true });
    
      // Pre-fetch existing assets once for skip checks (avoids N DB queries)
      const existingByPath = new Map(
        this.store.listAssetsForVideo(options.videoId).map((a) => [a.filePath, a]),
      );
    
      // Extract frames using seek-based approach (fast — seeks directly to each timestamp)
      const assets = await this.extractFrames({
        videoId: options.videoId,
        videoPath,
        timestamps,
        framesDir,
        imageFormat,
        width,
        existingByPath,
      });
    
      return {
        videoId: options.videoId,
        framesExtracted: assets.length,
        assets,
        durationMs: Date.now() - startMs,
      };
    }
  • Input type definition for extractKeyframes.
    export interface ExtractKeyframesInput {
      videoIdOrUrl: string;
      intervalSec?: number;
      maxFrames?: number;
      imageFormat?: "jpg" | "png" | "webp";
      width?: number;
    }
  • Output type definition for extractKeyframes.
    export interface ExtractKeyframesOutput {
      videoId: string;
      framesExtracted: number;
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behavioral traits: the tool requires a pre-downloaded video asset, uses ffmpeg for processing, produces raw frame images (not analyzed content), and operates at regular intervals. It doesn't mention error handling, performance characteristics, or output format details, but covers the essential operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with three sentences that each earn their place: first states the core functionality, second specifies the prerequisite, third clarifies what the tool does NOT do. No wasted words, front-loaded with the main purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (5 parameters, no output schema, no annotations), the description provides good contextual completeness. It covers purpose, prerequisites, limitations, and behavioral context. The main gap is lack of information about return values (what 'produces raw frame images' means in practice), but otherwise it's quite complete for the tool's scope.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain parameter interactions or provide usage examples). This meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('extract keyframe images'), resource ('from a locally downloaded video'), and method ('at regular intervals using ffmpeg'). It explicitly distinguishes from sibling tools by stating 'Does NOT do visual search or classification' and references the prerequisite tool 'downloadAsset'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage guidance: 'Requires the video to be downloaded first via downloadAsset' (prerequisite), 'Does NOT do visual search or classification' (when-not-to-use), and implies alternatives like 'findSimilarFrames' or 'searchVisualContent' for visual analysis. This gives clear context for when to use this tool versus others.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rajanrengasamy/vidlens-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server