Skip to main content
Glama

clip_video

Extract specific segments from videos using start and end times or duration. Supports multiple time formats, enables custom output paths, and integrates with FFmpeg for precise video trimming.

Instructions

智能视频剪辑函数

参数:
video_path : str - 源视频文件路径
start : int/float/str - 开始时间(支持秒数、MM:SS、HH:MM:SS格式,默认为视频开头,如果不传该参数,或者该参数为负数,从视频结尾往前剪辑)
end : int/float/str - 结束时间(同上,默认为视频结尾)
duration:  int/float/str - 裁剪时长,end和duration必须有一个
output_path: str - 裁剪后视频输出路径,如果不传入,会有一个默认的输出路径
time_out: int - 命令行执行超时时间,默认为300s
返回:
error - 错误码
str - ffmpeg执行过程中所有日志
str - 生成的剪辑文件路径
示例:
clip_video("input.mp4", "00:01:30", "02:30")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationNo
endNo
output_pathNo
startNo
time_outNo
video_pathYes

Implementation Reference

  • MCP tool handler and registration for 'clip_video'. This is the entry point decorated with @mcp.tool() that delegates to the core implementation.
    @mcp.tool()
    def clip_video(video_path, start=None, end=None,duration = None, output_path=None,time_out=300):
        """
        智能视频剪辑函数
        
        参数:
        video_path : str - 源视频文件路径
        start : int/float/str - 开始时间(支持秒数、MM:SS、HH:MM:SS格式,默认为视频开头,如果不传该参数,或者该参数为负数,从视频结尾往前剪辑)
        end : int/float/str - 结束时间(同上,默认为视频结尾)
        duration:  int/float/str - 裁剪时长,end和duration必须有一个
        output_path: str - 裁剪后视频输出路径,如果不传入,会有一个默认的输出路径
        time_out: int - 命令行执行超时时间,默认为300s
        返回:
        error - 错误码
        str - ffmpeg执行过程中所有日志
        str - 生成的剪辑文件路径
        示例:
        clip_video("input.mp4", "00:01:30", "02:30")
        """
        return cut_video.clip_video_ffmpeg(video_path,start=start,end=end,duration=duration, output_path=output_path,time_out=time_out)   
  • Core helper function implementing the video clipping logic using FFmpeg commands.
    def clip_video_ffmpeg(video_path, start = None, end = None, duration=None, output_path = None, time_out = 30):
        """
        智能视频剪辑函数
        
        参数:
        video_path : str - 源视频文件路径
        start : int/float/str - 开始时间(支持秒数、MM:SS、HH:MM:SS格式,默认为视频开头)
        end : int/float/str - 结束时间(同上,默认为视频结尾)
        duration:  int/float/str - 裁剪时长,end和duration必须有一个
        output_path: str - 裁剪后视频输出路径,如果不传入,会有一个默认的输出路径
        time_out: int - 命令行执行超时时间,默认为30s
        返回:
        error - 错误码
        str - ffmpeg执行过程中所有日志
        str - 生成的剪辑文件路径
        示例:
        clip_video("input.mp4", "00:01:30", "02:30")
        """
        try:
            base, ext = os.path.splitext(video_path)
            if (output_path == None):
                output_path = f"{base}_clip{ext}"
            cmd = f"-i {video_path} "
            if (start != None):
                start_sec = utils.convert_to_seconds(start)
                cmd = f"{cmd} -ss {start_sec}"
            if (end == None and duration is not None):
                end = start_sec + utils.convert_to_seconds(duration)
            if (end != None):
                end_sec = utils.convert_to_seconds(end) 
                cmd = f"{cmd} -to {end_sec}"
            cmd = f"{cmd} -y {output_path}"
            print(cmd)
            status_code, log = ffmpeg.run_ffmpeg(cmd, timeout=time_out)
            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. It discloses that the tool uses ffmpeg for execution and includes a timeout parameter, which adds some behavioral context. However, it lacks critical details: it doesn't specify whether the operation is read-only or destructive (clipping likely modifies or creates files), doesn't mention error handling beyond the error code, and omits information about permissions, rate limits, or side effects on the source video.

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

Conciseness3/5

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

The description is moderately concise but lacks front-loading of key information. It starts with a general title, then lists parameters in detail, which is useful but could be better organized. The inclusion of an example at the end is helpful, but some sentences are redundant (e.g., repeating time format info). Overall, it's adequately sized but not optimally structured for quick comprehension.

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 complexity (6 parameters, no annotations, no output schema), the description is partially complete. It covers parameter semantics well but falls short on behavioral aspects like safety, error details, and output explanation. The example helps, but without annotations or output schema, more context on the return values (e.g., what the error codes mean) would improve completeness.

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

Parameters4/5

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

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains each parameter's purpose, formats (e.g., time formats for start/end), defaults, and constraints (e.g., end and duration must have one). This compensates well for the schema's lack of descriptions, though it could be more structured and doesn't fully clarify all parameter interactions.

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 as '智能视频剪辑函数' (intelligent video clipping function) and specifies it clips video files. It distinguishes from siblings like concat_videos or overlay_video by focusing on temporal clipping rather than concatenation or overlaying. However, it doesn't explicitly contrast with extract_frames_from_video which also involves video extraction.

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

Usage Guidelines3/5

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

The description implies usage through the parameter explanations (e.g., 'end和duration必须有一个' - end and duration must have one), suggesting when to use certain parameters. However, it doesn't provide explicit guidance on when to choose this tool over alternatives like extract_frames_from_video or scale_video, nor does it mention prerequisites or exclusions.

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