extract_audio
Extract audio from video files in MP3 format using FFmpeg MCP Server. Input video file path, specify output (optional), and generate audio efficiently for media processing needs.
Instructions
Extract audio as mp3 from a video
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_file | Yes | Path to input file | |
| output_file | No | Path to output file, output to the same directory if not specified |
Implementation Reference
- main.ts:86-120 (handler)The async handler function that uses ffmpeg to extract audio from a video file and save it as MP3. Handles output path, executes the command via 'x' from tinyexec, logs errors, and returns success/error messages.async (args) => { const output_file = args.output_file || getOutputFilePath(args.input_file, ".mp3") const result = await x(ffmpeg, [ `-i`, args.input_file, `-vn`, `-acodec`, `mp3`, `-y`, output_file, ]) if (result.exitCode !== 0) { return { content: [ { type: "text", text: `Error: ${result.stderr}`, }, ], isError: true, } } return { content: [ { type: "text", text: `Successfully extracted audio to: ${output_file}`, }, ], } },
- main.ts:82-121 (registration)Registration of the 'extract_audio' tool on the MCP server using server.tool(), providing name, description, input schema, and inline handler.server.tool( tools.extract_audio.name, tools.extract_audio.description, tools.extract_audio.input, async (args) => { const output_file = args.output_file || getOutputFilePath(args.input_file, ".mp3") const result = await x(ffmpeg, [ `-i`, args.input_file, `-vn`, `-acodec`, `mp3`, `-y`, output_file, ]) if (result.exitCode !== 0) { return { content: [ { type: "text", text: `Error: ${result.stderr}`, }, ], isError: true, } } return { content: [ { type: "text", text: `Successfully extracted audio to: ${output_file}`, }, ], } }, )
- tools.ts:30-42 (schema)Schema definition for the extract_audio tool, including Zod input schema for input_file (required string) and optional output_file.extract_audio: { name: "extract_audio", description: "Extract audio as mp3 from a video", input: { input_file: z.string().describe("Path to input file"), output_file: z .string() .describe( "Path to output file, output to the same directory if not specified", ) .optional(), }, },
- main.ts:9-13 (helper)Helper function to generate default output file path in the same directory as input, appending '_output' + extension.const getOutputFilePath = (input: string, ext: string) => { const input_dir = path.dirname(input) const input_filename = path.basename(input, path.extname(input)) return path.join(input_dir, `${input_filename}_output${ext}`) }