mcp-extract-video-frames 0.1.0 → 0.1.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.md +9 -6
- package/package.json +39 -10
- package/src/ffmpeg.js +6 -2
- package/src/frames.js +1 -1
- package/src/index.js +1 -1
- package/src/ffmpeg-command.js +0 -31
- package/src/ffmpeg-provider.cjs +0 -18
package/README.md
CHANGED
|
@@ -4,12 +4,15 @@ Turn local videos into a small, configurable set of PNG screenshots for slide
|
|
|
4
4
|
references, illustrated notes, and visual review. Use the same extraction engine
|
|
5
5
|
from JavaScript, the command line, or an MCP client.
|
|
6
6
|
|
|
7
|
-
Requires Node.js 22.18
|
|
8
|
-
|
|
9
|
-
The
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
FFmpeg
|
|
7
|
+
Requires Node.js 22.18+. FFmpeg is supplied by the JavaScript dependency
|
|
8
|
+
`mcp-ffmpeg-runtime`, declared as `latest` and refreshed when preparing each new
|
|
9
|
+
release. The resolved dependency is saved with the release for reproducible retries.
|
|
10
|
+
At first media use in each process, that runtime checks its current FFmpeg build
|
|
11
|
+
and reuses or updates its binary cache. Subsequent extraction passes reuse the
|
|
12
|
+
resolved command. System FFmpeg and FFprobe are not required. Runtime settings
|
|
13
|
+
such as `FFMPEG_CACHE_DIR`, `FFMPEG_CHANNEL`, `FFMPEG_OFFLINE`, and
|
|
14
|
+
`FFMPEG_PREFER_LOCAL` are handled by mcp-ffmpeg-runtime. Offline or local preference
|
|
15
|
+
can opt out of downloading the current build. FFmpeg has its own licenses.
|
|
13
16
|
|
|
14
17
|
## CLI
|
|
15
18
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-extract-video-frames",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Extract adaptive video screenshots through a JavaScript library, CLI, or MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Łukasz Kucharski",
|
|
8
|
-
"repository": {
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/kucharskill/mcp-extract-video-frames.git"
|
|
11
|
+
},
|
|
9
12
|
"homepage": "https://github.com/kucharskill/mcp-extract-video-frames#readme",
|
|
10
|
-
"bugs": {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/kucharskill/mcp-extract-video-frames/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mcp",
|
|
18
|
+
"video",
|
|
19
|
+
"ffmpeg",
|
|
20
|
+
"screenshots",
|
|
21
|
+
"frames"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.18.0"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"mcp-extract-video-frames": "bin/cli.js"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./src/index.js",
|
|
31
|
+
"./options": "./src/options.js"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"bin/",
|
|
35
|
+
"src/",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
".env.example"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
17
43
|
"scripts": {
|
|
18
44
|
"check": "node scripts/check.mjs",
|
|
19
45
|
"test": "node --test tests/*.test.mjs",
|
|
@@ -25,7 +51,10 @@
|
|
|
25
51
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
26
52
|
"commander": "^15.1.0",
|
|
27
53
|
"dotenv": "^18.0.10",
|
|
54
|
+
"mcp-ffmpeg-runtime": "latest",
|
|
28
55
|
"zod": "^4.6.7"
|
|
29
56
|
},
|
|
30
|
-
"devDependencies": {
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@modelcontextprotocol/client": "^2.4.0"
|
|
59
|
+
}
|
|
31
60
|
}
|
package/src/ffmpeg.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
-
import {
|
|
3
|
+
import { resolveBinary } from "mcp-ffmpeg-runtime";
|
|
4
4
|
const execute = promisify(execFile);
|
|
5
|
+
let runtime;
|
|
5
6
|
export async function runFfmpeg(args, { signal } = {}) {
|
|
6
7
|
signal?.throwIfAborted();
|
|
7
|
-
|
|
8
|
+
runtime ??= resolveBinary("ffmpeg").catch(error => { runtime = undefined; throw error; });
|
|
9
|
+
const { command } = await runtime;
|
|
10
|
+
signal?.throwIfAborted();
|
|
11
|
+
return execute(command, ["-nostdin", "-hide_banner", "-nostats", ...args], {
|
|
8
12
|
windowsHide: true, shell: false, maxBuffer: 16 * 1024 * 1024, signal,
|
|
9
13
|
});
|
|
10
14
|
}
|
package/src/frames.js
CHANGED
|
@@ -61,7 +61,7 @@ export async function renderSelectedFrames(source, directory, timeline, options,
|
|
|
61
61
|
const indices = selected.map((sample) => `eq(n,${sample.index})`).join("+");
|
|
62
62
|
await writeFile(script, `[0:V:0]${settings.filter},select='${indices}',scale=-2:'min(ih,${options.frameMaxHeight})'[frames]`);
|
|
63
63
|
try {
|
|
64
|
-
await runFfmpeg(["-loglevel", "error", "-y", "-i", source, "
|
|
64
|
+
await runFfmpeg(["-loglevel", "error", "-y", "-i", source, "-/filter_complex", script, "-map", "[frames]", "-fps_mode", "vfr", "-enc_time_base", "1:1000", join(directory, "sample-%012d.png")], { signal: options.signal });
|
|
65
65
|
} finally { await rm(script, { force: true }); }
|
|
66
66
|
const files = (await readdir(directory)).filter((name) => /^sample-\d+\.png$/.test(name));
|
|
67
67
|
if (files.length !== selected.length) throw new Error("Selected frame count does not match extracted images.");
|
package/src/index.js
CHANGED
|
@@ -72,7 +72,7 @@ export async function extractFrames(file, { outputDir, timeline, signal, envFile
|
|
|
72
72
|
if(retained.originalSeconds > duration + 0.1)throw new Error("Timeline extends beyond the source video duration.");
|
|
73
73
|
const settings = frameFilter(retained,options);
|
|
74
74
|
await writeFile(script,`[0:V:0]${settings.filter},scale=96:96:force_original_aspect_ratio=decrease,format=gray,pad=96:96:(ow-iw)/2:(oh-ih)/2,showinfo=checksum=0[frames]`);
|
|
75
|
-
const scanned = await runFfmpeg(["-loglevel","info","-y","-i",input,"
|
|
75
|
+
const scanned = await runFfmpeg(["-loglevel","info","-y","-i",input,"-/filter_complex",script,"-map","[frames]","-fps_mode","passthrough","-threads","1","-f","rawvideo",scanFile],{signal});
|
|
76
76
|
await writeFile(log,scanned.stderr);
|
|
77
77
|
const result = await renderSelectedFrames(input,directory,retained,{...options,signal},scanFile,scanned.stderr,settings);
|
|
78
78
|
const manifest = result.count ? JSON.parse(await readFile(result.manifest,"utf8")) : {source:input,timestamps:"original",settings:options,frames:[]};
|
package/src/ffmpeg-command.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { accessSync, constants, existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { dirname, delimiter, join, resolve } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
|
|
7
|
-
let command;
|
|
8
|
-
export function getFfmpegCommand() {
|
|
9
|
-
if (command) return command;
|
|
10
|
-
const candidates = [process.env.npm_execpath,
|
|
11
|
-
join(dirname(process.execPath), "node_modules/npm/bin/npm-cli.js"),
|
|
12
|
-
resolve(dirname(process.execPath), "../lib/node_modules/npm/bin/npm-cli.js"),
|
|
13
|
-
...(process.env.PATH ?? "").split(delimiter).map(directory => join(directory, "node_modules/npm/bin/npm-cli.js")),
|
|
14
|
-
].filter(Boolean);
|
|
15
|
-
const npm = candidates.find(file => /npm-cli\.js$/i.test(file) && existsSync(file));
|
|
16
|
-
if (!npm) throw new Error("FFmpeg provider requires npm. Install Node.js with npm available.");
|
|
17
|
-
const cwd = join(tmpdir(), "extract-video-frames", "ffmpeg");
|
|
18
|
-
mkdirSync(cwd, { recursive: true });
|
|
19
|
-
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^npm_config_(package|call)$/i.test(key)));
|
|
20
|
-
try {
|
|
21
|
-
const output = execFileSync(process.execPath, [npm, "exec", "--yes", "--prefer-online", "--package=@seydx/node-av-ffmpeg@latest", "--", process.execPath, fileURLToPath(new URL("./ffmpeg-provider.cjs", import.meta.url))], {
|
|
22
|
-
cwd, env, stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true, encoding: "utf8", timeout: 180000, maxBuffer: 1024 * 1024,
|
|
23
|
-
});
|
|
24
|
-
const result = JSON.parse(output.trim());
|
|
25
|
-
accessSync(result.command, constants.X_OK);
|
|
26
|
-
command = result.command;
|
|
27
|
-
return command;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
throw new Error(`FFmpeg provider could not resolve @seydx/node-av-ffmpeg@latest through npm exec. Check npm connectivity and optional dependencies. ${error.message}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/ffmpeg-provider.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const { createRequire } = require("node:module");
|
|
2
|
-
const { delimiter, dirname, join } = require("node:path");
|
|
3
|
-
const { platform, arch } = process;
|
|
4
|
-
const musl = platform === "linux" && !process.report.getReport().header.glibcVersionRuntime;
|
|
5
|
-
const variant = `${platform}-${arch}${musl ? "-musl" : ""}`;
|
|
6
|
-
let provider;
|
|
7
|
-
for (const directory of process.env.PATH.split(delimiter)) {
|
|
8
|
-
if (!/[\\/]node_modules[\\/]\.bin$/.test(directory)) continue;
|
|
9
|
-
try {
|
|
10
|
-
const candidate = createRequire(join(dirname(directory), "@seydx/node-av-ffmpeg/package.json"));
|
|
11
|
-
candidate.resolve("./package.json");
|
|
12
|
-
provider = candidate;
|
|
13
|
-
break;
|
|
14
|
-
} catch { /* Continue through npm's injected dependency directories. */ }
|
|
15
|
-
}
|
|
16
|
-
if (!provider) throw new Error("npm exec did not provide the FFmpeg package.");
|
|
17
|
-
const command = provider.resolve(`@seydx/node-av-ffmpeg-${variant}/ffmpeg${platform === "win32" ? ".exe" : ""}`);
|
|
18
|
-
process.stdout.write(JSON.stringify({ command }));
|