convert-video
Transform video files into various formats using the MCP Media Processing Server. Specify input path, desired format, and optional output details for efficient conversion.
Instructions
Convert video to different format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Absolute path to input video file | |
| outputFilename | No | Output filename (only used if outputPath is not provided) | |
| outputFormat | Yes | Desired output format (e.g., mp4, mkv, avi) | |
| outputPath | No | Optional absolute path for output file. If not provided, file will be saved in Downloads folder |
Implementation Reference
- src/index.ts:145-178 (handler)Handler function that converts video to specified format using fluent-ffmpeg. Resolves paths, sets output, executes FFmpeg, handles errors.}, async ({ inputPath, outputFormat, outputPath, outputFilename }) => { try { const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const defaultFilename = outputFilename || `${inputFileName}_converted.${outputFormat}`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = ffmpeg(absoluteInputPath) .toFormat(outputFormat) .save(finalOutputPath); await executeFFmpeg(command); return { content: [ { type: "text", text: `Video successfully converted and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error converting video: ${errorMessage}`, }, ], }; } }
- src/index.ts:140-144 (schema)Zod schema defining input parameters for the convert-video tool.{ inputPath: z.string().describe("Absolute path to input video file"), outputFormat: z.string().describe("Desired output format (e.g., mp4, mkv, avi)"), 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:137-179 (registration)Registration of the 'convert-video' tool using server.tool() with name, description, schema, and handler.server.tool( "convert-video", "Convert video to different format", { inputPath: z.string().describe("Absolute path to input video file"), outputFormat: z.string().describe("Desired output format (e.g., mp4, mkv, avi)"), 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, outputFormat, outputPath, outputFilename }) => { try { const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const defaultFilename = outputFilename || `${inputFileName}_converted.${outputFormat}`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = ffmpeg(absoluteInputPath) .toFormat(outputFormat) .save(finalOutputPath); await executeFFmpeg(command); return { content: [ { type: "text", text: `Video successfully converted and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error converting video: ${errorMessage}`, }, ], }; } } );
- src/index.ts:79-86 (helper)Helper function to execute FFmpeg commands asynchronously, used by convert-video.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 to resolve input path to absolute path and check existence, used in convert-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}`); } }