Skip to main content
Glama

add_video_keyframe

Add animation keyframes to video segments in JianYing (CapCut) to control properties like position, rotation, scale, opacity, and effects at specific timestamps for dynamic video editing.

Instructions

为视频片段添加关键帧

Args: video_segment_id: 视频片段ID,通过add_video_segment获得 property_name: 属性名称,可选参数如下: position_x:右移为正, 此处的数值应该为剪映中显示的值 / 草稿宽度, 也即单位是半个画布宽 position_y:上移为正, 此处的数值应该为剪映中显示的值 / 草稿高度, 也即单位是半个画布高 rotation:顺时针旋转的角度 scale_x:单独控制X轴缩放比例(1.0为不缩放), 与uniform_scale互斥 scale_y:单独控制Y轴缩放比例(1.0为不缩放), 与uniform_scale互斥 uniform_scale:同时控制X轴及Y轴缩放比例(1.0为不缩放), 与scale_xscale_y互斥 alpha:不透明度, 1.0为完全不透明, 仅对VideoSegment有效 saturation:饱和度, 0.0为原始饱和度, 范围为-1.0到1.0 contrast:对比度, 0.0为原始对比度, 范围为-1.0到1.0 brightness:亮度, 0.0为原始亮度, 范围为-1.0到1.0 volume:音量, 1.0为原始音量 time_offset: 时间偏移量,格式如 "0.5s", "1s" 等 value: 属性值 Examples: # 在0.5秒时设置水平位置 add_video_keyframe("video_segment_id", "position_x", "0.5s", 0.2)

# 在1秒时设置旋转角度
add_video_keyframe("video_segment_id", "rotation", "1s", 45.0)

