@ash_j1997/ffmpeg-mcp-server 0.4.2 → 0.5.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.
- package/README.ko.md +120 -0
- package/README.md +37 -23
- package/dist/index.js +283 -91
- package/dist/tools/audio.js +24 -9
- package/dist/tools/burn_subtitles.js +94 -0
- package/dist/tools/compress.js +8 -4
- package/dist/tools/concat.js +14 -3
- package/dist/tools/convert.js +78 -42
- package/dist/tools/keyframes.js +75 -0
- package/dist/tools/normalize.js +75 -0
- package/dist/tools/overlay.js +115 -0
- package/dist/tools/probe.js +6 -2
- package/dist/tools/reformat.js +14 -7
- package/dist/tools/silence.js +81 -20
- package/dist/tools/speed.js +24 -3
- package/dist/tools/split.js +15 -9
- package/dist/tools/subtitles.js +17 -4
- package/dist/tools/thumbnail.js +29 -13
- package/dist/tools/trim.js +47 -14
- package/dist/tools/waveform.js +9 -4
- package/dist/utils/exec.js +139 -8
- package/dist/utils/hwaccel.js +179 -26
- package/package.json +2 -1
package/dist/utils/hwaccel.js
CHANGED
|
@@ -1,45 +1,198 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
2
|
import { runCommand } from "./exec.js";
|
|
3
3
|
let cachedInfo = null;
|
|
4
|
+
async function canEncodeWith(encoder) {
|
|
5
|
+
try {
|
|
6
|
+
await runCommand("ffmpeg", [
|
|
7
|
+
"-v", "quiet",
|
|
8
|
+
"-f", "lavfi",
|
|
9
|
+
"-i", "color=c=black:s=16x16:d=0.04",
|
|
10
|
+
"-c:v", encoder,
|
|
11
|
+
"-f", "null",
|
|
12
|
+
"-"
|
|
13
|
+
]);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
4
20
|
/**
|
|
5
|
-
* Detects
|
|
21
|
+
* Detects available hardware-accelerated video encoders across macOS, Linux, and Windows.
|
|
22
|
+
* Supports Apple Silicon (VideoToolbox), NVIDIA (NVENC), Intel (QuickSync), AMD (AMF), and Linux (VAAPI).
|
|
6
23
|
*/
|
|
7
24
|
export async function detectHwAccel() {
|
|
8
25
|
if (cachedInfo) {
|
|
9
26
|
return cachedInfo;
|
|
10
27
|
}
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
isAvailable: false,
|
|
15
|
-
h264Encoder: "libx264",
|
|
16
|
-
hevcEncoder: "libx265",
|
|
17
|
-
hardwareType: "none",
|
|
18
|
-
};
|
|
19
|
-
return cachedInfo;
|
|
20
|
-
}
|
|
28
|
+
const detectedH264 = [];
|
|
29
|
+
const detectedHevc = [];
|
|
30
|
+
const detectedTypes = [];
|
|
21
31
|
try {
|
|
22
32
|
const res = await runCommand("ffmpeg", ["-encoders"]);
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const text = `${res.stdout}\n${res.stderr}`;
|
|
34
|
+
const check = (enc) => text.includes(` ${enc} `) || text.includes(` ${enc}\n`);
|
|
35
|
+
if (check("h264_videotoolbox")) {
|
|
36
|
+
detectedH264.push("h264_videotoolbox");
|
|
37
|
+
if (!detectedTypes.includes("videotoolbox"))
|
|
38
|
+
detectedTypes.push("videotoolbox");
|
|
39
|
+
}
|
|
40
|
+
if (check("hevc_videotoolbox")) {
|
|
41
|
+
detectedHevc.push("hevc_videotoolbox");
|
|
42
|
+
if (!detectedTypes.includes("videotoolbox"))
|
|
43
|
+
detectedTypes.push("videotoolbox");
|
|
44
|
+
}
|
|
45
|
+
if (check("h264_nvenc")) {
|
|
46
|
+
detectedH264.push("h264_nvenc");
|
|
47
|
+
if (!detectedTypes.includes("nvenc"))
|
|
48
|
+
detectedTypes.push("nvenc");
|
|
49
|
+
}
|
|
50
|
+
if (check("hevc_nvenc")) {
|
|
51
|
+
detectedHevc.push("hevc_nvenc");
|
|
52
|
+
if (!detectedTypes.includes("nvenc"))
|
|
53
|
+
detectedTypes.push("nvenc");
|
|
54
|
+
}
|
|
55
|
+
if (check("h264_qsv")) {
|
|
56
|
+
detectedH264.push("h264_qsv");
|
|
57
|
+
if (!detectedTypes.includes("qsv"))
|
|
58
|
+
detectedTypes.push("qsv");
|
|
59
|
+
}
|
|
60
|
+
if (check("hevc_qsv")) {
|
|
61
|
+
detectedHevc.push("hevc_qsv");
|
|
62
|
+
if (!detectedTypes.includes("qsv"))
|
|
63
|
+
detectedTypes.push("qsv");
|
|
64
|
+
}
|
|
65
|
+
if (check("h264_amf")) {
|
|
66
|
+
detectedH264.push("h264_amf");
|
|
67
|
+
if (!detectedTypes.includes("amf"))
|
|
68
|
+
detectedTypes.push("amf");
|
|
69
|
+
}
|
|
70
|
+
if (check("hevc_amf")) {
|
|
71
|
+
detectedHevc.push("hevc_amf");
|
|
72
|
+
if (!detectedTypes.includes("amf"))
|
|
73
|
+
detectedTypes.push("amf");
|
|
74
|
+
}
|
|
75
|
+
if (check("h264_vaapi")) {
|
|
76
|
+
detectedH264.push("h264_vaapi");
|
|
77
|
+
if (!detectedTypes.includes("vaapi"))
|
|
78
|
+
detectedTypes.push("vaapi");
|
|
79
|
+
}
|
|
80
|
+
if (check("hevc_vaapi")) {
|
|
81
|
+
detectedHevc.push("hevc_vaapi");
|
|
82
|
+
if (!detectedTypes.includes("vaapi"))
|
|
83
|
+
detectedTypes.push("vaapi");
|
|
33
84
|
}
|
|
34
85
|
}
|
|
35
86
|
catch {
|
|
36
|
-
//
|
|
87
|
+
// If probing fails, fall back to software
|
|
88
|
+
}
|
|
89
|
+
const isDarwin = os.platform() === "darwin";
|
|
90
|
+
let chosenType = "none";
|
|
91
|
+
let h264Encoder = "libx264";
|
|
92
|
+
let hevcEncoder = "libx265";
|
|
93
|
+
const candidates = [];
|
|
94
|
+
if (isDarwin && detectedTypes.includes("videotoolbox")) {
|
|
95
|
+
candidates.push({
|
|
96
|
+
type: "videotoolbox",
|
|
97
|
+
h264: "h264_videotoolbox",
|
|
98
|
+
hevc: detectedHevc.includes("hevc_videotoolbox") ? "hevc_videotoolbox" : "libx265",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (detectedTypes.includes("nvenc")) {
|
|
102
|
+
candidates.push({
|
|
103
|
+
type: "nvenc",
|
|
104
|
+
h264: "h264_nvenc",
|
|
105
|
+
hevc: detectedHevc.includes("hevc_nvenc") ? "hevc_nvenc" : "libx265",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (detectedTypes.includes("qsv")) {
|
|
109
|
+
candidates.push({
|
|
110
|
+
type: "qsv",
|
|
111
|
+
h264: "h264_qsv",
|
|
112
|
+
hevc: detectedHevc.includes("hevc_qsv") ? "hevc_qsv" : "libx265",
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (detectedTypes.includes("amf")) {
|
|
116
|
+
candidates.push({
|
|
117
|
+
type: "amf",
|
|
118
|
+
h264: "h264_amf",
|
|
119
|
+
hevc: detectedHevc.includes("hevc_amf") ? "hevc_amf" : "libx265",
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (detectedTypes.includes("vaapi")) {
|
|
123
|
+
candidates.push({
|
|
124
|
+
type: "vaapi",
|
|
125
|
+
h264: "h264_vaapi",
|
|
126
|
+
hevc: detectedHevc.includes("hevc_vaapi") ? "hevc_vaapi" : "libx265",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Verify that the driver/device actually initializes (e.g. NVENC compiled in ffmpeg on runner without GPU)
|
|
130
|
+
for (const candidate of candidates) {
|
|
131
|
+
if (await canEncodeWith(candidate.h264)) {
|
|
132
|
+
chosenType = candidate.type;
|
|
133
|
+
h264Encoder = candidate.h264;
|
|
134
|
+
hevcEncoder = candidate.hevc;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
37
137
|
}
|
|
38
138
|
cachedInfo = {
|
|
39
|
-
isAvailable:
|
|
40
|
-
h264Encoder
|
|
41
|
-
hevcEncoder
|
|
42
|
-
hardwareType:
|
|
139
|
+
isAvailable: chosenType !== "none",
|
|
140
|
+
h264Encoder,
|
|
141
|
+
hevcEncoder,
|
|
142
|
+
hardwareType: chosenType,
|
|
143
|
+
availableTypes: detectedTypes,
|
|
144
|
+
encoders: {
|
|
145
|
+
h264: detectedH264,
|
|
146
|
+
hevc: detectedHevc,
|
|
147
|
+
},
|
|
43
148
|
};
|
|
44
149
|
return cachedInfo;
|
|
45
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Helper to generate video encoder command line arguments for either hardware or software encoding.
|
|
153
|
+
*/
|
|
154
|
+
export function getVideoEncoderArgs(hwInfo, options) {
|
|
155
|
+
const useHw = options?.useHardware !== false && hwInfo.isAvailable;
|
|
156
|
+
if (useHw) {
|
|
157
|
+
return {
|
|
158
|
+
encoder: hwInfo.h264Encoder,
|
|
159
|
+
isHardware: true,
|
|
160
|
+
args: ["-c:v", hwInfo.h264Encoder, "-b:v", options?.bitrate || "4M"],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
encoder: "libx264",
|
|
165
|
+
isHardware: false,
|
|
166
|
+
args: [
|
|
167
|
+
"-c:v",
|
|
168
|
+
"libx264",
|
|
169
|
+
"-crf",
|
|
170
|
+
String(options?.crf ?? 22),
|
|
171
|
+
"-preset",
|
|
172
|
+
options?.preset || "medium",
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if a specific FFmpeg filter is supported by the local FFmpeg build.
|
|
178
|
+
*/
|
|
179
|
+
let cachedFilters = null;
|
|
180
|
+
export async function hasFilter(filterName) {
|
|
181
|
+
if (!cachedFilters) {
|
|
182
|
+
try {
|
|
183
|
+
const res = await runCommand("ffmpeg", ["-filters"]);
|
|
184
|
+
const lines = `${res.stdout}\n${res.stderr}`.split(/\r?\n/);
|
|
185
|
+
cachedFilters = new Set();
|
|
186
|
+
for (const line of lines) {
|
|
187
|
+
const match = line.match(/^\s*[TSC.]{2}\s+([a-zA-Z0-9_]+)/);
|
|
188
|
+
if (match) {
|
|
189
|
+
cachedFilters.add(match[1]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return cachedFilters.has(filterName);
|
|
198
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ash_j1997/ffmpeg-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "MCP server for FFmpeg and FFprobe media processing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "tsc",
|
|
15
|
+
"test": "npm run build && node test-tools.js",
|
|
15
16
|
"start": "node dist/index.js",
|
|
16
17
|
"prepare": "npm run build"
|
|
17
18
|
},
|