Skip to main content
Glama

add_video_background_filling

Apply background fill effects to video segments by adding blur or solid color backgrounds to enhance visual composition in video editing workflows.

Instructions

为视频片段添加背景填充效果

Args: video_segment_id: 视频片段ID,通过add_video_segment获得 fill_type: 填充类型,"blur"表示模糊,"color"表示颜色 blur: 模糊程度,范围0.0-1.0,仅在fill_type为"blur"时有效,默认0.0625 剪映中的四档模糊数值分别为0.0625, 0.375, 0.75和1.0 color: 填充颜色,格式为'#RRGGBBAA',仅在fill_type为"color"时有效,默认"#00000000"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_segment_idYes
fill_typeYes
blurNo
colorNo#00000000

Implementation Reference

  • Main tool handler decorated with @mcp.tool(). Handles input validation, retrieves draft/track info, calls service, returns ToolResponse.
    @mcp.tool()
    def add_video_background_filling(
            video_segment_id: str,
            fill_type: str,
            blur: float = 0.0625,
            color: str = "#00000000"
    ) -> ToolResponse:
        """
        为视频片段添加背景填充效果
    
        Args:
            video_segment_id: 视频片段ID,通过add_video_segment获得
            fill_type: 填充类型,"blur"表示模糊,"color"表示颜色
            blur: 模糊程度,范围0.0-1.0,仅在fill_type为"blur"时有效,默认0.0625
                  剪映中的四档模糊数值分别为0.0625, 0.375, 0.75和1.0
            color: 填充颜色,格式为'#RRGGBBAA',仅在fill_type为"color"时有效,默认"#00000000"
        """
        # 参数验证
        if fill_type not in ["blur", "color"]:
            return ToolResponse(
                success=False,
                message=f"无效的填充类型 '{fill_type}',支持的类型: blur, color"
            )
    
        if not (0.0 <= blur <= 1.0):
            return ToolResponse(
                success=False,
                message=f"模糊程度必须在0.0-1.0范围内,当前值: {blur}"
            )
    
        # 通过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_background_filling_service(
            draft_id=draft_id,
            video_segment_id=video_segment_id,
            fill_type=fill_type,
            blur=blur,
            color=color,
            track_name=track_name
        )
    
        return result
  • Service layer function that instantiates VideoSegment and invokes its add_background_filling method to perform the actual background filling operation.
    def add_video_background_filling_service(
        draft_id: str,
        video_segment_id: str,
        fill_type: str,
        blur: float = 0.0625,
        color: str = "#00000000",
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        视频背景填充添加服务 - 为视频片段添加背景填充效果
    
        Args:
            draft_id: 草稿ID
            video_segment_id: 视频片段ID
            fill_type: 填充类型,"blur"表示模糊,"color"表示颜色
            blur: 模糊程度,0.0-1.0,仅在fill_type为"blur"时有效,默认0.0625
            color: 填充颜色,格式为'#RRGGBBAA',仅在fill_type为"color"时有效,默认"#00000000"
            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_background_filling(
                fill_type=fill_type,
                blur=blur,
                color=color
            )
    
            # 构建返回数据
            response_data = {
                "video_segment_id": video_segment_id,
                "draft_id": draft_id,
                "fill_type": fill_type,
                "blur": blur,
                "color": color,
                "add_background_filling": result_data
            }
    
            # 如果有轨道名称,添加到返回数据中
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"视频背景填充添加成功: {fill_type}",
                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)}"
            )
  • The server.py file imports and calls video_tools(mcp), which registers the add_video_background_filling tool along with other video tools via @mcp.tool() decorators.
    from jianyingdraft.tool.video_tool import video_tools
    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)
        audio_tools(mcp)
        utility_tools(mcp)

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