add_video_animation
Apply animation effects to video segments in JianYing (CapCut) projects. Add intro, outro, or group animations to enhance video content with customizable duration.
Instructions
为视频片段添加动画效果
Args: video_segment_id: 视频片段ID,通过add_video_segment获得 animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType" animation_name: 动画名称,如 "上下抖动", "向上滑动" 等,可以使用find_effects_by_type工具,资源类型选择IntroType、OutroType、GroupAnimationType,从而获取动画类型有哪些 duration: 动画持续时间,格式如 "1s"(可选)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| video_segment_id | Yes | ||
| animation_type | Yes | ||
| animation_name | Yes | ||
| duration | No |
Implementation Reference
- jianyingdraft/tool/video_tool.py:128-215 (handler)MCP tool handler decorated with @mcp.tool(). Performs input validation, animation existence check using JianYingResourceManager, retrieves draft and track info from index_manager, and delegates to add_video_animation_service.@mcp.tool() def add_video_animation( video_segment_id: str, animation_type: str, animation_name: str, duration: Optional[str] = '' ) -> ToolResponse: """ 为视频片段添加动画效果 Args: video_segment_id: 视频片段ID,通过add_video_segment获得 animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType" animation_name: 动画名称,如 "上下抖动", "向上滑动" 等,可以使用find_effects_by_type工具,资源类型选择IntroType、OutroType、GroupAnimationType,从而获取动画类型有哪些 duration: 动画持续时间,格式如 "1s"(可选) """ # 动画类型验证 valid_animation_types = ["IntroType", "OutroType", "GroupAnimationType"] if animation_type not in valid_animation_types: return ToolResponse( success=False, message=f"无效的动画类型 '{animation_type}',支持的类型: {', '.join(valid_animation_types)}" ) # 动画存在性验证 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 } ) # 通过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) print(duration, type(duration)) 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_animation_service( draft_id=draft_id, video_segment_id=video_segment_id, animation_type=animation_type, animation_name=animation_name, duration=duration, track_name=track_name ) return result
- Helper service function that creates a VideoSegment instance for the given draft and segment, calls video_segment.add_animation to apply the effect, and wraps the result in ToolResponse.def add_video_animation_service( draft_id: str, video_segment_id: str, animation_type: str, animation_name: str, duration: Optional[str] = None, track_name: Optional[str] = None ) -> ToolResponse: """ 视频动画添加服务 - 为视频片段添加动画效果 Args: draft_id: 草稿ID video_segment_id: 视频片段ID animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType" animation_name: 动画名称,如 "上下抖动", "向上滑动" 等 duration: 动画持续时间,格式如 "1s"(可选) 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_animation( animation_type=animation_type, animation_name=animation_name, duration=duration ) # 构建返回数据 response_data = { "video_segment_id": video_segment_id, "draft_id": draft_id, "animation_type": animation_type, "animation_name": animation_name, "duration": duration, "add_animation": result_data } # 如果有轨道名称,添加到返回数据中 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)}" )