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
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Absolute path to input video file | |
| options | Yes | Array of FFmpeg command options (e.g. ['-c:v', 'libx264', '-crf', '23']) | |
| outputFilename | No | Output filename (only used if outputPath is not provided) | |
| outputPath | No | Optional absolute path for output file. If not provided, file will be saved in Downloads folder |
Implementation Reference
- src/index.ts:98-134 (handler)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}`, }, ], }; } }
- src/index.ts:92-97 (schema)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",
- src/index.ts:79-86 (helper)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(); }); };
- src/index.ts:30-44 (helper)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}`); } }