# 在2秒时设置透明度
add_video_keyframe("video_segment_id", "alpha", "2s", 0.5)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_segment_idYes
property_nameYes
time_offsetYes
valueYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • MCP tool handler for 'add_video_keyframe'. Handles input validation, retrieves draft and track information using index_manager, and delegates to the service function add_video_keyframe_service.
    @mcp.tool()
    def add_video_keyframe(
            video_segment_id: str,
            property_name: str,
            time_offset: str,
            value: float
    ) -> ToolResponse:
        """
        为视频片段添加关键帧
    
        Args:
            video_segment_id: 视频片段ID,通过add_video_segment获得
            property_name: 属性名称,可选参数如下:
                position_x:右移为正, 此处的数值应该为`剪映中显示的值` / `草稿宽度`, 也即单位是半个画布宽
                position_y:上移为正, 此处的数值应该为`剪映中显示的值` / `草稿高度`, 也即单位是半个画布高
                rotation:顺时针旋转的**角度**
                scale_x:单独控制X轴缩放比例(1.0为不缩放), 与`uniform_scale`互斥
                scale_y:单独控制Y轴缩放比例(1.0为不缩放), 与`uniform_scale`互斥
                uniform_scale:同时控制X轴及Y轴缩放比例(1.0为不缩放), 与`scale_x`和`scale_y`互斥
                alpha:不透明度, 1.0为完全不透明, 仅对`VideoSegment`有效
                saturation:饱和度, 0.0为原始饱和度, 范围为-1.0到1.0
                contrast:对比度, 0.0为原始对比度, 范围为-1.0到1.0
                brightness:亮度, 0.0为原始亮度, 范围为-1.0到1.0
                volume:音量, 1.0为原始音量
            time_offset: 时间偏移量,格式如 "0.5s", "1s" 等
            value: 属性值
        Examples:
            # 在0.5秒时设置水平位置
            add_video_keyframe("video_segment_id", "position_x", "0.5s", 0.2)
    
            # 在1秒时设置旋转角度
            add_video_keyframe("video_segment_id", "rotation", "1s", 45.0)
    
            # 在2秒时设置透明度
            add_video_keyframe("video_segment_id", "alpha", "2s", 0.5)
        """
        # 通过video_segment_id获取相关信息
        draft_id = index_manager.get_draft_id_by_video_segment_id(video_segment_id)
        track_info = index_manager.get_track_info_by_video_segment_id(video_segment_id)
    
        if not draft_id:
            return ToolResponse(
                success=False,
                message=f"未找到视频片段ID对应的草稿: {video_segment_id}"
            )
    
        if not track_info:
            return ToolResponse(
                success=False,
                message=f"未找到视频片段ID对应的轨道信息: {video_segment_id}"
            )
    
        track_name = track_info.get("track_name")
    
        # 调用服务层处理业务逻辑
        result = add_video_keyframe_service(
            draft_id=draft_id,
            video_segment_id=video_segment_id,
            property_name=property_name,
            time_offset=time_offset,
            value=value,
            track_name=track_name
        )
    
        return result
  • Helper service function that instantiates VideoSegment and calls its add_keyframe method to perform the actual keyframe addition logic, with error handling and response formatting.
    def add_video_keyframe_service(
        draft_id: str,
        video_segment_id: str,
        property_name: str,
        time_offset: str,
        value: float,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        视频关键帧添加服务 - 为视频片段添加关键帧
    
        Args:
            draft_id: 草稿ID
            video_segment_id: 视频片段ID
            property_name: 属性名称,如 "position_x", "rotation", "alpha" 等
            time_offset: 时间偏移量,如 "0.5s", "1s" 等
            value: 属性值
            track_name: 轨道名称(可选)
    
        Returns:
            ToolResponse: 包含操作结果的响应对象
        """
        try:
            # 创建VideoSegment实例,传入video_segment_id
            video_segment = VideoSegment(draft_id, video_segment_id=video_segment_id, track_name=track_name)
    
            # 调用视频关键帧添加方法
            result_data = video_segment.add_keyframe(
                property_name=property_name,
                time_offset=time_offset,
                value=value
            )
    
            # 构建返回数据
            response_data = {
                "video_segment_id": video_segment_id,
                "draft_id": draft_id,
                "property_name": property_name,
                "time_offset": time_offset,
                "value": value,
                "add_keyframe": result_data
            }
    
            # 如果有轨道名称,添加到返回数据中
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"视频关键帧添加成功: {property_name}={value} at {time_offset}",
                data=response_data
            )
    
        except ValueError as e:
            # 处理参数错误
            return ToolResponse(
                success=False,
                message=f"参数错误: {str(e)}"
            )
    
        except NameError as e:
            # 处理轨道不存在错误
            return ToolResponse(
                success=False,
                message=f"轨道错误: {str(e)}"
            )
    
        except Exception as e:
            # 处理其他未预期的错误
            return ToolResponse(
                success=False,
                message=f"视频关键帧添加失败: {str(e)}"
            )
  • Import statement registering the dependency on add_video_keyframe_service in the video tool module.
    from jianyingdraft.services.video_service import add_video_segment_service, add_video_animation_service, \
        add_video_transition_service, add_video_keyframe_service, add_video_filter_service, \
        add_video_background_filling_service, \
        add_video_mask_service, add_video_effect_service
Behavior3/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 explains what properties can be modified (position, rotation, scale, etc.) and provides examples, but doesn't mention whether this is a destructive operation, if it requires specific permissions, rate limits, or what happens on success/failure. The examples show usage but lack broader behavioral context like error conditions or side effects.

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 appropriately sized but not optimally structured. It starts with the purpose, then has an 'Args:' section with detailed parameter explanations, and ends with examples. However, the parameter explanations are quite lengthy (listing 11 property options with formulas), making it dense. The structure is functional but could be more front-loaded with critical usage information.

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 4 parameters with 0% schema coverage and no annotations, the description does an excellent job explaining parameters with detailed options and examples. Since there's an output schema (though not shown here), the description doesn't need to explain return values. The main gap is lack of behavioral context (permissions, errors, etc.), but for parameter semantics, it's quite complete.

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 schema description coverage is 0%, so the description must fully compensate. It provides extensive parameter documentation: video_segment_id is explained as coming from add_video_segment, property_name has 11 detailed options with formulas and constraints, time_offset specifies format, and value is shown through examples. This adds significant meaning beyond the bare schema, fully compensating for the lack of schema 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 as '为视频片段添加关键帧' (add keyframes to video segments), which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like add_video_animation or add_video_effect, which might also involve video manipulation. The purpose is clear but lacks sibling differentiation.

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 mentions that video_segment_id should be obtained from add_video_segment, which is a prerequisite but not usage context. There's no mention of when to use keyframes versus other video manipulation tools in the sibling list, nor any exclusions or preferred scenarios.

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/hey-jian-wei/jianying-mcp'

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