// Frame Extraction for MCP Integration
// Run this to extract a frame and immediately process through puppet pipeline
const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');
const WebSocket = require('ws');
// Configuration
const VIDEO_PATH = 'C:\\puppet_production\\rendernet_media_vid_NS5ozVwpwE.mp4';
const FRAME_OUTPUT = 'C:\\puppet_production\\reference_frame.jpg';
const MCP_SERVER = 'ws://localhost:3000/mcp';
// Step 1: Extract frame using ffmpeg command line
function extractFrame(timestamp = 2) {
return new Promise((resolve, reject) => {
const cmd = `ffmpeg -i "${VIDEO_PATH}" -ss ${timestamp} -vframes 1 -q:v 2 "${FRAME_OUTPUT}" -y`;
console.log('πΉ Extracting frame from video...');
exec(cmd, (error, stdout, stderr) => {
if (error) {
// Try PowerShell as fallback
const psCmd = `powershell -Command "ffmpeg -i '${VIDEO_PATH}' -ss ${timestamp} -vframes 1 -q:v 2 '${FRAME_OUTPUT}' -y"`;
exec(psCmd, (error2) => {
if (error2) {
reject(`Failed to extract frame: ${error2.message}`);
} else {
console.log('β
Frame extracted successfully');
resolve(FRAME_OUTPUT);
}
});
} else {
console.log('β
Frame extracted successfully');
resolve(FRAME_OUTPUT);
}
});
});
}
// Step 2: Process through puppet pipeline
function processPuppetPipeline(imagePath) {
return new Promise((resolve, reject) => {
const ws = new WebSocket(MCP_SERVER);
ws.on('open', () => {
console.log('π Connected to MCP server');
console.log('π¨ Starting puppet production pipeline...');
const request = {
jsonrpc: '2.0',
id: 1,
method: 'hybrid_puppet_pipeline',
params: {
reference_image_path: imagePath,
character_name: 'RenderNet_Character',
proof_of_concept: true,
create_affogato_character: true,
scene_generations: [
{
scene_prompt: 'Character as action hero in explosive movie poster',
output_path: 'C:\\puppet_production\\outputs\\action_poster.png',
quality: 'Plus'
},
{
scene_prompt: 'Character in cyberpunk city with neon lights',
output_path: 'C:\\puppet_production\\outputs\\cyberpunk.png',
quality: 'Plus'
},
{
scene_prompt: 'Character in mystical fantasy setting with magic',
output_path: 'C:\\puppet_production\\outputs\\fantasy.png',
quality: 'Plus'
}
],
voice_videos: [
{
image_path: 'C:\\puppet_production\\outputs\\action_poster.png',
script: 'Welcome to my channel! Let\'s dive into today\'s adventure.',
voice_id: '21m00Tcm4TlvDq8ikWAM',
output_path: 'C:\\puppet_production\\outputs\\intro_video.mp4',
duration: 5
}
]
}
};
ws.send(JSON.stringify(request));
});
ws.on('message', (data) => {
const response = JSON.parse(data.toString());
console.log('π¦ Pipeline Response:', JSON.stringify(response, null, 2));
ws.close();
resolve(response);
});
ws.on('error', (err) => {
console.error('β WebSocket error:', err.message);
reject(err);
});
});
}
// Main execution
async function main() {
try {
// Create output directory
if (!fs.existsSync('C:\\puppet_production\\outputs')) {
fs.mkdirSync('C:\\puppet_production\\outputs', { recursive: true });
console.log('π Created output directory');
}
// Extract frame
const framePath = await extractFrame(2); // Extract at 2 seconds
console.log(`πΈ Frame saved to: ${framePath}`);
// Check if frame exists
if (fs.existsSync(framePath)) {
const stats = fs.statSync(framePath);
console.log(`π Frame size: ${(stats.size / 1024).toFixed(2)} KB`);
// Process through pipeline
console.log('\nπ Processing through puppet pipeline...');
const result = await processPuppetPipeline(framePath);
console.log('\n⨠Pipeline processing complete!');
console.log('π Check C:\\puppet_production\\outputs\\ for results');
} else {
console.error('β Frame file not found after extraction');
}
} catch (error) {
console.error('β Error:', error);
}
}
// Run if executed directly
if (require.main === module) {
main();
}
module.exports = { extractFrame, processPuppetPipeline };