Skip to main content
Glama

execute-ffmpeg

Process video files using custom FFmpeg commands on the MCP Media Processing Server. Specify input paths, output paths, and FFmpeg options to manage conversions, compressions, and edits efficiently.

Instructions

Execute any FFmpeg command with custom options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesAbsolute path to input video file
optionsYesArray of FFmpeg command options (e.g. ['-c:v', 'libx264', '-crf', '23'])
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

Implementation Reference

  • The main handler function for the 'execute-ffmpeg' tool. It resolves input and output paths, constructs an FFmpeg command using fluent-ffmpeg with provided options, executes it, and returns success or error message.
    async ({ inputPath, outputPath, outputFilename, options }) => { try { const absoluteInputPath = await getAbsolutePath(inputPath); const finalOutputPath = await getOutputPath(outputPath, outputFilename || 'output.mp4'); let command = ffmpeg(absoluteInputPath); // Add all options in pairs for (let i = 0; i < options.length; i += 2) { if (i + 1 < options.length) { command = command.addOption(options[i], options[i + 1]); } } command.save(finalOutputPath); await executeFFmpeg(command); return { content: [ { type: "text", text: `Video processing completed successfully. Output saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error processing video: ${errorMessage}`, }, ], }; } }
  • Zod schema defining the input parameters for the 'execute-ffmpeg' tool: inputPath (required), outputPath and outputFilename (optional), and options array.
    { inputPath: z.string().describe("Absolute path to input video 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)"), options: z.array(z.string()).describe("Array of FFmpeg command options (e.g. ['-c:v', 'libx264', '-crf', '23'])") },
  • src/index.ts:89-91 (registration)
    Registration of the 'execute-ffmpeg' tool using McpServer.tool() method, specifying the tool name and description.
    server.tool( "execute-ffmpeg", "Execute any FFmpeg command with custom options",
  • Helper function that wraps fluent-ffmpeg command execution in a Promise, resolving on 'end' event and rejecting on 'error'.
    const executeFFmpeg = (command: any): Promise<void> => { return new Promise((resolve, reject) => { command .on('end', () => resolve()) .on('error', (err: Error) => reject(err)) .run(); }); };
  • Helper function to convert relative input paths to absolute paths and verify file existence.
    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