Skip to main content
Glama

clipVideo

Trim video clips with millisecond precision, set custom time segments, and adjust quality, video, and audio codecs for tailored output.

Instructions

剪辑视频片段,支持毫秒级精度的时间段裁剪

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
audioCodecNo音频编码格式
inputPathYes输入视频文件路径
outputPathYes输出视频文件路径
preserveMetadataNo是否保留元数据
qualityNo视频质量预设
timeSegmentYes
videoCodecNo视频编码格式

Implementation Reference

  • MCP tool handler for 'clipVideo' that delegates to VideoEngine.clipVideo and formats the response for MCP protocol.
    private async handleClipVideo(args: MCPToolParams['clipVideo']) { const result = await this.videoEngine.clipVideo(args); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • Core implementation of the video clipping functionality using FFmpeg, including file validation, time segment processing, encoding configuration, and error handling.
    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 : '未知错误' }; } }
  • Registration of the 'clipVideo' MCP tool, defining its name, description, and comprehensive input schema for parameters like input/output paths, time segment, and encoding options.
    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'] } },
  • TypeScript type definition for 'clipVideo' tool input parameters, referencing ClipOptions interface.
    clipVideo: ClipOptions;
  • TypeScript type definition for 'clipVideo' tool output result, referencing ProcessResult interface.
    clipVideo: ProcessResult;

Other Tools

Related Tools

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/pickstar-2002/video-clip-mcp'

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