Skip to main content
Glama

extract_frames_from_video

Extract frames from a video at specified intervals or total count, saving them in PNG, JPG, or WebP formats. Ideal for creating still images, thumbnails, or analyzing video content.

Instructions

提取视频中的图像。

参数:
video_path(str) - 视频路径。
fps(int) - 每多少秒抽一帧,如果传0,代表全部都抽,传1,代表每一秒抽1帧。
output_folder(str) - 把图片输出到哪个目录
format(int) - 抽取的图片格式,0:代表png 1:jpg 2:webp
total_frames(int) - 最多抽取多少张,0代表不限制

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNo
fpsNo
output_folderNo
total_framesNo
video_pathYes

Implementation Reference

  • MCP tool handler for 'extract_frames_from_video' decorated with @mcp.tool(). Includes input parameters schema in docstring and delegates to helper function in cut_video.py.
    @mcp.tool()   
    def extract_frames_from_video(video_path,fps=0, output_folder=None, format=0, total_frames=0):
        """
        提取视频中的图像。
    
        参数:
        video_path(str) - 视频路径。
        fps(int) - 每多少秒抽一帧,如果传0,代表全部都抽,传1,代表每一秒抽1帧。
        output_folder(str) - 把图片输出到哪个目录
        format(int) - 抽取的图片格式,0:代表png 1:jpg 2:webp
        total_frames(int) - 最多抽取多少张,0代表不限制
        """ 
        return cut_video.extract_frames_from_video(video_path, fps, output_folder, format, total_frames)
  • Core implementation of frame extraction using FFmpeg, handling parameters to construct the command for extracting frames at specified fps, format, and total_frames limit.
    def extract_frames_from_video(video_path,fps=0, output_folder=None, format=0, total_frames=0):
        """
        使用 FFmpeg 提取视频中的每一帧图像。
    
        :param video_path: 视频文件的路径。
        :param fps: 每多少秒抽一帧,如果传0,代表每一帧都抽
        :param output_folder: 输出图像的文件夹路径。
        :param format: 输出图像的图片格式 0:png 1:jpg 2:webp。
        """
        # 确保输出文件夹存在
        if output_folder == None:
              output_folder = os.path.dirname(video_path)
        if not os.path.exists(output_folder):
            os.makedirs(output_folder)
        img_ext = "png"
        if (format == 0):
            img_ext = "png"
        elif (format == 1):
            img_ext = "jpg"
        else:
            img_ext = "webp"
        output_path = os.path.join(output_folder, f'frame_%04d.{img_ext}')
        try:
            cmd = f" -i {video_path}"
            # 执行 FFmpeg 命令
            if fps > 0:
                cmd = f" {cmd} -vf 'fps=1/{fps}'"
            else:
                cmd = f" {cmd} -vsync 0"
            if (total_frames > 0):
                cmd = f" {cmd} -vframes {total_frames} "
            cmd = f" {cmd} -y {output_path}"
            status_code, log = ffmpeg.run_ffmpeg(cmd, timeout=1000)
            print(log)
            return {status_code, log, output_path}
        except Exception as e:
            print(f"抽取失败: {str(e)}")
            return {-1, str(e), ""}
Behavior2/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 describes the extraction action but lacks critical details: it doesn't mention whether this is a read-only or destructive operation, potential performance impacts (e.g., large video processing), error handling, or output behavior (e.g., file creation confirmation). The description covers basic functionality but misses important behavioral traits.

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

Conciseness4/5

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

The description is well-structured and appropriately sized. It starts with a clear purpose statement, followed by a bullet-point-like list of parameters with explanations. Each sentence adds value without redundancy. Minor improvement could be made by front-loading key constraints, but overall it's efficient.

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

Completeness3/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 is partially complete. It thoroughly documents parameters but lacks context on behavioral aspects (e.g., side effects, errors) and output details. Without annotations or output schema, users might not understand the full operation scope, though parameter coverage is excellent.

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

Parameters5/5

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

The description adds significant value beyond the input schema, which has 0% schema description coverage. It clearly explains all five parameters in Chinese, including 'video_path' (video path), 'fps' (frames per second with examples), 'output_folder' (output directory), 'format' (image format with mappings: 0=PNG, 1=JPG, 2=WEBP), and 'total_frames' (maximum frames, 0=unlimited). This compensates fully for the schema's lack of descriptions.

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

Purpose4/5

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

The description clearly states the tool's purpose: '提取视频中的图像' (extract frames from video). It specifies the verb (extract) and resource (frames from video), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'clip_video' or 'get_video_info', which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., video file accessibility), compare to siblings like 'clip_video' for different operations, or specify scenarios where extraction is appropriate. Usage is implied but not explicitly stated.

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

Related 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/video-creator/ffmpeg-mcp'

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