Skip to main content
Glama

FFmpeg Transcode

ffmpeg_transcode

Transcode or resize videos using safe preset options. Set aspect ratio, frame rate, quality (CRF), and dimensions.

Instructions

Transcode or resize a video using safe preset options.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYes
outputPathYes
aspectNokeep
fpsNo
crfNo
widthNo
heightNo
overwriteNo

Implementation Reference

  • The async handler function that executes the ffmpeg_transcode tool logic. It builds ffmpeg arguments with optional overwrite, input/output paths, fps scaling, aspect ratio filters (9:16, 16:9, 1:1), and codec settings (libx264, aac), then runs ffmpeg via runCommand.
      async ({ inputPath, outputPath, aspect, fps, crf, width, height, overwrite }) => {
        try {
          const input = safePath(inputPath);
          const output = safePath(outputPath);
          const args: string[] = [];
          if (overwrite) args.push('-y');
          args.push('-i', input);
          const filters: string[] = [];
          if (fps) filters.push(`fps=${fps}`);
          if (width && height) filters.push(`scale=${width}:${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2`);
          else if (aspect === '9:16') filters.push('scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920');
          else if (aspect === '16:9') filters.push('scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080');
          else if (aspect === '1:1') filters.push('scale=1080:1080:force_original_aspect_ratio=increase,crop=1080:1080');
          if (filters.length) args.push('-vf', filters.join(','));
          args.push('-c:v', 'libx264', '-preset', 'medium', '-crf', String(crf), '-c:a', 'aac', '-b:a', '192k', output);
          const result = await runCommand(config.ffmpegBin, args);
          if (result.code !== 0) return errorResult('ffmpeg failed', result.stderr);
          return textResult({ ok: true, outputPath, command: [config.ffmpegBin, ...args].join(' ') });
        } catch (err) {
          return errorResult('Failed to transcode media', String(err));
        }
      }
    );
  • Zod input schema for ffmpeg_transcode defining inputPath (string), outputPath (string), aspect (enum: keep, 9:16, 16:9, 1:1, default keep), fps (optional positive int ≤120), crf (int 12-35, default 20), width (optional positive int), height (optional positive int), and overwrite (boolean, default true).
    inputSchema: z.object({
      inputPath: z.string(),
      outputPath: z.string(),
      aspect: z.enum(['keep', '9:16', '16:9', '1:1']).default('keep'),
      fps: z.number().int().positive().max(120).optional(),
      crf: z.number().int().min(12).max(35).default(20),
      width: z.number().int().positive().optional(),
      height: z.number().int().positive().optional(),
      overwrite: z.boolean().default(true)
    })
  • Registration of the 'ffmpeg_transcode' tool via server.registerTool() inside the registerMediaTools function. The function is called from src/index.ts line 21.
    server.registerTool(
      'ffmpeg_transcode',
      {
        title: 'FFmpeg Transcode',
        description: 'Transcode or resize a video using safe preset options.',
        inputSchema: z.object({
          inputPath: z.string(),
          outputPath: z.string(),
          aspect: z.enum(['keep', '9:16', '16:9', '1:1']).default('keep'),
          fps: z.number().int().positive().max(120).optional(),
          crf: z.number().int().min(12).max(35).default(20),
          width: z.number().int().positive().optional(),
          height: z.number().int().positive().optional(),
          overwrite: z.boolean().default(true)
        })
      },
      async ({ inputPath, outputPath, aspect, fps, crf, width, height, overwrite }) => {
        try {
          const input = safePath(inputPath);
          const output = safePath(outputPath);
          const args: string[] = [];
          if (overwrite) args.push('-y');
          args.push('-i', input);
          const filters: string[] = [];
          if (fps) filters.push(`fps=${fps}`);
          if (width && height) filters.push(`scale=${width}:${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2`);
          else if (aspect === '9:16') filters.push('scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920');
          else if (aspect === '16:9') filters.push('scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080');
          else if (aspect === '1:1') filters.push('scale=1080:1080:force_original_aspect_ratio=increase,crop=1080:1080');
          if (filters.length) args.push('-vf', filters.join(','));
          args.push('-c:v', 'libx264', '-preset', 'medium', '-crf', String(crf), '-c:a', 'aac', '-b:a', '192k', output);
          const result = await runCommand(config.ffmpegBin, args);
          if (result.code !== 0) return errorResult('ffmpeg failed', result.stderr);
          return textResult({ ok: true, outputPath, command: [config.ffmpegBin, ...args].join(' ') });
        } catch (err) {
          return errorResult('Failed to transcode media', String(err));
        }
      }
    );
  • src/index.ts:20-21 (registration)
    Call site where registerMediaTools is invoked, which registers the ffmpeg_transcode tool on the MCP server.
    registerComfyTools(server);
    registerMediaTools(server);
  • The runCommand helper used by the ffmpeg_transcode handler to spawn the ffmpeg process with provided arguments.
    export function runCommand(command: string, args: string[], cwd?: string): Promise<{ code: number; stdout: string; stderr: string }> {
      return new Promise((resolve) => {
        const child = spawn(command, args, { cwd, shell: false });
        let stdout = '';
        let stderr = '';
        child.stdout.on('data', (d) => (stdout += d.toString()));
        child.stderr.on('data', (d) => (stderr += d.toString()));
        child.on('close', (code) => resolve({ code: code ?? -1, stdout, stderr }));
      });
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'safe preset options' without explaining what 'safe' entails or disclosing potential side effects like overwriting files, resource usage, or authentication needs.

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

Conciseness2/5

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

The description is extremely short (one sentence), which is too terse for a tool with 8 parameters. It sacrifices necessary detail for brevity, making it insufficient for an agent to use correctly.

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

Completeness1/5

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

Given the tool's complexity (8 parameters, no annotations, no output schema), the description is grossly incomplete. It fails to explain transcoding options, aspect ratio behavior, or the meaning of technical parameters like CRF and FPS.

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

Parameters1/5

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

With 0% schema description coverage, the description adds no meaning to the 8 parameters. The vague phrase 'safe preset options' does not clarify the purpose of inputPath, outputPath, aspect, fps, crf, width, height, or overwrite.

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

Purpose5/5

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

The description clearly states the action (transcode or resize) and the resource (video). It effectively distinguishes this tool from its siblings, which are focused on other tasks like After Effects scripts, ComfyUI workflows, or media analysis.

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. There is no mention of prerequisites, exclusions, or context for using FFmpeg transcoding over other media tools.

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/Eliveral/codex-mcp-comfy-ae-video-factory-mcp'

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