Skip to main content
Glama

add_text_animation

Apply entrance, exit, or looping animations to text segments in video editing projects. Choose from effects like typewriter, spring, glitch, fade-in, or fade-out to enhance visual storytelling.

Instructions

为文本片段添加动画效果

Args: text_segment_id: 文本片段ID,通过add_text_segment获得 animation_type: 动画类型,支持以下类型: - "TextIntro": 入场动画 - "TextOutro": 出场动画 - "TextLoopAnim": 循环动画 animation_name: 动画名称,如 "复古打字机", "弹簧", "色差故障", "淡入", "淡出" 等,可以使用find_effects_by_type工具,资源类型选择TextIntro、TextOutro、TextLoopAnim,从而获取动画类型有哪些 duration: 动画持续时间(可选),格式如 "1s", "500ms"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
text_segment_idYes
animation_typeYes
animation_nameYes
durationNo

Implementation Reference

  • The primary handler for the 'add_text_animation' MCP tool. It performs input validation (animation type and existence check using JianYingResourceManager), resolves draft/track info via index_manager, and delegates to the service layer for execution.
    @mcp.tool()
    def add_text_animation(
            text_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = None
    ) -> ToolResponse:
        """
        为文本片段添加动画效果
    
        Args:
            text_segment_id: 文本片段ID,通过add_text_segment获得
            animation_type: 动画类型,支持以下类型:
                - "TextIntro": 入场动画
                - "TextOutro": 出场动画
                - "TextLoopAnim": 循环动画
            animation_name: 动画名称,如 "复古打字机", "弹簧", "色差故障", "淡入", "淡出" 等,可以使用find_effects_by_type工具,资源类型选择TextIntro、TextOutro、TextLoopAnim,从而获取动画类型有哪些
            duration: 动画持续时间(可选),格式如 "1s", "500ms"
        """
        # 参数验证
        valid_types = ["TextIntro", "TextOutro", "TextLoopAnim"]
        if animation_type not in valid_types:
            return ToolResponse(
                success=False,
                message=f"无效的动画类型 '{animation_type}',支持的类型: {', '.join(valid_types)}"
            )
    
        # 动画存在性验证(文本动画使用 title 字段)
        from jianyingdraft.utils.effect_manager import JianYingResourceManager
        manager = JianYingResourceManager()
    
        effects = manager.find_by_type(
            effect_type=animation_type,
            keyword=animation_name,
            limit=1
        )
    
        # 检查是否找到完全匹配的动画
        exact_match = False
        if effects:
            for effect in effects:
                if effect.get('title') == animation_name:
                    exact_match = True
                    break
    
        if not effects or not exact_match:
            # 获取建议动画
            animation_suggestions = manager.find_by_type(animation_type, keyword=animation_name)
    
            all_suggestions = []
            for effect in animation_suggestions:
                if effect.get('title'):
                    all_suggestions.append(effect.get('title'))
    
            return ToolResponse(
                success=False,
                message=f"在 {animation_type} 中未找到动画 '{animation_name}',请确认动画名称是否正确,或使用建议动画",
                data={
                    "error_type": "animation_not_found",
                    "animation_type": animation_type,
                    "animation_name": animation_name,
                    "suggestions": all_suggestions
                }
            )
    
        # 通过text_segment_id获取相关信息
        draft_id = index_manager.get_draft_id_by_text_segment_id(text_segment_id)
        track_info = index_manager.get_track_info_by_text_segment_id(text_segment_id)
    
        if not draft_id:
            return ToolResponse(
                success=False,
                message=f"未找到文本片段ID对应的草稿: {text_segment_id}"
            )
    
        if not track_info:
            return ToolResponse(
                success=False,
                message=f"未找到文本片段ID对应的轨道信息: {text_segment_id}"
            )
    
        track_name = track_info.get("track_name")
    
        # 调用服务层处理业务逻辑
        result = add_text_animation_service(
            draft_id=draft_id,
            text_segment_id=text_segment_id,
            animation_type=animation_type,
            animation_name=animation_name,
            duration=duration,
            track_name=track_name
        )
    
        return result
  • Registration of the text tools module, including 'add_text_animation', by calling text_tools(mcp) on the FastMCP server instance.
    from jianyingdraft.tool.text_tool import text_tools
    from jianyingdraft.tool.audio_tool import audio_tools
    from jianyingdraft.tool.utility_tool import utility_tools
    
    
    def main():
        # 注册所有工具
        draft_tools(mcp)
        track_tools(mcp)
        video_tools(mcp)
        text_tools(mcp)
  • Helper service function called by the handler. Instantiates TextSegment and invokes add_animation method to apply the text animation effect, handling errors and formatting responses.
    def add_text_animation_service(
        draft_id: str,
        text_segment_id: str,
        animation_type: str,
        animation_name: str,
        duration: Optional[str] = None,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        文本动画添加服务 - 为文本片段添加动画效果
    
        Args:
            draft_id: 草稿ID
            text_segment_id: 文本片段ID
            animation_type: 动画类型,"TextIntro"、"TextOutro"、"TextLoopAnim"
            animation_name: 动画名称,如 "复古打字机"、"弹簧"、"色差故障" 等
            duration: 动画持续时间(可选),格式如 "1s"、"500ms"
            track_name: 轨道名称(可选)
    
        Returns:
            ToolResponse: 包含操作结果的响应对象
        """
        try:
            # 创建TextSegment实例,传入text_segment_id
            text_segment = TextSegment(draft_id, text_segment_id=text_segment_id, track_name=track_name)
    
            # 调用文本动画添加方法
            result_data = text_segment.add_animation(
                animation_type=animation_type,
                animation_name=animation_name,
                duration=duration
            )
    
            # 构建返回数据
            response_data = {
                "text_segment_id": text_segment_id,
                "draft_id": draft_id,
                "animation_type": animation_type,
                "animation_name": animation_name,
                "add_animation": result_data
            }
    
            # 添加可选参数到返回数据
            if duration:
                response_data["duration"] = duration
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"文本动画添加成功: {animation_type}.{animation_name}",
                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)}"
            )
  • Input schema defined by function parameters and comprehensive docstring describing args, types, and examples.
    def add_text_animation(
            text_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = None
    ) -> ToolResponse:
        """
        为文本片段添加动画效果
    
        Args:
            text_segment_id: 文本片段ID,通过add_text_segment获得
            animation_type: 动画类型,支持以下类型:
                - "TextIntro": 入场动画
                - "TextOutro": 出场动画
                - "TextLoopAnim": 循环动画
            animation_name: 动画名称,如 "复古打字机", "弹簧", "色差故障", "淡入", "淡出" 等,可以使用find_effects_by_type工具,资源类型选择TextIntro、TextOutro、TextLoopAnim,从而获取动画类型有哪些
            duration: 动画持续时间(可选),格式如 "1s", "500ms"
        """

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