Skip to main content
Glama

convert_video_to_gif

Convert video files to GIF animations with customizable FPS, dimensions, and duration settings for sharing and web use.

Instructions

Convert a video file to a GIF file in the same directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_pathYesPath to the video file to convert
fpsNoFrames per second for the GIF (default: 10)
widthNoWidth of the output GIF (maintains aspect ratio if height not specified)
heightNoHeight of the output GIF (maintains aspect ratio if width not specified)
start_timeNoStart time in seconds (default: 0)
durationNoDuration in seconds (default: entire video)

Implementation Reference

  • The main handler function that destructures parameters, checks file existence, generates output path, calls the conversion helper, and returns success message or throws MCP errors.
    private async convertVideoToGif(params: ConvertVideoToGifParams) {
      const {
        video_path,
        fps = 10,
        width,
        height,
        start_time,
        duration
      } = params;
    
      try {
        // Check if video file exists
        await fs.access(video_path);
        
        // Generate output path in the same directory
        const dir = dirname(video_path);
        const filename = basename(video_path, extname(video_path));
        const output_path = join(dir, `${filename}.gif`);
    
        console.error(`Converting video to GIF: ${video_path} -> ${output_path}`);
    
        await this.performConversion(video_path, output_path, {
          fps,
          width,
          height,
          start_time,
          duration
        });
    
        return {
          content: [
            {
              type: "text",
              text: `GIF created successfully at: ${output_path}`
            }
          ]
        };
      } catch (error) {
        if (error instanceof Error && error.message.includes('ENOENT')) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Video file not found: ${video_path}`
          );
        }
        
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to convert video to GIF: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Supporting utility that executes the ffmpeg command with palettegen for high-quality GIF conversion, including scaling, FPS, start time, duration, progress logging, and timeout handling.
    private performConversion(
      inputPath: string,
      outputPath: string,
      options: {
        fps: number;
        width?: number;
        height?: number;
        start_time?: number;
        duration?: number;
      }
    ): Promise<void> {
      return new Promise((resolve, reject) => {
        const timeout = setTimeout(() => {
          reject(new Error('Video conversion timed out after 120 seconds'));
        }, 120000);
    
        let command = ffmpeg(inputPath)
          .format('gif');
    
        // Apply start time if specified
        if (options.start_time !== undefined) {
          command = command.setStartTime(options.start_time);
        }
    
        // Apply duration if specified
        if (options.duration !== undefined) {
          command = command.setDuration(options.duration);
        }
    
        // Build the filter complex for high-quality GIF
        let filterString = `fps=${options.fps}`;
        
        // Add scaling if dimensions are specified
        if (options.width && options.height) {
          filterString += `,scale=${options.width}:${options.height}:flags=lanczos`;
        } else if (options.width) {
          filterString += `,scale=${options.width}:-1:flags=lanczos`;
        } else if (options.height) {
          filterString += `,scale=-1:${options.height}:flags=lanczos`;
        }
    
        // Add palette generation for better quality
        filterString += `,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`;
    
        command = command.complexFilter(filterString);
    
        command
          .on('start', (commandLine) => {
            console.error('Spawned ffmpeg with command: ' + commandLine);
          })
          .on('progress', (progress) => {
            console.error('Processing: ' + progress.percent + '% done');
          })
          .on('end', () => {
            clearTimeout(timeout);
            console.error('Conversion finished successfully');
            resolve();
          })
          .on('error', (err) => {
            clearTimeout(timeout);
            console.error('Conversion error:', err);
            reject(err);
          })
          .save(outputPath);
      });
    }
  • src/index.ts:49-84 (registration)
    Tool registration in the ListTools response, including name, description, and detailed JSON input schema.
    {
      name: "convert_video_to_gif",
      description: "Convert a video file to a GIF file in the same directory",
      inputSchema: {
        type: "object",
        properties: {
          video_path: {
            type: "string",
            description: "Path to the video file to convert"
          },
          fps: {
            type: "number",
            description: "Frames per second for the GIF (default: 10)",
            minimum: 1,
            maximum: 30
          },
          width: {
            type: "number",
            description: "Width of the output GIF (maintains aspect ratio if height not specified)"
          },
          height: {
            type: "number",
            description: "Height of the output GIF (maintains aspect ratio if width not specified)"
          },
          start_time: {
            type: "number",
            description: "Start time in seconds (default: 0)"
          },
          duration: {
            type: "number",
            description: "Duration in seconds (default: entire video)"
          }
        },
        required: ["video_path"]
      }
    }
  • TypeScript interface defining the input parameters matching the tool schema for type safety.
    interface ConvertVideoToGifParams {
      video_path: string;
      fps?: number;
      width?: number;
      height?: number;
      start_time?: number;
      duration?: number;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the output location but doesn't cover critical behaviors like whether the tool overwrites existing files, handles errors, requires specific permissions, or has performance constraints. For a file conversion tool with zero annotation coverage, this leaves significant gaps.

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, clear sentence that efficiently conveys the core functionality without unnecessary details. It's front-loaded with the main action and location, making it easy to understand at a glance.

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 complexity of a video-to-GIF conversion tool with no annotations and no output schema, the description is incomplete. It lacks information about output format, error handling, file size considerations, and behavioral traits, which are essential for proper tool invocation.

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?

The description doesn't add any parameter-specific information beyond what's already in the schema, which has 100% coverage. It mentions the output directory but doesn't explain parameter interactions or defaults. With high schema coverage, the baseline is 3, as the description doesn't compensate but also doesn't detract.

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: converting a video file to a GIF file. It specifies the verb 'convert' and the resources involved (video to GIF), and mentions the output location ('in the same directory'). However, it doesn't differentiate from siblings since none exist, so it can't achieve a perfect score of 5.

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, limitations, or scenarios where other tools might be more appropriate. With no sibling tools, this isn't a major issue, but it still lacks explicit usage context.

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/ananddtyagi/gif-creator-mcp'

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