@snahrup/notion-hero-image-mcp
Version:
AI-powered animated hero banner generator for Notion pages. Integrates DALL-E 3, Google Veo 3, Cloudinary CDN, and Notion API.
80 lines • 2.83 kB
JavaScript
import ffmpeg from 'fluent-ffmpeg';
import { join } from 'path';
import { tmpdir } from 'os';
import { execSync } from 'child_process';
const definition = {
name: 'mp4_to_gif',
description: 'Convert MP4 to optimized GIF under 10MB',
inputSchema: {
type: 'object',
properties: {
mp4_path: {
type: 'string',
description: 'Local path to MP4 file'
},
width: {
type: 'number',
description: 'Output width (default: 640)',
default: 640
},
fps: {
type: 'number',
description: 'Frames per second (default: 15)',
default: 15
}
},
required: ['mp4_path']
}
};
const handler = {
'tools/call': async (request) => {
if (request.params.name !== 'mp4_to_gif')
return null;
const { mp4_path, width = 640, fps = 15 } = request.params.arguments;
const gifPath = join(tmpdir(), `hero-${Date.now()}.gif`);
const paletteGen = join(tmpdir(), `palette-${Date.now()}.png`);
return new Promise((resolve, reject) => {
// Generate palette for better quality
ffmpeg(mp4_path)
.outputOptions([
'-vf',
`fps=${fps},scale=${width}:-1:flags=lanczos,palettegen`
])
.output(paletteGen)
.on('end', () => {
// Convert using palette
ffmpeg(mp4_path)
.input(paletteGen)
.outputOptions([
'-lavfi',
`fps=${fps},scale=${width}:-1:flags=lanczos[x];[x][1:v]paletteuse`
])
.output(gifPath)
.on('end', () => {
// Optimize with gifsicle
try {
execSync(`gifsicle -O3 --lossy=80 -o ${gifPath} ${gifPath}`);
resolve({
content: [{
type: 'text',
text: JSON.stringify({
gif_path: gifPath,
size_mb: require('fs').statSync(gifPath).size / 1024 / 1024
})
}]
});
}
catch (error) {
reject(error);
}
})
.on('error', reject)
.run();
})
.on('error', reject)
.run();
});
}
};
export default { definition, handler };
//# sourceMappingURL=mp4-to-gif.js.map