contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
153 lines (152 loc) • 6.88 kB
JavaScript
import { FFmpegTool } from '../services/tools/FFmpegTool.js';
export async function testFFmpegGuardrails() {
console.log('🛡️ Testing FFmpeg Tool Enhanced Guardrails...\n');
const baseDir = process.cwd();
const ffmpegTool = new FFmpegTool(baseDir);
console.log('🎯 Enhanced Agent Guidance:');
const guidance = ffmpegTool.getAgentGuidance();
console.log(guidance);
console.log();
console.log('🔍 Smart Aspect Ratio Detection Examples:\n');
const testScenarios = [
{
title: "Instagram Reel from Landscape Video",
description: "Converting 1920x1080 landscape to 1080x1920 vertical",
expectedWarning: "Source is landscape but target is 9:16 vertical - content will be cropped",
params: {
operation: 'social_media_convert',
input_file: 'landscape_video.mp4', // hypothetical 1920x1080
output_file: 'instagram_reel.mp4',
platform: 'instagram_reel'
}
},
{
title: "TikTok from Square Video",
description: "Converting 1080x1080 square to 1080x1920 vertical",
expectedWarning: "Source is square but target is 9:16 vertical - content will be cropped",
params: {
operation: 'social_media_convert',
input_file: 'square_video.mp4', // hypothetical 1080x1080
output_file: 'tiktok_video.mp4',
platform: 'tiktok'
}
},
{
title: "YouTube from Portrait Video",
description: "Converting 1080x1920 portrait to 1920x1080 landscape",
expectedWarning: "Source is portrait but target is 16:9 landscape - content will be cropped",
params: {
operation: 'social_media_convert',
input_file: 'portrait_video.mp4', // hypothetical 1080x1920
output_file: 'youtube_video.mp4',
platform: 'youtube'
}
},
{
title: "Resize with Aspect Ratio Mismatch",
description: "Resizing without maintaining aspect ratio",
expectedWarning: "May cause stretching - consider cropping first",
params: {
operation: 'resize',
input_file: 'source_video.mp4',
output_file: 'resized_video.mp4',
resolution: '1080x1920' // If source is landscape, this will stretch
}
}
];
testScenarios.forEach((scenario, index) => {
console.log(`${index + 1}. ${scenario.title}`);
console.log(` Description: ${scenario.description}`);
console.log(` Expected Warning: ${scenario.expectedWarning}`);
console.log(` Parameters: ${JSON.stringify(scenario.params, null, 6)}`);
console.log();
});
console.log('🚨 Common Issues the Tool Now Prevents:\n');
const preventedIssues = [
{
issue: "Squeezed Instagram Reels",
solution: "Detects landscape-to-vertical conversion and warns about cropping needs",
before: "Video gets stretched/squeezed to fit 9:16 format",
after: "Agent knows to crop center portion and scale properly"
},
{
issue: "Stretched YouTube Videos",
solution: "Warns when portrait content is forced into landscape format",
before: "Tall videos get horizontally stretched",
after: "Agent suggests letterboxing or proper cropping"
},
{
issue: "Poor Social Media Formatting",
solution: "Platform-specific aspect ratio validation and smart cropping",
before: "Generic resize operations ignore platform requirements",
after: "Tailored conversion for each social media platform"
},
{
issue: "Unnoticed Quality Loss",
solution: "Warns about significant aspect ratio changes before processing",
before: "Users only discover issues after processing",
after: "Proactive warnings help users make informed decisions"
}
];
preventedIssues.forEach((item, index) => {
console.log(`${index + 1}. ${item.issue}`);
console.log(` Solution: ${item.solution}`);
console.log(` Before: ${item.before}`);
console.log(` After: ${item.after}`);
console.log();
});
console.log('🎬 New Social Media Convert Operation:\n');
const socialMediaExamples = [
{
platform: 'Instagram Reel',
command: 'social_media_convert',
params: { platform: 'instagram_reel', crop_strategy: 'center' },
result: '9:16 aspect ratio (1080x1920) with center cropping'
},
{
platform: 'TikTok',
command: 'social_media_convert',
params: { platform: 'tiktok', crop_strategy: 'center' },
result: '9:16 aspect ratio (1080x1920) optimized for TikTok'
},
{
platform: 'YouTube Shorts',
command: 'social_media_convert',
params: { platform: 'youtube_shorts', crop_strategy: 'center' },
result: '9:16 aspect ratio (1080x1920) for YouTube Shorts'
},
{
platform: 'Instagram Post',
command: 'social_media_convert',
params: { platform: 'instagram_post', crop_strategy: 'center' },
result: '1:1 aspect ratio (1080x1080) square format'
},
{
platform: 'YouTube',
command: 'social_media_convert',
params: { platform: 'youtube', crop_strategy: 'center' },
result: '16:9 aspect ratio (1920x1080) landscape format'
}
];
socialMediaExamples.forEach((example, index) => {
console.log(`${index + 1}. ${example.platform}`);
console.log(` Operation: ${example.command}`);
console.log(` Parameters: ${JSON.stringify(example.params, null, 6)}`);
console.log(` Result: ${example.result}`);
console.log();
});
console.log('✅ Enhanced Guardrails Summary:');
console.log('• Proactive aspect ratio validation');
console.log('• Platform-specific conversion operations');
console.log('• Intelligent cropping strategies');
console.log('• Warning system for potential quality issues');
console.log('• Smart defaults based on source/target formats');
console.log('• Prevention of common "squeezed video" problems');
console.log();
console.log('🎯 The tool now prevents the Instagram Reel issue we encountered!');
console.log('✅ FFmpeg Guardrails test completed!');
}
// Run test if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
testFFmpegGuardrails().catch(console.error);
}