@ash_j1997/ffmpeg-mcp-server 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ import fs from "node:fs/promises";
2
+ import { z } from "zod";
3
+ import { runFfmpeg, ensureFileExists, ensureOutputDir } from "../utils/exec.js";
4
+ export const generateWaveformSchema = z.object({
5
+ inputPath: z.string().describe("Path to the audio or video file."),
6
+ outputPath: z.string().describe("Destination path for the PNG image."),
7
+ width: z.number().int().positive().optional().default(1200).describe("Image width in pixels. Default: 1200."),
8
+ height: z.number().int().positive().optional().default(280).describe("Image height in pixels. Default: 280."),
9
+ color: z.string().optional().default("0x6366f1").describe("Waveform color in hex or name (such as '0x6366f1', 'white', or 'black'). Default: '0x6366f1'."),
10
+ scale: z.enum(["lin", "log", "sqrt"]).optional().default("lin").describe("Amplitude scale: 'lin', 'log', or 'sqrt'. Default: 'lin'."),
11
+ includeBase64: z.boolean().optional().describe("Return base64 image data in the response for vision models. Default: true."),
12
+ });
13
+ export async function generateWaveform(params) {
14
+ const { inputPath, outputPath, width = 1200, height = 280, color = "0x6366f1", scale = "lin", includeBase64 = true } = params;
15
+ const input = await ensureFileExists(inputPath);
16
+ const output = await ensureOutputDir(outputPath);
17
+ const filter = `aformat=channel_layouts=mono,showwavespic=s=${width}x${height}:colors=${color}:scale=${scale}`;
18
+ const args = [
19
+ "-i", input,
20
+ "-filter_complex", filter,
21
+ "-vframes", "1",
22
+ "-y", output
23
+ ];
24
+ const result = await runFfmpeg(args);
25
+ let base64;
26
+ if (includeBase64) {
27
+ try {
28
+ const buffer = await fs.readFile(output);
29
+ if (buffer.length < 4 * 1024 * 1024) {
30
+ base64 = buffer.toString("base64");
31
+ }
32
+ }
33
+ catch {
34
+ // Optional
35
+ }
36
+ }
37
+ return {
38
+ success: true,
39
+ outputPath: output,
40
+ resolution: `${width}x${height}`,
41
+ color,
42
+ commandExecuted: result.command,
43
+ durationSeconds: result.durationSeconds,
44
+ base64,
45
+ };
46
+ }
@@ -0,0 +1,73 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ /**
5
+ * Execute a command using spawn, capturing stdout and stderr.
6
+ */
7
+ export async function runCommand(command, args) {
8
+ return new Promise((resolve, reject) => {
9
+ const child = spawn(command, args);
10
+ let stdout = "";
11
+ let stderr = "";
12
+ child.stdout.on("data", (data) => {
13
+ stdout += data.toString();
14
+ });
15
+ child.stderr.on("data", (data) => {
16
+ stderr += data.toString();
17
+ });
18
+ child.on("error", (error) => {
19
+ reject(new Error(`Failed to launch ${command}: ${error.message}`));
20
+ });
21
+ child.on("close", (code) => {
22
+ const exitCode = code ?? 0;
23
+ if (exitCode !== 0) {
24
+ reject(new Error(`${command} exited with code ${exitCode}:\n${stderr || stdout}`));
25
+ }
26
+ else {
27
+ resolve({ stdout, stderr, exitCode });
28
+ }
29
+ });
30
+ });
31
+ }
32
+ /**
33
+ * Convenience wrapper for running ffmpeg commands with execution timing.
34
+ */
35
+ export async function runFfmpeg(args) {
36
+ const startTime = Date.now();
37
+ const res = await runCommand("ffmpeg", args);
38
+ const durationSeconds = Number(((Date.now() - startTime) / 1000).toFixed(2));
39
+ return {
40
+ command: `ffmpeg ${args.join(" ")}`,
41
+ stdout: res.stdout,
42
+ stderr: res.stderr,
43
+ durationSeconds,
44
+ };
45
+ }
46
+ /**
47
+ * Validates that an input file exists and is accessible.
48
+ */
49
+ export async function ensureFileExists(filePath) {
50
+ const resolved = path.resolve(filePath);
51
+ try {
52
+ const stat = await fs.stat(resolved);
53
+ if (!stat.isFile()) {
54
+ throw new Error(`Path is not a regular file: ${resolved}`);
55
+ }
56
+ return resolved;
57
+ }
58
+ catch (err) {
59
+ if (err.code === "ENOENT") {
60
+ throw new Error(`Input file not found: ${resolved}`);
61
+ }
62
+ throw err;
63
+ }
64
+ }
65
+ /**
66
+ * Ensures parent directory exists before writing output file.
67
+ */
68
+ export async function ensureOutputDir(outputPath) {
69
+ const resolved = path.resolve(outputPath);
70
+ const dir = path.dirname(resolved);
71
+ await fs.mkdir(dir, { recursive: true });
72
+ return resolved;
73
+ }
@@ -0,0 +1,45 @@
1
+ import os from "node:os";
2
+ import { runCommand } from "./exec.js";
3
+ let cachedInfo = null;
4
+ /**
5
+ * Detects if hardware-accelerated video encoders (Apple Silicon VideoToolbox) are available.
6
+ */
7
+ export async function detectHwAccel() {
8
+ if (cachedInfo) {
9
+ return cachedInfo;
10
+ }
11
+ const isDarwin = os.platform() === "darwin";
12
+ if (!isDarwin) {
13
+ cachedInfo = {
14
+ isAvailable: false,
15
+ h264Encoder: "libx264",
16
+ hevcEncoder: "libx265",
17
+ hardwareType: "none",
18
+ };
19
+ return cachedInfo;
20
+ }
21
+ try {
22
+ const res = await runCommand("ffmpeg", ["-encoders"]);
23
+ const hasVtH264 = res.stdout.includes("h264_videotoolbox") || res.stderr.includes("h264_videotoolbox");
24
+ const hasVtHevc = res.stdout.includes("hevc_videotoolbox") || res.stderr.includes("hevc_videotoolbox");
25
+ if (hasVtH264) {
26
+ cachedInfo = {
27
+ isAvailable: true,
28
+ h264Encoder: "h264_videotoolbox",
29
+ hevcEncoder: hasVtHevc ? "hevc_videotoolbox" : "libx265",
30
+ hardwareType: "videotoolbox",
31
+ };
32
+ return cachedInfo;
33
+ }
34
+ }
35
+ catch {
36
+ // Fallback if ffprobe/ffmpeg check fails
37
+ }
38
+ cachedInfo = {
39
+ isAvailable: false,
40
+ h264Encoder: "libx264",
41
+ hevcEncoder: "libx265",
42
+ hardwareType: "none",
43
+ };
44
+ return cachedInfo;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@ash_j1997/ffmpeg-mcp-server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.1",
4
+ "description": "MCP server for FFmpeg and FFprobe media processing",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "ffmpeg-mcp-server": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "start": "node dist/index.js",
16
+ "prepare": "npm run build"
17
+ },
18
+ "keywords": [
19
+ "mcp",
20
+ "ffmpeg",
21
+ "media",
22
+ "video",
23
+ "audio"
24
+ ],
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^1.32.1",
28
+ "zod": "^4.6.7"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^26.6.5",
32
+ "typescript": "^7.0.2"
33
+ },
34
+ "author": "Ashutos1997",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/Ashutos1997/ffmpeg-mcp-server.git"
38
+ },
39
+ "homepage": "https://github.com/Ashutos1997/ffmpeg-mcp-server#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/Ashutos1997/ffmpeg-mcp-server/issues"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }