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
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to the input video file | |
| outputPath | Yes | Path for the output video file | |
| startTime | No | Start time (format: HH:MM:SS.mmm or seconds) | |
| duration | No | Duration (format: HH:MM:SS.mmm or seconds) | |
| endTime | No | End time (format: HH:MM:SS.mmm or seconds) |
Implementation Reference
- src/tools/handlers.ts:80-105 (handler)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}` }] }; }
- src/tools/definitions.ts:98-127 (schema)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}` }] }; } });