Skip to main content
Glama

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
NameRequiredDescriptionDefault
input_fileYesPath to input file
output_fileNoPath 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}`, }, ], } }, )
  • 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}`) }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZizoTheDev/ffmpeg-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server