UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

150 lines (149 loc) 6.44 kB
import { ChatService } from '../services/chatService.js'; export async function demonstrateFFmpegWithChat() { console.log('🎬 Demonstrating FFmpeg Tool with Chat Service...\n'); const baseDir = process.cwd(); const chatService = new ChatService(baseDir); // Example conversations showing how the agent would use the FFmpeg tool const examples = [ { title: "Extract Audio from Video", userMessage: "I have a video file called 'presentation.mp4' and I want to extract just the audio as an MP3 file.", expectedToolCall: { tool_name: "ffmpeg", parameters: { operation: "extract_audio", input_file: "presentation.mp4", output_file: "presentation_audio.mp3", format: "mp3", quality: "high" } } }, { title: "Video Shot Detection and Splitting", userMessage: "I have a video called 'presentation.mp4' and I want to analyze it for scene changes, then split it into separate files for each segment.", expectedToolCall: [ { tool_name: "ffmpeg", parameters: { operation: "detect_shots", input_file: "presentation.mp4", output_file: "shot_timestamps.txt", scene_threshold: "0.3" } }, // Then the agent would read the timestamps and create trim operations { tool_name: "ffmpeg", parameters: { operation: "trim", input_file: "presentation.mp4", output_file: "segment_001.mp4", start_time: "0", end_time: "2.52" } } ] }, { title: "Create a Short Clip", userMessage: "I need to create a 30-second clip from my video 'long_video.mp4' starting at 2 minutes and 15 seconds.", expectedToolCall: { tool_name: "ffmpeg", parameters: { operation: "trim", input_file: "long_video.mp4", output_file: "short_clip.mp4", start_time: "00:02:15", duration: "00:00:30" } } }, { title: "Resize Video for Web", userMessage: "I want to resize my 4K video 'high_res.mp4' to 1080p for web streaming.", expectedToolCall: { tool_name: "ffmpeg", parameters: { operation: "resize", input_file: "high_res.mp4", output_file: "web_ready.mp4", resolution: "1920x1080", quality: "medium" } } }, { title: "Add Watermark", userMessage: "Add my logo 'company_logo.png' as a watermark to 'product_demo.mp4' in the top-right corner.", expectedToolCall: { tool_name: "ffmpeg", parameters: { operation: "overlay", input_file: "product_demo.mp4", output_file: "watermarked_demo.mp4", overlay_file: "company_logo.png", overlay_position: "top-right" } } }, { title: "Convert Audio Format", userMessage: "Convert my WAV file 'recording.wav' to MP3 with high quality.", expectedToolCall: { tool_name: "ffmpeg", parameters: { operation: "convert_format", input_file: "recording.wav", output_file: "recording.mp3", format: "mp3", quality: "320k" } } }, { title: "Create GIF Animation", userMessage: "Create a 5-second GIF from my video 'funny_moment.mp4' starting at 10 seconds.", expectedToolCall: { tool_name: "ffmpeg", parameters: { operation: "extract_gif", input_file: "funny_moment.mp4", output_file: "funny_moment.gif", start_time: "00:00:10", duration: "00:00:05" } } } ]; console.log('📋 Example FFmpeg Operations via Chat:\n'); examples.forEach((example, index) => { console.log(`${index + 1}. ${example.title}`); console.log(` User: "${example.userMessage}"`); console.log(` Expected Tool Call:`); console.log(` ${JSON.stringify(example.expectedToolCall, null, 6)}`); console.log(); }); console.log('🤖 The agent will automatically:'); console.log('• Parse the user\'s intent from natural language'); console.log('• Select the appropriate FFmpeg operation'); console.log('• Set smart defaults for quality and format'); console.log('• Validate file paths and parameters'); console.log('• Execute the FFmpeg command safely'); console.log('• Provide detailed feedback on success/failure'); console.log(); console.log('🎯 Advanced Operations:'); console.log('• Merge multiple videos: "Combine video1.mp4, video2.mp4, and video3.mp4 into one file"'); console.log('• Replace audio track: "Replace the audio in video.mp4 with new_audio.mp3"'); console.log('• Speed up/slow down: "Make my video play at double speed"'); console.log('• Add text overlay: "Add the title \'My Video\' to the top of my video"'); console.log('• Extract frames: "Extract one frame per second from my video as images"'); console.log('• Normalize audio: "Fix the audio levels in my recording"'); console.log(); console.log('✅ FFmpeg Chat Demo completed!'); console.log('💡 Try: contaigents chat "Extract audio from my video.mp4 file"'); } // Run demo if called directly if (import.meta.url === `file://${process.argv[1]}`) { demonstrateFFmpegWithChat().catch(console.error); }