Skip to main content
Glama

trim_audio

Cut audio files to specified start and end times or durations using FFmpeg. Input and output paths, time formats, and audio formats are customizable for precise trimming.

Instructions

Trim an audio file to a specific duration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationNoDuration (format: HH:MM:SS.mmm or seconds)
endTimeNoEnd time (format: HH:MM:SS.mmm or seconds)
formatNoAudio format for output (mp3, aac, etc.)
inputPathYesPath to the input audio file
outputPathYesPath for the output audio file
startTimeNoStart time (format: HH:MM:SS.mmm or seconds)

Implementation Reference

  • The handler function for the 'trim_audio' tool within the switch statement in handleToolCall. It validates inputs, builds an FFmpeg command to trim the audio file based on start time, duration or end time, optionally re-encodes in a specified format, and returns the result.
    case "trim_audio": { const inputPath = validatePath(String(args?.inputPath), true); const outputPath = validatePath(String(args?.outputPath)); const startTime = String(args?.startTime || "0"); const duration = String(args?.duration || ""); const endTime = String(args?.endTime || ""); const format = String(args?.format || ""); await ensureDirectoryExists(outputPath); // Build the FFmpeg command let command = `-i "${inputPath}" -ss ${startTime}`; // Add duration or end time if provided if (duration) { command += ` -t ${duration}`; } else if (endTime) { command += ` -to ${endTime}`; } // Add format if specified, otherwise use copy codec if (format) { command += ` -acodec ${format}`; } else { command += ` -acodec copy`; } command += ` "${outputPath}" -y`; const result = await runFFmpegCommand(command); return { content: [{ type: "text", text: `Audio trimming completed: ${inputPath} → ${outputPath}\n\n${result}` }] }; }
  • The tool definition object including name, description, and input schema for the 'trim_audio' tool, used for registration and validation.
    { name: "trim_audio", description: "Trim an audio file to a specific duration", inputSchema: { type: "object", properties: { inputPath: { type: "string", description: "Path to the input audio file" }, outputPath: { type: "string", description: "Path for the output audio file" }, startTime: { type: "string", description: "Start time (format: HH:MM:SS.mmm or seconds)" }, duration: { type: "string", description: "Duration (format: HH:MM:SS.mmm or seconds)" }, endTime: { type: "string", description: "End time (format: HH:MM:SS.mmm or seconds)" }, format: { type: "string", description: "Audio format for output (mp3, aac, etc.)" } }, required: ["inputPath", "outputPath"] } },
  • src/index.ts:46-50 (registration)
    Registration of all tools including 'trim_audio' via the ListToolsRequestSchema handler, which returns the toolDefinitions array containing the trim_audio schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolDefinitions }; });
  • src/index.ts:56-68 (registration)
    Registration of the tool call handler that routes calls to 'trim_audio' (and others) to the handleToolCall function based on the tool name.
    server.setRequestHandler(CallToolRequestSchema, async (request) => { try { return await handleToolCall(request.params.name, request.params.arguments); } catch (error: any) { console.error("Tool execution error:", error.message); return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } });

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/sworddut/mcp-ffmpeg-helper'

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