Skip to main content
Glama

splitVideo

Split video files by duration, size, or segment count for easier sharing, editing, or storage management. Supports customizable encoding and naming patterns.

Instructions

分割视频文件,支持按时长、大小或段数分割

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYes输入视频文件路径
outputDirYes输出目录路径
splitByYes分割方式
durationNo按时长分割(秒)
maxSizeNo按大小分割(MB)
segmentCountNo分割段数
qualityNo视频质量预设
videoCodecNo视频编码格式
audioCodecNo音频编码格式
namePatternNo文件命名模式,支持 {name}、{index}、{ext} 占位符

Implementation Reference

  • Core implementation of the splitVideo tool. Calculates split segments based on criteria (duration, size, segments), then clips each segment serially using the clipVideo method, validates outputs, and returns ProcessResult with paths and any errors.
    public async splitVideo(options: SplitOptions): Promise<ProcessResult> {
      const startTime = Date.now();
    
      try {
        // 验证输入文件
        await this.validateInputFile(options.inputPath);
        
        // 确保输出目录存在
        await fs.mkdir(options.outputDir, { recursive: true });
    
        const videoInfo = await this.getVideoInfo(options.inputPath);
        const segments = this.calculateSplitSegments(videoInfo, options);
        const outputPaths: string[] = [];
        const errors: string[] = [];
    
        // 串行处理分割任务,避免并发导致的FFmpeg异常
        for (let i = 0; i < segments.length; i++) {
          const segment = segments[i];
          const outputPath = path.join(
            options.outputDir,
            this.generateSplitFileName(options.inputPath, i, options.namePattern)
          );
    
          try {
            const clipOptions: ClipOptions = {
              inputPath: options.inputPath,
              outputPath,
              timeSegment: segment,
              quality: options.quality,
              videoCodec: options.videoCodec,
              audioCodec: options.audioCodec
            };
    
            const result = await this.clipVideo(clipOptions);
            if (result.success && result.outputPaths.length > 0) {
              outputPaths.push(outputPath);
              
              // 验证生成的文件是否有效
              try {
                const stats = await fs.stat(outputPath);
                if (stats.size === 0) {
                  errors.push(`分割文件 ${i + 1} 大小为0`);
                }
              } catch (statError) {
                errors.push(`无法验证分割文件 ${i + 1}: ${statError}`);
              }
            } else {
              errors.push(`分割任务 ${i + 1} 失败: ${result.error || '未知错误'}`);
            }
          } catch (segmentError) {
            errors.push(`分割任务 ${i + 1} 异常: ${segmentError instanceof Error ? segmentError.message : '未知错误'}`);
          }
    
          // 添加短暂延迟,避免FFmpeg进程冲突
          if (i < segments.length - 1) {
            await new Promise(resolve => setTimeout(resolve, 100));
          }
        }
    
        const success = outputPaths.length > 0;
        const errorMessage = errors.length > 0 ? `部分任务失败: ${errors.join('; ')}` : undefined;
    
        return {
          success,
          outputPaths,
          duration: Date.now() - startTime,
          error: success ? errorMessage : (errorMessage || '所有分割任务都失败了')
        };
    
      } catch (error) {
        return {
          success: false,
          outputPaths: [],
          duration: Date.now() - startTime,
          error: error instanceof Error ? error.message : '未知错误'
        };
      }
    }
  • MCP server handler for splitVideo tool call. Delegates execution to VideoEngine.splitVideo and formats response as MCP content.
    private async handleSplitVideo(args: MCPToolParams['splitVideo']) {
      const result = await this.videoEngine.splitVideo(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Registration of the splitVideo tool in MCP server, including name, description, and detailed inputSchema for validation.
    {
      name: 'splitVideo',
      description: '分割视频文件,支持按时长、大小或段数分割',
      inputSchema: {
        type: 'object',
        properties: {
          inputPath: {
            type: 'string',
            description: '输入视频文件路径'
          },
          outputDir: {
            type: 'string',
            description: '输出目录路径'
          },
          splitBy: {
            type: 'string',
            enum: ['duration', 'size', 'segments'],
            description: '分割方式'
          },
          duration: {
            type: 'number',
            description: '按时长分割(秒)'
          },
          maxSize: {
            type: 'number',
            description: '按大小分割(MB)'
          },
          segmentCount: {
            type: 'number',
            description: '分割段数'
          },
          quality: {
            type: 'string',
            enum: Object.values(QualityPreset),
            description: '视频质量预设'
          },
          videoCodec: {
            type: 'string',
            enum: Object.values(VideoCodec),
            description: '视频编码格式'
          },
          audioCodec: {
            type: 'string',
            enum: Object.values(AudioCodec),
            description: '音频编码格式'
          },
          namePattern: {
            type: 'string',
            description: '文件命名模式,支持 {name}、{index}、{ext} 占位符'
          }
        },
        required: ['inputPath', 'outputDir', 'splitBy']
      }
  • Type definition mapping splitVideo tool params to SplitOptions interface.
    splitVideo: SplitOptions;
  • Type definition for splitVideo tool result as ProcessResult.
    splitVideo: ProcessResult;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but discloses minimal behavioral traits. It states what the tool does (splitting with three methods) but doesn't cover critical aspects: whether it's destructive to the original file, permission requirements, rate limits, error handling, or output behavior. For a tool with 10 parameters and no output schema, this leaves significant gaps in understanding how the tool behaves beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that states the core functionality and supported methods. Every word earns its place with zero waste. It's appropriately sized for a tool with clear parameters documented elsewhere, though it could benefit from more context given the complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (10 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain what the tool returns, error conditions, file format requirements, or how the split methods interact with encoding parameters. For a video processing tool with multiple configuration options, this leaves too much undefined for reliable agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond implying the three split methods (duration, size, segments) which correspond to parameters splitBy, duration, maxSize, and segmentCount. This meets the baseline of 3 since the schema does the heavy lifting, but the description doesn't enhance understanding of parameter interactions or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '分割视频文件' (split video files) with specific methods '按时长、大小或段数分割' (by duration, size, or number of segments). It distinguishes from siblings like clipVideo (likely clips rather than splits) and mergeVideos, but doesn't explicitly contrast with batchProcess which might handle similar operations. The verb+resource+methods are specific, though sibling differentiation is implicit rather than explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file format compatibility), when not to use it, or how it differs from siblings like clipVideo or batchProcess. The agent must infer usage from the tool name and parameters alone, which is insufficient for informed selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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