Dynamic Media Processing: Compressing and Transcoding Streams with FFmpeg MCP
Perform video transformations, audio transcoding, and media stream optimizations semantically via an FFmpeg MCP Server.
Dynamic Media Processing: Compressing and Transcoding with FFmpeg
Processing media files typically requires memorizing complex, highly-specific CLI argument strings for FFmpeg. The FFmpeg MCP server abstracts this complexity by providing a semantic boundary. Your agent can execute advanced video transcoding, audio extraction, format inspection, and scaling simply through conversational requests.
Prerequisites
- ▸FFmpeg Installed: You must have
ffmpegandffprobeinstalled on the host machine running the MCP server, and they must be accessible in your system'sPATH. - ▸Node.js: The custom MCP bridge server requires Node.js to execute local child processes.
TypeScript Service Code
If you are writing a custom MCP server to wrap FFmpeg, you'll expose a tool that executes the binary using child processes. Here is a TypeScript blueprint:
import { exec } from 'child_process';
import util from 'util';
const execPromise = util.promisify(exec);
async function transcodeVideo(inputPath: string, outputPath: string, bitrate: string) {
// Always use the -y flag in automated environments to avoid stalling on 'overwrite?' prompts
const command = `ffmpeg -y -i "${inputPath}" -b:v ${bitrate} -vcodec libx264 "${outputPath}"`;
const { stdout, stderr } = await execPromise(command);
return { stdout, stderr };
}Action Prompt Patterns
With the MCP Server running, you can give instructions like:
- ▸Batch Audio Conversion: "Convert all WAV recordings inside the
/audiofolder to MP3 at 192kbps, and then list the new file sizes." - ▸Scale Video: "Create a 720p copy of my
screen-recording.movfile to make it optimized for upload to Slack." - ▸Extract Audio: "Rip the audio track from
interview.mp4and save it as a mono FLAC file."
Best Practices & Troubleshooting
- ▸Handling Large Files: Video transcoding can take minutes or hours. Because MCP is fundamentally request/response over JSON-RPC, a long-running process might timeout your AI client. It's recommended to build the FFmpeg MCP tool so it spawns the process asynchronously and returns a "job ID", allowing the agent to poll for status.
- ▸Missing Codecs: If you get a
Unknown encodererror instderr, your local installation of FFmpeg was likely compiled without support for that specific codec (e.g., missinglibx264). Reinstall FFmpeg with the necessary flags. - ▸Always Include
-y: When generating FFmpeg commands, ensure your agent includes the-yflag. Otherwise, FFmpeg will hang forever in the background waiting for aY/Nkeyboard input to overwrite existing files!
Using with OpenAI Codex
To use this MCP server with the OpenAI Codex CLI, you can add it to your configuration using the codex mcp add command:
codex mcp add --name ffmpeg-media --command "npx @modelcontextprotocol/server-ffmpeg-media"(Note: Depending on the server, you may need to append arguments or use --env flags for environment variables as described in the configuration section above)
Related Guides
How to Build a Custom MCP Server from Scratch
Learn how to create your own MCP server using the TypeScript or Python SDK. Expose custom tools and resources for AI agents to use.
Dev ToolsHow to Use the Puppeteer MCP Server for Web Scraping & Automation
Automate web browsers using the Puppeteer MCP server. Navigate websites, take screenshots, extract data, and automate web interactions through AI.
Dev ToolsHow to Use the Git MCP Server for Version Control Operations
Manage local Git repositories through AI agents. Clone repos, create branches, make commits, and view diffs using the Git MCP server.