@gehdoc/svg-to-video 0.27.7 → 0.28.0
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 +5 -2
- package/dist/shared/rendererTracking.js +4 -4
- package/dist/src/formats/generators/ApngFormatGenerator.js +1 -0
- package/dist/src/formats/generators/GifFormatGenerator.js +1 -0
- package/dist/src/formats/generators/MkvFormatGenerator.js +1 -0
- package/dist/src/formats/generators/MovFormatGenerator.js +1 -0
- package/dist/src/formats/generators/Mp4FormatGenerator.js +1 -0
- package/dist/src/formats/generators/WebmFormatGenerator.js +1 -0
- package/dist/src/index.js +49 -10
- package/dist/src/mcp.js +152 -73
- package/dist/src/utils/analytics.js +28 -4
- package/dist/src/utils/logger.js +4 -2
- package/package.json +7 -2
- package/skills/svg-to-video/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
[](https://github.com/GehDoc/svg-to-video/actions/workflows/ci.yml)
|
|
8
8
|
[](https://github.com/GehDoc/svg-to-video/releases)
|
|
9
9
|
[](https://www.npmjs.com/package/@gehdoc/svg-to-video)
|
|
10
|
+
[](https://glama.ai/mcp/servers/GehDoc/svg-to-video)
|
|
10
11
|
[](https://registry.modelcontextprotocol.io/v0/servers/io.github.GehDoc%2Fsvg-to-video/versions/latest)
|
|
11
12
|
[](https://gehdoc.github.io/svg-to-video/llms.txt)
|
|
12
13
|
[](https://hub.docker.com/r/gehdoc/svg-to-video)
|
|
@@ -84,8 +85,8 @@ npx @gehdoc/svg-to-video input.svg 60 ./out-dir -d 5 --format gif --transparent
|
|
|
84
85
|
# Node.js (animated PNG output)
|
|
85
86
|
npx @gehdoc/svg-to-video input.svg 60 ./out-dir -d 5 --format apng
|
|
86
87
|
|
|
87
|
-
# Docker (zero local dependencies; add :Z to -v for SELinux / Fedora)
|
|
88
|
-
docker run --rm -v $(pwd):/data:Z gehdoc/svg-to-video /data/input.svg 60 /data/out-dir -d 5 --format gif
|
|
88
|
+
# Docker (zero local dependencies; requires --shm-size=2gb for Chromium rendering; add :Z to -v for SELinux / Fedora)
|
|
89
|
+
docker run --rm --shm-size=2gb -e PUPPETEER_ARGS="--no-sandbox" -v $(pwd):/data:Z gehdoc/svg-to-video /data/input.svg 60 /data/out-dir -d 5 --format gif
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
See [docs/CLI.md](./docs/CLI.md) for full usage, arguments, and options. For local building and source execution, see [CONTRIBUTING.md](./CONTRIBUTING.md#commands--testing-strategy).
|
|
@@ -119,6 +120,8 @@ See **[docs/MCP.md](./docs/MCP.md)** for full setup instructions, tool schemas,
|
|
|
119
120
|
- 📦 **npm Package**: [`@gehdoc/svg-to-video`](https://www.npmjs.com/package/@gehdoc/svg-to-video)
|
|
120
121
|
- 🐳 **Docker Hub Image**: [`gehdoc/svg-to-video`](https://hub.docker.com/r/gehdoc/svg-to-video)
|
|
121
122
|
- 🌐 **Web Studio**: [`gehdoc.github.io/svg-to-video/`](https://gehdoc.github.io/svg-to-video/)
|
|
123
|
+
- 🤖 **MCP Registry**: [`io.github.GehDoc/svg-to-video`](https://registry.modelcontextprotocol.io/v0/servers/io.github.GehDoc%2Fsvg-to-video/versions/latest)
|
|
124
|
+
- ⭐ **Glama MCP**: [`glama.ai/mcp/servers/GehDoc/svg-to-video`](https://glama.ai/mcp/servers/GehDoc/svg-to-video)
|
|
122
125
|
|
|
123
126
|
---
|
|
124
127
|
|
|
@@ -21,7 +21,7 @@ export class ConversionTracker {
|
|
|
21
21
|
typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
22
22
|
}
|
|
23
23
|
start() {
|
|
24
|
-
this.trackFn('conversion-start', {
|
|
24
|
+
return this.trackFn('conversion-start', {
|
|
25
25
|
format: this.options.format,
|
|
26
26
|
isTransparent: this.options.isTransparent,
|
|
27
27
|
captureMethod: this.options.captureMethod,
|
|
@@ -31,7 +31,7 @@ export class ConversionTracker {
|
|
|
31
31
|
}
|
|
32
32
|
success(totalFrames) {
|
|
33
33
|
const processDurationSec = calculateElapsedSec(this.startTimeMs);
|
|
34
|
-
this.trackFn('conversion-success', {
|
|
34
|
+
return this.trackFn('conversion-success', {
|
|
35
35
|
format: this.options.format,
|
|
36
36
|
isTransparent: this.options.isTransparent,
|
|
37
37
|
captureMethod: this.options.captureMethod,
|
|
@@ -44,7 +44,7 @@ export class ConversionTracker {
|
|
|
44
44
|
failed(error) {
|
|
45
45
|
const processDurationSec = calculateElapsedSec(this.startTimeMs);
|
|
46
46
|
const errorMessage = typeof error === 'string' ? error : error.message;
|
|
47
|
-
this.trackFn('conversion-failed', {
|
|
47
|
+
return this.trackFn('conversion-failed', {
|
|
48
48
|
error: errorMessage,
|
|
49
49
|
format: this.options.format,
|
|
50
50
|
isTransparent: this.options.isTransparent,
|
|
@@ -54,7 +54,7 @@ export class ConversionTracker {
|
|
|
54
54
|
}
|
|
55
55
|
cancel() {
|
|
56
56
|
const processDurationSec = calculateElapsedSec(this.startTimeMs);
|
|
57
|
-
this.trackFn('conversion-cancel', {
|
|
57
|
+
return this.trackFn('conversion-cancel', {
|
|
58
58
|
format: this.options.format,
|
|
59
59
|
isTransparent: this.options.isTransparent,
|
|
60
60
|
captureMethod: this.options.captureMethod,
|
|
@@ -5,6 +5,7 @@ import { injectApngMetadata } from '#shared/apngMetadataInjector.js';
|
|
|
5
5
|
export class ApngFormatGenerator {
|
|
6
6
|
id = 'apng';
|
|
7
7
|
extensions = ['.apng', '.png'];
|
|
8
|
+
mimeType = 'image/png';
|
|
8
9
|
supportsAlpha = true;
|
|
9
10
|
buildFfmpegArgs(options) {
|
|
10
11
|
const { fps, hold, outDir, transparent, metadata, inputPattern, pkgVersion, outputFileName, } = options;
|
|
@@ -5,6 +5,7 @@ import { injectGifMetadata } from '#shared/gifMetadataInjector.js';
|
|
|
5
5
|
export class GifFormatGenerator {
|
|
6
6
|
id = 'gif';
|
|
7
7
|
extensions = ['.gif'];
|
|
8
|
+
mimeType = 'image/gif';
|
|
8
9
|
supportsAlpha = true;
|
|
9
10
|
buildFfmpegArgs(options) {
|
|
10
11
|
const { fps, hold, outDir, transparent, metadata, inputPattern, pkgVersion, outputFileName, } = options;
|
|
@@ -3,6 +3,7 @@ import { mergeMetadataComments } from '#shared/metadata.js';
|
|
|
3
3
|
export class MkvFormatGenerator {
|
|
4
4
|
id = 'mkv';
|
|
5
5
|
extensions = ['.mkv'];
|
|
6
|
+
mimeType = 'video/x-matroska';
|
|
6
7
|
supportsAlpha = true;
|
|
7
8
|
buildFfmpegArgs(options) {
|
|
8
9
|
const { fps, hold, outDir, transparent, metadata, inputPattern, pkgVersion, outputFileName, } = options;
|
|
@@ -3,6 +3,7 @@ import { mergeMetadataComments } from '#shared/metadata.js';
|
|
|
3
3
|
export class MovFormatGenerator {
|
|
4
4
|
id = 'mov';
|
|
5
5
|
extensions = ['.mov'];
|
|
6
|
+
mimeType = 'video/quicktime';
|
|
6
7
|
supportsAlpha = true;
|
|
7
8
|
buildFfmpegArgs(options) {
|
|
8
9
|
const { fps, hold, outDir, transparent, metadata, inputPattern, pkgVersion, outputFileName, } = options;
|
|
@@ -3,6 +3,7 @@ import { mergeMetadataComments } from '#shared/metadata.js';
|
|
|
3
3
|
export class Mp4FormatGenerator {
|
|
4
4
|
id = 'mp4';
|
|
5
5
|
extensions = ['.mp4'];
|
|
6
|
+
mimeType = 'video/mp4';
|
|
6
7
|
supportsAlpha = false;
|
|
7
8
|
buildFfmpegArgs(options) {
|
|
8
9
|
const { fps, hold, outDir, metadata, inputPattern, pkgVersion, outputFileName, } = options;
|
|
@@ -3,6 +3,7 @@ import { mergeMetadataComments } from '#shared/metadata.js';
|
|
|
3
3
|
export class WebmFormatGenerator {
|
|
4
4
|
id = 'webm';
|
|
5
5
|
extensions = ['.webm'];
|
|
6
|
+
mimeType = 'video/webm';
|
|
6
7
|
supportsAlpha = true;
|
|
7
8
|
buildFfmpegArgs(options) {
|
|
8
9
|
const { fps, hold, outDir, transparent, metadata, inputPattern, pkgVersion, outputFileName, } = options;
|
package/dist/src/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { formatRegistry } from './formats/registry.js';
|
|
|
11
11
|
import { pkg } from './utils/packageInfo.js';
|
|
12
12
|
import { JSDOM } from 'jsdom'; // For duration detection in Node environment
|
|
13
13
|
import { Logger } from './utils/logger.js';
|
|
14
|
-
import { trackEvent } from './utils/analytics.js';
|
|
14
|
+
import { trackEvent, flushAnalytics } from './utils/analytics.js';
|
|
15
15
|
import { ConversionTracker } from '#shared/rendererTracking.js';
|
|
16
16
|
const frameFileExtension = 'png';
|
|
17
17
|
async function main() {
|
|
@@ -55,7 +55,7 @@ Resources:
|
|
|
55
55
|
.action(async () => {
|
|
56
56
|
await import('./mcp.js');
|
|
57
57
|
});
|
|
58
|
-
program.
|
|
58
|
+
await program.parseAsync(process.argv);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* main function to run the conversion process
|
|
@@ -73,16 +73,19 @@ async function run(svgPath, fps, outDir, options) {
|
|
|
73
73
|
const outputFileName = `${inputBasename}${ext}`;
|
|
74
74
|
const outputFullPath = path.join(outDir, outputFileName);
|
|
75
75
|
if (fs.existsSync(outputFullPath) && !options.force) {
|
|
76
|
-
|
|
76
|
+
await logger.fatal(`Output file "${outputFullPath}" already exists. Use the --force (-f) flag to overwrite it.`);
|
|
77
|
+
return;
|
|
77
78
|
}
|
|
78
79
|
try {
|
|
79
80
|
validateOptions(options);
|
|
80
81
|
}
|
|
81
82
|
catch (error) {
|
|
82
|
-
|
|
83
|
+
await logger.fatal(error instanceof Error ? error.message : String(error));
|
|
84
|
+
return;
|
|
83
85
|
}
|
|
84
86
|
if (!fs.existsSync(svgPath)) {
|
|
85
|
-
|
|
87
|
+
await logger.fatal(`Input SVG file "${svgPath}" does not exist.`);
|
|
88
|
+
return;
|
|
86
89
|
}
|
|
87
90
|
const svg = fs.readFileSync(svgPath, 'utf-8');
|
|
88
91
|
const dom = new JSDOM('');
|
|
@@ -93,7 +96,8 @@ async function run(svgPath, fps, outDir, options) {
|
|
|
93
96
|
logger.info('🔍 Duration not provided, attempting to auto-detect...');
|
|
94
97
|
duration = detectedDuration;
|
|
95
98
|
if (duration === undefined) {
|
|
96
|
-
|
|
99
|
+
await logger.fatal('Could not detect duration. Please provide a duration using -d or --duration.');
|
|
100
|
+
return;
|
|
97
101
|
}
|
|
98
102
|
logger.info(`✅ Auto-detected duration: ${duration}s`);
|
|
99
103
|
}
|
|
@@ -126,6 +130,23 @@ async function run(svgPath, fps, outDir, options) {
|
|
|
126
130
|
videoDurationSec: duration,
|
|
127
131
|
}, trackEvent);
|
|
128
132
|
tracker.start();
|
|
133
|
+
let isCancelled = false;
|
|
134
|
+
const handleSignal = async (signal) => {
|
|
135
|
+
if (isCancelled)
|
|
136
|
+
return;
|
|
137
|
+
isCancelled = true;
|
|
138
|
+
logger.info(`\n⚠️ Received ${signal}. Cancelling conversion...`);
|
|
139
|
+
tracker.cancel();
|
|
140
|
+
if (!options.keepFrames && totalFrames > 0 && padWidth > 0) {
|
|
141
|
+
cleanupFrames(totalFrames, padWidth, outDir, logger);
|
|
142
|
+
}
|
|
143
|
+
await flushAnalytics();
|
|
144
|
+
process.exit(130);
|
|
145
|
+
};
|
|
146
|
+
const sigintListener = () => void handleSignal('SIGINT');
|
|
147
|
+
const sigtermListener = () => void handleSignal('SIGTERM');
|
|
148
|
+
process.once('SIGINT', sigintListener);
|
|
149
|
+
process.once('SIGTERM', sigtermListener);
|
|
129
150
|
try {
|
|
130
151
|
fs.mkdirSync(outDir, { recursive: true });
|
|
131
152
|
await createFrames(svg, parsedDim, fps, totalFrames, padWidth, outDir, puppeteerArgs, options.resolution, options.scale, options.transparent, options.bgColor, logger);
|
|
@@ -134,6 +155,7 @@ async function run(svgPath, fps, outDir, options) {
|
|
|
134
155
|
cleanupFrames(totalFrames, padWidth, outDir, logger);
|
|
135
156
|
}
|
|
136
157
|
tracker.success(totalFrames);
|
|
158
|
+
await flushAnalytics();
|
|
137
159
|
logger.done(outputFullPath, {
|
|
138
160
|
duration,
|
|
139
161
|
fps,
|
|
@@ -144,8 +166,23 @@ async function run(svgPath, fps, outDir, options) {
|
|
|
144
166
|
});
|
|
145
167
|
}
|
|
146
168
|
catch (error) {
|
|
147
|
-
|
|
148
|
-
|
|
169
|
+
if (!isCancelled) {
|
|
170
|
+
tracker.failed(error instanceof Error ? error : String(error));
|
|
171
|
+
if (!options.keepFrames) {
|
|
172
|
+
try {
|
|
173
|
+
cleanupFrames(totalFrames, padWidth, outDir, logger);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// ignore frame cleanup error during exception handling
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
await flushAnalytics();
|
|
180
|
+
await logger.fatal('Conversion failed', error instanceof Error ? error.message : String(error));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
process.removeListener('SIGINT', sigintListener);
|
|
185
|
+
process.removeListener('SIGTERM', sigtermListener);
|
|
149
186
|
}
|
|
150
187
|
}
|
|
151
188
|
/**
|
|
@@ -264,7 +301,8 @@ function convertToOutput(outputFileName, format, fps, padWidth, hold, outDir, tr
|
|
|
264
301
|
}
|
|
265
302
|
}
|
|
266
303
|
catch (error) {
|
|
267
|
-
|
|
304
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
305
|
+
throw new Error(`FFmpeg execution failed: ${details}`);
|
|
268
306
|
}
|
|
269
307
|
}
|
|
270
308
|
/**
|
|
@@ -289,7 +327,8 @@ function getFrameFilename(frame, padWidth) {
|
|
|
289
327
|
const prefix = ('' + frame).padStart(padWidth, '0');
|
|
290
328
|
return `${prefix}.${frameFileExtension}`;
|
|
291
329
|
}
|
|
292
|
-
main().catch((err) => {
|
|
330
|
+
main().catch(async (err) => {
|
|
331
|
+
await flushAnalytics();
|
|
293
332
|
console.error(err);
|
|
294
333
|
process.exit(1);
|
|
295
334
|
});
|
package/dist/src/mcp.js
CHANGED
|
@@ -9,6 +9,7 @@ import { execFileSync } from 'child_process';
|
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
10
|
import { JSDOM } from 'jsdom';
|
|
11
11
|
import { analyzeSvgAnimation, parseSvgDimensions, calculateAspectRatio, } from '#shared/analyzeSvgAnimation.js';
|
|
12
|
+
import { formatRegistry } from './formats/registry.js';
|
|
12
13
|
import { isLoggerJsonOutput } from './utils/logger.js';
|
|
13
14
|
import { trackEvent } from './utils/analytics.js';
|
|
14
15
|
import { pkg } from './utils/packageInfo.js';
|
|
@@ -17,6 +18,25 @@ const __dirname = path.dirname(__filename);
|
|
|
17
18
|
const cliJsPath = path.join(__dirname, 'index.js');
|
|
18
19
|
const cliTsPath = path.join(__dirname, 'index.ts');
|
|
19
20
|
const cliIndexPath = fs.existsSync(cliJsPath) ? cliJsPath : cliTsPath;
|
|
21
|
+
const isHosted = process.env.MCP_HOSTED === 'true' ||
|
|
22
|
+
process.env.MCP_HOSTED === '1' ||
|
|
23
|
+
process.argv.includes('--hosted');
|
|
24
|
+
function trackSecurityRejection() {
|
|
25
|
+
trackEvent('file-load', {
|
|
26
|
+
aspectRatio: 'unknown',
|
|
27
|
+
hasAnimation: false,
|
|
28
|
+
isDimensionsDetected: false,
|
|
29
|
+
rejectionReason: 'path-traversal-blocked',
|
|
30
|
+
isHosted: true,
|
|
31
|
+
}, 'mcp');
|
|
32
|
+
}
|
|
33
|
+
function getMimeType(formatStr) {
|
|
34
|
+
const generator = formatRegistry.get(formatStr);
|
|
35
|
+
if (generator?.mimeType) {
|
|
36
|
+
return generator.mimeType;
|
|
37
|
+
}
|
|
38
|
+
return 'application/octet-stream';
|
|
39
|
+
}
|
|
20
40
|
const server = new Server({
|
|
21
41
|
name: 'svg-to-video',
|
|
22
42
|
version: pkg.version,
|
|
@@ -30,21 +50,21 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
30
50
|
tools: [
|
|
31
51
|
{
|
|
32
52
|
name: 'render_svg_to_video',
|
|
33
|
-
description: 'Render an animated SVG (from
|
|
53
|
+
description: 'Render an animated SVG (from raw SVG code or file path) into a high-quality video (MP4, WebM, MKV, MOV) or animated image (aPNG, GIF) with in-band Base64 media delivery. Use this tool when you need to convert animated SVG graphics into video or image files. First use inspect_svg_animation to detect duration and dimensions if unknown. Specify svgContent for raw XML input or svgFilePath for local files. Pass transparent: true for WebM/GIF/aPNG transparency.',
|
|
34
54
|
inputSchema: {
|
|
35
55
|
type: 'object',
|
|
36
56
|
properties: {
|
|
37
57
|
svgFilePath: {
|
|
38
58
|
type: 'string',
|
|
39
|
-
description: 'Absolute or relative path to the input .svg file.',
|
|
59
|
+
description: 'Absolute or relative path to the input .svg file (forbidden in hosted sandboxed mode).',
|
|
40
60
|
},
|
|
41
61
|
svgContent: {
|
|
42
62
|
type: 'string',
|
|
43
|
-
description: 'Raw SVG string content to render (if svgFilePath is not provided).',
|
|
63
|
+
description: 'Raw SVG string content to render (required if svgFilePath is not provided).',
|
|
44
64
|
},
|
|
45
65
|
outDir: {
|
|
46
66
|
type: 'string',
|
|
47
|
-
description: 'Output directory
|
|
67
|
+
description: 'Output directory to preserve generated file locally. Omit to deliver purely in-band via ephemeral storage (forbidden in hosted sandboxed mode).',
|
|
48
68
|
},
|
|
49
69
|
fps: {
|
|
50
70
|
type: 'number',
|
|
@@ -90,13 +110,13 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
90
110
|
},
|
|
91
111
|
{
|
|
92
112
|
name: 'inspect_svg_animation',
|
|
93
|
-
description: 'Analyze an SVG file or raw SVG content to detect CSS keyframe animations, estimate duration, and extract viewBox dimensions.',
|
|
113
|
+
description: 'Analyze an SVG file or raw SVG content to detect CSS keyframe animations, estimate duration, and extract viewBox dimensions. Call this tool first before rendering to discover animation parameters and calculate optimal resolution.',
|
|
94
114
|
inputSchema: {
|
|
95
115
|
type: 'object',
|
|
96
116
|
properties: {
|
|
97
117
|
svgFilePath: {
|
|
98
118
|
type: 'string',
|
|
99
|
-
description: 'Path to the .svg file to inspect.',
|
|
119
|
+
description: 'Path to the .svg file to inspect (forbidden in hosted sandboxed mode).',
|
|
100
120
|
},
|
|
101
121
|
svgContent: {
|
|
102
122
|
type: 'string',
|
|
@@ -112,6 +132,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
112
132
|
const { name, arguments: args } = request.params;
|
|
113
133
|
if (name === 'inspect_svg_animation') {
|
|
114
134
|
const params = (args || {});
|
|
135
|
+
if (isHosted && params.svgFilePath) {
|
|
136
|
+
trackSecurityRejection();
|
|
137
|
+
return {
|
|
138
|
+
isError: true,
|
|
139
|
+
content: [
|
|
140
|
+
{
|
|
141
|
+
type: 'text',
|
|
142
|
+
text: 'Access to svgFilePath is forbidden when MCP_HOSTED security sandboxing is enabled. Please provide raw svgContent instead.',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
115
147
|
let svgContent = params.svgContent;
|
|
116
148
|
if (!svgContent && params.svgFilePath) {
|
|
117
149
|
if (!fs.existsSync(params.svgFilePath)) {
|
|
@@ -166,53 +198,82 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
166
198
|
}
|
|
167
199
|
if (name === 'render_svg_to_video') {
|
|
168
200
|
const params = (args || {});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!targetSvgPath && params.svgContent) {
|
|
172
|
-
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'svg2vid-mcp-'));
|
|
173
|
-
targetSvgPath = path.join(tempDir, 'input.svg');
|
|
174
|
-
fs.writeFileSync(targetSvgPath, params.svgContent, 'utf-8');
|
|
175
|
-
tempSvgFile = true;
|
|
176
|
-
}
|
|
177
|
-
if (!targetSvgPath || !fs.existsSync(targetSvgPath)) {
|
|
201
|
+
if (isHosted && (params.svgFilePath || params.outDir)) {
|
|
202
|
+
trackSecurityRejection();
|
|
178
203
|
return {
|
|
179
204
|
isError: true,
|
|
180
205
|
content: [
|
|
181
206
|
{
|
|
182
207
|
type: 'text',
|
|
183
|
-
text:
|
|
208
|
+
text: 'Providing svgFilePath or custom outDir is forbidden when MCP_HOSTED security sandboxing is enabled. Use raw svgContent and rely on in-band media delivery.',
|
|
184
209
|
},
|
|
185
210
|
],
|
|
186
211
|
};
|
|
187
212
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const command = cliIndexPath.endsWith('.ts') ? 'npx' : process.execPath;
|
|
191
|
-
const cliArgs = cliIndexPath.endsWith('.ts')
|
|
192
|
-
? ['tsx', cliIndexPath, targetSvgPath, fps, outDir, '--json', '--force']
|
|
193
|
-
: [cliIndexPath, targetSvgPath, fps, outDir, '--json', '--force'];
|
|
194
|
-
if (params.duration) {
|
|
195
|
-
cliArgs.push('-d', String(params.duration));
|
|
196
|
-
}
|
|
197
|
-
if (params.format) {
|
|
198
|
-
cliArgs.push('--format', params.format);
|
|
199
|
-
}
|
|
200
|
-
if (params.transparent) {
|
|
201
|
-
cliArgs.push('--transparent');
|
|
202
|
-
}
|
|
203
|
-
if (params.resolution) {
|
|
204
|
-
cliArgs.push('--resolution', params.resolution);
|
|
205
|
-
}
|
|
206
|
-
if (params.scale) {
|
|
207
|
-
cliArgs.push('--scale', String(params.scale));
|
|
208
|
-
}
|
|
209
|
-
if (params.bgColor) {
|
|
210
|
-
cliArgs.push('--bg-color', params.bgColor);
|
|
211
|
-
}
|
|
212
|
-
if (params.hold) {
|
|
213
|
-
cliArgs.push('-h', String(params.hold));
|
|
214
|
-
}
|
|
213
|
+
let tempWorkDir = null;
|
|
214
|
+
let targetSvgPath = params.svgFilePath;
|
|
215
215
|
try {
|
|
216
|
+
if (!targetSvgPath && params.svgContent) {
|
|
217
|
+
tempWorkDir = fs.mkdtempSync(path.join(os.tmpdir(), 'svg2vid-mcp-'));
|
|
218
|
+
targetSvgPath = path.join(tempWorkDir, 'input.svg');
|
|
219
|
+
fs.writeFileSync(targetSvgPath, params.svgContent, 'utf-8');
|
|
220
|
+
}
|
|
221
|
+
if (!targetSvgPath || !fs.existsSync(targetSvgPath)) {
|
|
222
|
+
return {
|
|
223
|
+
isError: true,
|
|
224
|
+
content: [
|
|
225
|
+
{
|
|
226
|
+
type: 'text',
|
|
227
|
+
text: `Input SVG not found or not provided: ${targetSvgPath || 'N/A'}`,
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const isExplicitOutDir = Boolean(params.outDir);
|
|
233
|
+
let renderOutDir;
|
|
234
|
+
if (isExplicitOutDir && params.outDir) {
|
|
235
|
+
renderOutDir = params.outDir;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (!tempWorkDir) {
|
|
239
|
+
tempWorkDir = fs.mkdtempSync(path.join(os.tmpdir(), 'svg2vid-mcp-'));
|
|
240
|
+
}
|
|
241
|
+
renderOutDir = tempWorkDir;
|
|
242
|
+
}
|
|
243
|
+
const fps = String(params.fps || 60);
|
|
244
|
+
const command = cliIndexPath.endsWith('.ts') ? 'npx' : process.execPath;
|
|
245
|
+
const cliArgs = cliIndexPath.endsWith('.ts')
|
|
246
|
+
? [
|
|
247
|
+
'tsx',
|
|
248
|
+
cliIndexPath,
|
|
249
|
+
targetSvgPath,
|
|
250
|
+
fps,
|
|
251
|
+
renderOutDir,
|
|
252
|
+
'--json',
|
|
253
|
+
'--force',
|
|
254
|
+
]
|
|
255
|
+
: [cliIndexPath, targetSvgPath, fps, renderOutDir, '--json', '--force'];
|
|
256
|
+
if (params.duration) {
|
|
257
|
+
cliArgs.push('-d', String(params.duration));
|
|
258
|
+
}
|
|
259
|
+
if (params.format) {
|
|
260
|
+
cliArgs.push('--format', params.format);
|
|
261
|
+
}
|
|
262
|
+
if (params.transparent) {
|
|
263
|
+
cliArgs.push('--transparent');
|
|
264
|
+
}
|
|
265
|
+
if (params.resolution) {
|
|
266
|
+
cliArgs.push('--resolution', params.resolution);
|
|
267
|
+
}
|
|
268
|
+
if (params.scale) {
|
|
269
|
+
cliArgs.push('--scale', String(params.scale));
|
|
270
|
+
}
|
|
271
|
+
if (params.bgColor) {
|
|
272
|
+
cliArgs.push('--bg-color', params.bgColor);
|
|
273
|
+
}
|
|
274
|
+
if (params.hold) {
|
|
275
|
+
cliArgs.push('-h', String(params.hold));
|
|
276
|
+
}
|
|
216
277
|
const rawOutput = execFileSync(command, cliArgs, {
|
|
217
278
|
encoding: 'utf-8',
|
|
218
279
|
cwd: process.cwd(),
|
|
@@ -221,36 +282,55 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
221
282
|
SVG_TO_VIDEO_INTERFACE: 'mcp',
|
|
222
283
|
},
|
|
223
284
|
});
|
|
224
|
-
if (tempSvgFile && targetSvgPath) {
|
|
225
|
-
try {
|
|
226
|
-
fs.rmSync(path.dirname(targetSvgPath), {
|
|
227
|
-
recursive: true,
|
|
228
|
-
force: true,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
catch {
|
|
232
|
-
// ignore cleanup error
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
285
|
const parsed = JSON.parse(rawOutput.trim());
|
|
236
286
|
if (isLoggerJsonOutput(parsed)) {
|
|
237
|
-
if (parsed.success === true) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
287
|
+
if (parsed.success === true && parsed.outputFile) {
|
|
288
|
+
const generatedFilePath = parsed.outputFile;
|
|
289
|
+
const mediaBuffer = fs.readFileSync(generatedFilePath);
|
|
290
|
+
const base64Data = mediaBuffer.toString('base64');
|
|
291
|
+
const resolvedFormat = parsed.format || params.format || 'webm';
|
|
292
|
+
const mimeType = getMimeType(resolvedFormat);
|
|
293
|
+
const responseTextObject = { ...parsed };
|
|
294
|
+
if (!isExplicitOutDir) {
|
|
295
|
+
delete responseTextObject['outputFile'];
|
|
296
|
+
}
|
|
297
|
+
const responseContentList = [
|
|
298
|
+
{
|
|
299
|
+
type: 'text',
|
|
300
|
+
text: JSON.stringify(responseTextObject, null, 2),
|
|
301
|
+
},
|
|
302
|
+
];
|
|
303
|
+
if (mimeType.startsWith('image/')) {
|
|
304
|
+
responseContentList.push({
|
|
305
|
+
type: 'image',
|
|
306
|
+
data: base64Data,
|
|
307
|
+
mimeType,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
responseContentList.push({
|
|
312
|
+
type: 'resource',
|
|
313
|
+
resource: {
|
|
314
|
+
uri: `urn:svg-to-video:media`,
|
|
315
|
+
mimeType,
|
|
316
|
+
blob: base64Data,
|
|
243
317
|
},
|
|
244
|
-
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
content: responseContentList,
|
|
245
322
|
};
|
|
246
323
|
}
|
|
247
324
|
else {
|
|
325
|
+
const errorMsg = 'error' in parsed && typeof parsed.error === 'string'
|
|
326
|
+
? parsed.error
|
|
327
|
+
: 'Conversion failed';
|
|
248
328
|
return {
|
|
249
329
|
isError: true,
|
|
250
330
|
content: [
|
|
251
331
|
{
|
|
252
332
|
type: 'text',
|
|
253
|
-
text:
|
|
333
|
+
text: errorMsg,
|
|
254
334
|
},
|
|
255
335
|
],
|
|
256
336
|
};
|
|
@@ -269,17 +349,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
269
349
|
}
|
|
270
350
|
}
|
|
271
351
|
catch (error) {
|
|
272
|
-
if (tempSvgFile && targetSvgPath) {
|
|
273
|
-
try {
|
|
274
|
-
fs.rmSync(path.dirname(targetSvgPath), {
|
|
275
|
-
recursive: true,
|
|
276
|
-
force: true,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
catch {
|
|
280
|
-
// ignore cleanup error
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
352
|
return {
|
|
284
353
|
isError: true,
|
|
285
354
|
content: [
|
|
@@ -290,6 +359,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
290
359
|
],
|
|
291
360
|
};
|
|
292
361
|
}
|
|
362
|
+
finally {
|
|
363
|
+
if (tempWorkDir) {
|
|
364
|
+
try {
|
|
365
|
+
fs.rmSync(tempWorkDir, { recursive: true, force: true });
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
// ignore cleanup error
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
293
372
|
}
|
|
294
373
|
return {
|
|
295
374
|
isError: true,
|
|
@@ -5,6 +5,7 @@ const umami = new Umami({
|
|
|
5
5
|
hostUrl: UMAMI_HOST_URL,
|
|
6
6
|
websiteId: UMAMI_WEBSITE_ID,
|
|
7
7
|
});
|
|
8
|
+
const activePromises = new Set();
|
|
8
9
|
export function isOptedOut() {
|
|
9
10
|
const dnt = process.env.DO_NOT_TRACK;
|
|
10
11
|
if (dnt) {
|
|
@@ -13,7 +14,10 @@ export function isOptedOut() {
|
|
|
13
14
|
return true;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
if (process.env.CI ||
|
|
17
|
+
if (process.env.CI ||
|
|
18
|
+
process.env.NODE_ENV === 'test' ||
|
|
19
|
+
process.env.VITEST ||
|
|
20
|
+
process.env.PLAYWRIGHT_TEST) {
|
|
17
21
|
return true;
|
|
18
22
|
}
|
|
19
23
|
return false;
|
|
@@ -26,11 +30,14 @@ export function resolveInterfaceType(defaultType = 'cli') {
|
|
|
26
30
|
}
|
|
27
31
|
export function trackEvent(eventName, properties, interfaceType) {
|
|
28
32
|
if (isOptedOut()) {
|
|
29
|
-
return;
|
|
33
|
+
return Promise.resolve(false);
|
|
30
34
|
}
|
|
31
|
-
sendEvent(eventName, properties, interfaceType).catch(() =>
|
|
32
|
-
|
|
35
|
+
const promise = sendEvent(eventName, properties, interfaceType).catch(() => false);
|
|
36
|
+
activePromises.add(promise);
|
|
37
|
+
promise.finally(() => {
|
|
38
|
+
activePromises.delete(promise);
|
|
33
39
|
});
|
|
40
|
+
return promise;
|
|
34
41
|
}
|
|
35
42
|
export async function sendEvent(eventName, properties, interfaceType) {
|
|
36
43
|
if (isOptedOut()) {
|
|
@@ -59,3 +66,20 @@ export async function sendEvent(eventName, properties, interfaceType) {
|
|
|
59
66
|
clearTimeout(timeoutId);
|
|
60
67
|
}
|
|
61
68
|
}
|
|
69
|
+
export async function flushAnalytics(timeoutMs = 3000) {
|
|
70
|
+
if (activePromises.size === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const active = Array.from(activePromises);
|
|
74
|
+
const flushPromise = Promise.allSettled(active);
|
|
75
|
+
if (timeoutMs <= 0) {
|
|
76
|
+
await flushPromise;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let timeoutId;
|
|
80
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
81
|
+
timeoutId = setTimeout(() => resolve(), timeoutMs);
|
|
82
|
+
});
|
|
83
|
+
await Promise.race([flushPromise.then(() => { }), timeoutPromise]);
|
|
84
|
+
clearTimeout(timeoutId);
|
|
85
|
+
}
|
package/dist/src/utils/logger.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { flushAnalytics } from './analytics.js';
|
|
1
2
|
export function isLoggerJsonOutput(obj) {
|
|
2
3
|
return (typeof obj === 'object' &&
|
|
3
4
|
obj !== null &&
|
|
@@ -64,9 +65,9 @@ export class Logger {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
|
-
* Output fatal error (as JSON or stderr string) and terminate execution
|
|
68
|
+
* Output fatal error (as JSON or stderr string), await pending analytics, and terminate execution
|
|
68
69
|
*/
|
|
69
|
-
fatal(msg, details) {
|
|
70
|
+
async fatal(msg, details) {
|
|
70
71
|
if (this.isJson) {
|
|
71
72
|
const payload = {
|
|
72
73
|
success: false,
|
|
@@ -80,6 +81,7 @@ export class Logger {
|
|
|
80
81
|
if (details)
|
|
81
82
|
console.error(details);
|
|
82
83
|
}
|
|
84
|
+
await flushAnalytics();
|
|
83
85
|
process.exit(1);
|
|
84
86
|
}
|
|
85
87
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gehdoc/svg-to-video",
|
|
3
3
|
"mcpName": "io.github.GehDoc/svg-to-video",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Professional animated SVG to Video (MP4/WebM/MKV/MOV) and Animated Image (aPNG/GIF) converter featuring frame-accurate rendering, CLI automation, Model Context Protocol (MCP) server integration, and a serverless Web Studio.",
|
|
7
7
|
"imports": {
|
|
@@ -57,12 +57,12 @@
|
|
|
57
57
|
"@umami/node": "^0.4.0",
|
|
58
58
|
"commander": "^15.0.0",
|
|
59
59
|
"jsdom": "^29.1.1",
|
|
60
|
+
"mcp-proxy": "^6.7.19",
|
|
60
61
|
"puppeteer": "^25.8.0",
|
|
61
62
|
"tsx": "^4.23.0"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@eslint/js": "^9.39.4",
|
|
65
|
-
"@types/commander": "^2.12.0",
|
|
66
66
|
"@types/ffprobe-static": "^2.0.3",
|
|
67
67
|
"@types/jsdom": "^28.0.3",
|
|
68
68
|
"@types/node": "^25.4.0",
|
|
@@ -88,7 +88,12 @@
|
|
|
88
88
|
"lint:fix": "eslint . --fix && npm run lint:fix -w web",
|
|
89
89
|
"format": "prettier --check .",
|
|
90
90
|
"format:fix": "prettier --write .",
|
|
91
|
+
"cli": "tsx src/index.ts",
|
|
91
92
|
"mcp": "tsx src/mcp.ts",
|
|
93
|
+
"mcp:sse": "mcp-proxy --port 8080 --host 0.0.0.0 -- tsx src/mcp.ts",
|
|
94
|
+
"start:cli": "node dist/src/index.js",
|
|
95
|
+
"start:mcp": "node dist/src/mcp.js",
|
|
96
|
+
"start:mcp:sse": "mcp-proxy --port 8080 --host 0.0.0.0 -- node dist/src/mcp.js",
|
|
92
97
|
"test:cli": "tsx --test tests/cli.spec.ts",
|
|
93
98
|
"test:mcp": "tsx --test tests/mcp.spec.ts",
|
|
94
99
|
"test:pack": "npm run build && tsx --test tests/pack.spec.ts",
|
|
@@ -35,5 +35,5 @@ When asked to generate a video or GIF from an SVG animation:
|
|
|
35
35
|
|
|
36
36
|
3. **Option C: Via Docker**:
|
|
37
37
|
```bash
|
|
38
|
-
docker run
|
|
38
|
+
docker run --rm -p 8080:8080 --shm-size=2gb -e PUPPETEER_ARGS="--no-sandbox" gehdoc/svg-to-video --mcp
|
|
39
39
|
```
|