Skip to main content
Glama

trim_video

Cut video clips to specific start and end times or durations using FFmpeg processing. Specify input/output paths and timing parameters to extract segments.

Instructions

Trim a video to a specific duration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to the input video file
outputPathYesPath for the output video file
startTimeNoStart time (format: HH:MM:SS.mmm or seconds)
durationNoDuration (format: HH:MM:SS.mmm or seconds)
endTimeNoEnd time (format: HH:MM:SS.mmm or seconds)

Implementation Reference

  • Main execution logic for trim_video tool: validates input/output paths, handles startTime, duration or endTime, builds FFmpeg command with stream copy (-c copy) for efficient trimming without re-encoding, executes via runFFmpegCommand, and returns completion message.
    case "trim_video": {
      const inputPath = validatePath(String(args?.inputPath), true);
      const outputPath = validatePath(String(args?.outputPath));
      const startTime = String(args?.startTime || "0");
      const duration = String(args?.duration || "");
      const endTime = String(args?.endTime || "");
      
      await ensureDirectoryExists(outputPath);
      
      let command = `-i "${inputPath}" -ss ${startTime}`;
      if (duration) {
        command += ` -t ${duration}`;
      } else if (endTime) {
        command += ` -to ${endTime}`;
      }
      command += ` -c copy "${outputPath}" -y`;
      
      const result = await runFFmpegCommand(command);
      
      return {
        content: [{
          type: "text",
          text: `Video trimming completed: ${inputPath} → ${outputPath}\n\n${result}`
        }]
      };
    }
  • Tool schema definition: name, description, and inputSchema specifying properties for inputPath (required), outputPath (required), and optional startTime, duration, endTime as strings.
    {
      name: "trim_video",
      description: "Trim a video to a specific duration",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input video file"
          },
          outputPath: {
            type: "string",
            description: "Path for the output video file"
          },
          startTime: {
            type: "string",
            description: "Start time (format: HH:MM:SS.mmm or seconds)"
          },
          duration: {
            type: "string",
            description: "Duration (format: HH:MM:SS.mmm or seconds)"
          },
          endTime: {
            type: "string",
            description: "End time (format: HH:MM:SS.mmm or seconds)"
          }
        },
        required: ["inputPath", "outputPath"]
      }
    },
  • src/index.ts:46-50 (registration)
    Registers trim_video tool schema by including it in the toolDefinitions array returned for ListToolsRequest.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: toolDefinitions
      };
    });
  • src/index.ts:56-68 (registration)
    Registers the general tool call handler that dispatches 'trim_video' calls to the specific handleToolCall implementation in handlers.ts.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        return await handleToolCall(request.params.name, request.params.arguments);
      } catch (error: any) {
        console.error("Tool execution error:", error.message);
        return {
          content: [{
            type: "text",
            text: `Error: ${error.message}`
          }]
        };
      }
    });

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/sworddut/mcp-ffmpeg-helper'

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