clipVideo
Trim video clips with millisecond precision by specifying exact start and end times. Extract specific segments from video files for editing or sharing.
Instructions
剪辑视频片段,支持毫秒级精度的时间段裁剪
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | 输入视频文件路径 | |
| outputPath | Yes | 输出视频文件路径 | |
| timeSegment | Yes | ||
| quality | No | 视频质量预设 | |
| videoCodec | No | 视频编码格式 | |
| audioCodec | No | 音频编码格式 | |
| preserveMetadata | No | 是否保留元数据 |
Implementation Reference
- src/core/video-engine.ts:76-129 (handler)Core implementation of the clipVideo tool using FFmpeg. Validates inputs, sets up FFmpeg command for seeking and duration clipping, applies encoding options, handles progress and errors, returns ProcessResult.public async clipVideo(options: ClipOptions): Promise<ProcessResult> { const startTime = Date.now(); const taskId = uuidv4(); try { // 验证输入文件 await this.validateInputFile(options.inputPath); // 确保输出目录存在 await this.ensureOutputDir(options.outputPath); // 验证时间段 const videoInfo = await this.getVideoInfo(options.inputPath); this.validateTimeSegment(options.timeSegment, videoInfo.duration); return new Promise((resolve, reject) => { const command = ffmpeg(options.inputPath) .seekInput(options.timeSegment.start / 1000) // 转换为秒 .duration((options.timeSegment.end - options.timeSegment.start) / 1000) .output(options.outputPath); // 设置编码参数 this.applyEncodingOptions(command, options); // 进度监听 command.on('progress', (progress: any) => { // 可以在这里添加进度回调 }); command.on('end', () => { resolve({ success: true, outputPaths: [options.outputPath], duration: Date.now() - startTime }); }); command.on('error', (err: any) => { reject(new Error(`视频剪辑失败: ${err.message}`)); }); this.processingTasks.set(taskId, command); command.run(); }); } catch (error) { return { success: false, outputPaths: [], duration: Date.now() - startTime, error: error instanceof Error ? error.message : '未知错误' }; } }
- src/mcp/server.ts:344-354 (handler)MCP server handler for clipVideo tool call. Delegates execution to VideoEngine.clipVideo and formats the response as MCP content.private async handleClipVideo(args: MCPToolParams['clipVideo']) { const result = await this.videoEngine.clipVideo(args); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/mcp/server.ts:109-159 (registration)Registration of the clipVideo tool in MCP server, including name, description, and detailed input schema definition.{ name: 'clipVideo', description: '剪辑视频片段,支持毫秒级精度的时间段裁剪', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: '输入视频文件路径' }, outputPath: { type: 'string', description: '输出视频文件路径' }, timeSegment: { type: 'object', properties: { start: { type: 'number', description: '开始时间(毫秒)' }, end: { type: 'number', description: '结束时间(毫秒)' } }, required: ['start', 'end'] }, quality: { type: 'string', enum: Object.values(QualityPreset), description: '视频质量预设' }, videoCodec: { type: 'string', enum: Object.values(VideoCodec), description: '视频编码格式' }, audioCodec: { type: 'string', enum: Object.values(AudioCodec), description: '音频编码格式' }, preserveMetadata: { type: 'boolean', description: '是否保留元数据' } }, required: ['inputPath', 'outputPath', 'timeSegment'] } },
- src/types/mcp.ts:15-52 (schema)Type definitions for clipVideo tool parameters (MCPToolParams['clipVideo']) and results (MCPToolResults['clipVideo']).export interface MCPToolParams { // 视频剪辑工具参数 clipVideo: ClipOptions; // 视频合并工具参数 mergeVideos: MergeOptions; // 视频分割工具参数 splitVideo: SplitOptions; // 获取视频信息工具参数 getVideoInfo: { filePath: string; }; // 批量处理工具参数 batchProcess: { tasks: Omit<BatchTask, 'id' | 'status' | 'createdAt'>[]; }; // 获取支持格式工具参数 getSupportedFormats: Record<string, never>; // 取消任务工具参数 cancelTask: { taskId: string; }; // 获取任务状态工具参数 getTaskStatus: { taskId: string; }; } // MCP工具返回值类型 export interface MCPToolResults { clipVideo: ProcessResult; mergeVideos: ProcessResult;
- src/core/batch-manager.ts:208-209 (helper)Usage of clipVideo in batch processing for 'clip' type tasks.result = await videoEngine.clipVideo(task.options as ClipOptions); break;