convert_to_mp4
Convert .webm videos to MP4 format for compatibility with social media, sharing platforms, and embedding requirements.
Instructions
Convert a .webm video to MP4 (H.264). Widely compatible for social media, sharing, and embedding.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| webmPath | Yes | Path to the .webm file | |
| crf | No | Quality (18=high, 23=default, 28=small file) |
Implementation Reference
- src/converter.js:70-93 (handler)Handler implementation for converting WebM to MP4 using ffmpeg.
export async function convertToMp4(webmPath, options = {}) { await checkFfmpeg(); await access(webmPath); const mp4Path = options.outputPath || webmPath.replace(/\.webm$/, '.mp4'); const crf = options.crf || 23; // quality: lower = better, 18-28 is reasonable await run('ffmpeg', [ '-i', webmPath, '-c:v', 'libx264', '-preset', 'slow', '-crf', String(crf), '-pix_fmt', 'yuv420p', '-movflags', '+faststart', '-y', mp4Path ]); const mp4Stat = await stat(mp4Path); return { mp4Path, sizeBytes: mp4Stat.size, sizeMB: (mp4Stat.size / 1024 / 1024).toFixed(2) }; } - src/index.js:123-144 (registration)MCP tool registration for convert_to_mp4.
// Tool 5: Convert WebM to MP4 mcp.tool( 'convert_to_mp4', 'Convert a .webm video to MP4 (H.264). Widely compatible for social media, sharing, and embedding.', { webmPath: z.string().describe('Path to the .webm file'), crf: z.number().optional().default(23).describe('Quality (18=high, 23=default, 28=small file)') }, async ({ webmPath, crf }) => { try { const result = await convertToMp4(webmPath, { crf }); return { content: [{ type: 'text', text: `MP4 created!\n\nFile: ${result.mp4Path}\nSize: ${result.sizeMB} MB` }] }; } catch (err) { return { content: [{ type: 'text', text: `Error: ${err.message}` }], isError: true }; } } );