Skip to main content
Glama

compress-video

Reduce video file size while maintaining quality by compressing videos using a customizable quality setting. Save output to a specified path or default folder with the MCP Media Processing Server.

Instructions

Compress video file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesAbsolute path to input video file
outputFilenameNoOutput filename (only used if outputPath is not provided)
outputPathNoOptional absolute path for output file. If not provided, file will be saved in Downloads folder
qualityNoCompression quality (1-51, lower is better quality but larger file)

Implementation Reference

  • The handler function that implements the core logic for compressing a video file using fluent-ffmpeg with libx264 codec and CRF quality control.
    async ({ inputPath, quality, outputPath, outputFilename }) => { try { const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const defaultFilename = outputFilename || `${inputFileName}_compressed.mp4`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = ffmpeg(absoluteInputPath) .videoCodec('libx264') .addOption('-crf', quality.toString()) .save(finalOutputPath); await executeFFmpeg(command); return { content: [ { type: "text", text: `Video successfully compressed and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error compressing video: ${errorMessage}`, }, ], }; } }
  • Zod schema defining the input parameters and validation for the compress-video tool.
    { inputPath: z.string().describe("Absolute path to input video file"), quality: z.number().min(1).max(51).default(23).describe("Compression quality (1-51, lower is better quality but larger file)"), outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"), outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)") },
  • src/index.ts:181-224 (registration)
    The server.tool call that registers the compress-video tool with the MCP server, including name, description, schema, and handler.
    server.tool( "compress-video", "Compress video file", { inputPath: z.string().describe("Absolute path to input video file"), quality: z.number().min(1).max(51).default(23).describe("Compression quality (1-51, lower is better quality but larger file)"), outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"), outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)") }, async ({ inputPath, quality, outputPath, outputFilename }) => { try { const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const defaultFilename = outputFilename || `${inputFileName}_compressed.mp4`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = ffmpeg(absoluteInputPath) .videoCodec('libx264') .addOption('-crf', quality.toString()) .save(finalOutputPath); await executeFFmpeg(command); return { content: [ { type: "text", text: `Video successfully compressed and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error compressing video: ${errorMessage}`, }, ], }; } } );
  • Utility function to execute FFmpeg commands as a Promise, used by compress-video and other video processing tools.
    const executeFFmpeg = (command: any): Promise<void> => { return new Promise((resolve, reject) => { command .on('end', () => resolve()) .on('error', (err: Error) => reject(err)) .run(); }); };
  • Helper to resolve relative input paths to absolute paths and verify file existence, used in compress-video.
    async function getAbsolutePath(inputPath: string): Promise<string> { if (isAbsolute(inputPath)) { return inputPath; } // FIXME: But it's not working, because the server is running in a different directory const absolutePath = resolve(process.cwd(), inputPath); try { await fs.access(absolutePath); return absolutePath; } catch (error) { throw new Error(`Input file not found: ${inputPath}`); } }

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/maoxiaoke/mcp-media-processor'

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