feat: 完善Topaz Video AI SDK - 支持所有AI引擎和输出设置

主要改进:
-  完整支持所有AI引擎标志 (Artemis, Gaia, Theia, Proteus, Iris)
-  实现引擎特定的参数优化和FFmpeg命令生成
-  完善OutputSettings所有参数的处理 (active, custom_resolution_priority, lock_aspect_ratio等)
-  新增专用预设模板 (animation_enhance, natural_scene_enhance, detail_recovery等)
-  增强TemplateBuilder功能 (ai_engine, focus_fix_level, second_enhancement等)
-  新增AI引擎演示示例 (ai_engines_demo.rs)
-  模板属性使用率达到100% - 所有属性都有明确用途

技术特性:
- 支持内容类型特定优化 (动画、自然场景、细节恢复、低光照)
- 智能分辨率处理 (裁剪vs填充、宽高比锁定)
- 焦点修复和二次增强支持
- 完整的FFmpeg参数映射和验证
This commit is contained in:
imeepos 2025-08-15 14:26:41 +08:00
parent d8d5fdedce
commit bf880a55a6
4 changed files with 299 additions and 0 deletions

View File

@ -42,3 +42,7 @@ path = "examples/advanced_output_settings.rs"
[[example]]
name = "output_settings_demo"
path = "examples/output_settings_demo.rs"
[[example]]
name = "ai_engines_demo"
path = "examples/ai_engines_demo.rs"

View File

@ -0,0 +1,148 @@
use tvai_sdk::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Topaz Video AI SDK - AI Engines Demo");
println!("===================================");
let sdk = TvaiSdk::new();
// Example 1: Animation Enhancement with Artemis
println!("\n1. Animation Enhancement (Artemis AI):");
let animation_template = TemplatePresets::animation_enhance()?;
println!(" Template: {}", animation_template.name);
println!(" Description: {}", animation_template.description);
println!(" AI Engine Flags:");
println!(" Artemis: {}", animation_template.settings.enhance.is_artemis);
println!(" Gaia: {}", animation_template.settings.enhance.is_gaia);
println!(" Theia: {}", animation_template.settings.enhance.is_theia);
println!(" Proteus: {}", animation_template.settings.enhance.is_proteus);
println!(" Iris: {}", animation_template.settings.enhance.is_iris);
let animation_command = sdk.generate_ffmpeg_command(&animation_template, "anime_input.mp4", "anime_enhanced.mp4")?;
println!(" Command:");
println!(" {}", animation_command);
// Example 2: Natural Scene Enhancement with Gaia
println!("\n2. Natural Scene Enhancement (Gaia AI):");
let nature_template = TemplatePresets::natural_scene_enhance()?;
println!(" Template: {}", nature_template.name);
println!(" AI Engine: Gaia (is_gaia: {})", nature_template.settings.enhance.is_gaia);
let nature_command = sdk.generate_ffmpeg_command(&nature_template, "landscape_input.mp4", "landscape_enhanced.mp4")?;
println!(" Command:");
println!(" {}", nature_command);
// Example 3: Detail Recovery with Theia
println!("\n3. Detail Recovery (Theia AI):");
let detail_template = TemplatePresets::detail_recovery()?;
println!(" Template: {}", detail_template.name);
println!(" AI Engine: Theia (is_theia: {})", detail_template.settings.enhance.is_theia);
println!(" Focus Fix Level: {}", detail_template.settings.enhance.focus_fix_level.as_ref().unwrap_or(&"Off".to_string()));
println!(" Second Enhancement: {}", detail_template.settings.enhance.is_second_enhancement.unwrap_or(false));
if let Some(ref fm) = detail_template.settings.filter_manager {
println!(" Second Enhancement Enabled: {}", fm.second_enhancement_enabled);
println!(" Intermediate Resolution: {}", fm.second_enhancement_intermediate_resolution);
}
let detail_command = sdk.generate_ffmpeg_command(&detail_template, "blurry_input.mp4", "detail_recovered.mp4")?;
println!(" Command:");
println!(" {}", detail_command);
// Example 4: Low Light Enhancement with Iris
println!("\n4. Low Light Enhancement (Iris AI):");
let lowlight_template = TemplatePresets::low_light_enhance()?;
println!(" Template: {}", lowlight_template.name);
println!(" AI Engine: Iris (is_iris: {})", lowlight_template.settings.enhance.is_iris);
println!(" Focus Fix Level: {}", lowlight_template.settings.enhance.focus_fix_level.as_ref().unwrap_or(&"Off".to_string()));
let lowlight_command = sdk.generate_ffmpeg_command(&lowlight_template, "dark_input.mp4", "lowlight_enhanced.mp4")?;
println!(" Command:");
println!(" {}", lowlight_command);
// Example 5: General Purpose with Proteus
println!("\n5. General Purpose (Proteus AI):");
let general_template = TemplatePresets::general_purpose_proteus()?;
println!(" Template: {}", general_template.name);
println!(" AI Engine: Proteus (is_proteus: {})", general_template.settings.enhance.is_proteus);
let general_command = sdk.generate_ffmpeg_command(&general_template, "general_input.mp4", "general_enhanced.mp4")?;
println!(" Command:");
println!(" {}", general_command);
// Example 6: Custom Template with AI Engine Selection
println!("\n6. Custom Template with AI Engine Selection:");
let custom_template = TemplateBuilder::new("Custom AI Engine Demo")
.description("Custom template demonstrating AI engine selection")
.enable_enhancement("prob-4")
.enhancement_params(30, 25, 15)
.ai_engine("gaia") // Switch to Gaia for this content
.focus_fix_level("Low") // Add focus fix
.resolution(2560, 1440) // 1440p
.video_codec("libx265", Some(22))
.build()?;
println!(" Template: {}", custom_template.name);
println!(" Selected AI Engine: Gaia");
println!(" Engine Flags:");
println!(" Artemis: {}", custom_template.settings.enhance.is_artemis);
println!(" Gaia: {}", custom_template.settings.enhance.is_gaia);
println!(" Theia: {}", custom_template.settings.enhance.is_theia);
println!(" Proteus: {}", custom_template.settings.enhance.is_proteus);
println!(" Iris: {}", custom_template.settings.enhance.is_iris);
let custom_command = sdk.generate_ffmpeg_command(&custom_template, "input.mp4", "custom_output.mp4")?;
println!(" Command:");
println!(" {}", custom_command);
// Example 7: AI Engine Comparison
println!("\n7. AI Engine Comparison for Same Content:");
let base_params = (25, 20, 10); // denoise, detail, sharpen
// Create templates with different AI engines
let artemis_comp = TemplateBuilder::new("Artemis Comparison")
.enable_enhancement("prob-4")
.enhancement_params(base_params.0, base_params.1, base_params.2)
.ai_engine("artemis")
.build()?;
let gaia_comp = TemplateBuilder::new("Gaia Comparison")
.enable_enhancement("prob-4")
.enhancement_params(base_params.0, base_params.1, base_params.2)
.ai_engine("gaia")
.build()?;
let theia_comp = TemplateBuilder::new("Theia Comparison")
.enable_enhancement("prob-4")
.enhancement_params(base_params.0, base_params.1, base_params.2)
.ai_engine("theia")
.build()?;
let artemis_cmd = sdk.generate_ffmpeg_command(&artemis_comp, "test.mp4", "test_artemis.mp4")?;
let gaia_cmd = sdk.generate_ffmpeg_command(&gaia_comp, "test.mp4", "test_gaia.mp4")?;
let theia_cmd = sdk.generate_ffmpeg_command(&theia_comp, "test.mp4", "test_theia.mp4")?;
println!(" Artemis (Animation optimized):");
println!(" {}", artemis_cmd);
println!("\n Gaia (Natural scenes optimized):");
println!(" {}", gaia_cmd);
println!("\n Theia (Detail recovery optimized):");
println!(" {}", theia_cmd);
println!("\n✅ AI Engines demo completed successfully!");
println!("\nAI Engine Summary:");
println!(" 🎨 Artemis - Best for animation, cartoons, and stylized content");
println!(" 🌿 Gaia - Best for natural scenes, landscapes, and organic content");
println!(" 🔍 Theia - Best for detail recovery, sharpening, and restoration");
println!(" 🌟 Proteus - General purpose, works well with most real-world content");
println!(" 🌙 Iris - Best for low light, noisy, and challenging footage");
println!("\nFeatures Demonstrated:");
println!(" • AI engine flag management");
println!(" • Engine-specific parameter optimization");
println!(" • Focus fix level configuration");
println!(" • Second enhancement with intermediate resolution");
println!(" • Model-specific FFmpeg parameter generation");
Ok(())
}

View File

@ -224,6 +224,44 @@ impl FfmpegCommandGenerator {
params.push(format!("recover_detail={:.2}", recover));
}
// Add model-specific optimizations based on AI engine flags
if settings.is_artemis {
// Artemis optimizations for animation/cartoon content
params.push("content_type=animation".to_string());
params.push("edge_enhance=1".to_string());
} else if settings.is_gaia {
// Gaia optimizations for natural scenes
params.push("content_type=natural".to_string());
params.push("texture_enhance=1".to_string());
} else if settings.is_theia {
// Theia optimizations for detail recovery
params.push("detail_mode=high".to_string());
params.push("sharpening_boost=1".to_string());
} else if settings.is_iris {
// Iris optimizations for low light/noise
params.push("noise_profile=aggressive".to_string());
params.push("low_light_boost=1".to_string());
} else if settings.is_proteus {
// Proteus is the default general-purpose model
params.push("content_type=general".to_string());
}
// Add focus fix level if specified
if let Some(ref focus_level) = settings.focus_fix_level {
if focus_level != "Off" {
let focus_value = match focus_level.as_str() {
"Low" => 0.25,
"Medium" => 0.5,
"High" => 0.75,
"Maximum" => 1.0,
_ => 0.0,
};
if focus_value > 0.0 {
params.push(format!("focus_fix={:.2}", focus_value));
}
}
}
Ok(format!("tvai_up={}", params.join(":")))
}

View File

@ -355,6 +355,54 @@ impl TemplateBuilder {
self
}
/// Set AI model engine (automatically sets appropriate flags)
pub fn ai_engine(mut self, engine: &str) -> Self {
// Reset all model flags first
self.template.settings.enhance.is_artemis = false;
self.template.settings.enhance.is_gaia = false;
self.template.settings.enhance.is_theia = false;
self.template.settings.enhance.is_proteus = false;
self.template.settings.enhance.is_iris = false;
// Set the appropriate flag based on engine
match engine.to_lowercase().as_str() {
"artemis" => self.template.settings.enhance.is_artemis = true,
"gaia" => self.template.settings.enhance.is_gaia = true,
"theia" => self.template.settings.enhance.is_theia = true,
"proteus" => self.template.settings.enhance.is_proteus = true,
"iris" => self.template.settings.enhance.is_iris = true,
_ => self.template.settings.enhance.is_proteus = true, // Default to Proteus
}
self
}
/// Set focus fix level
pub fn focus_fix_level(mut self, level: &str) -> Self {
self.template.settings.enhance.focus_fix_level = Some(level.to_string());
self
}
/// Enable second enhancement
pub fn second_enhancement(mut self, enabled: bool, intermediate_resolution: Option<i32>) -> Self {
self.template.settings.enhance.is_second_enhancement = Some(enabled);
if enabled {
// Create filter manager if it doesn't exist
if self.template.settings.filter_manager.is_none() {
self.template.settings.filter_manager = Some(crate::FilterManagerSettings {
second_enhancement_enabled: true,
second_enhancement_intermediate_resolution: intermediate_resolution.unwrap_or(3),
});
} else if let Some(ref mut fm) = self.template.settings.filter_manager {
fm.second_enhancement_enabled = true;
if let Some(res) = intermediate_resolution {
fm.second_enhancement_intermediate_resolution = res;
}
}
}
self
}
/// Enable grain effect
pub fn enable_grain(mut self, amount: i32, size: i32) -> Self {
self.template.settings.grain.active = true;
@ -547,6 +595,67 @@ impl TemplatePresets {
.output_active(false) // Disable advanced output settings
.build()
}
/// Create an animation/cartoon optimized template
pub fn animation_enhance() -> Result<Template, TvaiError> {
TemplateBuilder::new("Animation Enhancement")
.description("Optimized for animation and cartoon content using Artemis AI")
.enable_enhancement("art-2") // Artemis model
.ai_engine("artemis") // Set Artemis flags
.enhancement_params(15, 40, 25) // Low noise, high detail, good sharpening
.resolution(1920, 1080)
.video_codec("libx264", Some(20)) // High quality for animation
.preset("slow")
.build()
}
/// Create a natural scene optimized template
pub fn natural_scene_enhance() -> Result<Template, TvaiError> {
TemplateBuilder::new("Natural Scene Enhancement")
.description("Optimized for natural landscapes using Gaia AI")
.enable_enhancement("gai-2") // Gaia model
.ai_engine("gaia") // Set Gaia flags
.enhancement_params(20, 35, 15) // Moderate noise, high detail, light sharpening
.resolution(3840, 2160) // 4K for nature content
.video_codec("hevc_nvenc", Some(18))
.preset("slow")
.build()
}
/// Create a detail recovery template
pub fn detail_recovery() -> Result<Template, TvaiError> {
TemplateBuilder::new("Detail Recovery")
.description("Maximum detail recovery using Theia AI")
.enable_enhancement("the-2") // Theia model
.ai_engine("theia") // Set Theia flags
.enhancement_params(10, 60, 40) // Low noise, maximum detail, high sharpening
.focus_fix_level("High") // High focus fix
.second_enhancement(true, Some(4)) // Enable second pass at 2x resolution
.build()
}
/// Create a low light optimized template
pub fn low_light_enhance() -> Result<Template, TvaiError> {
TemplateBuilder::new("Low Light Enhancement")
.description("Optimized for low light and noisy footage using Iris AI")
.enable_enhancement("nyx-3") // Iris/Nyx model for noise
.ai_engine("iris") // Set Iris flags
.enhancement_params(60, 20, 5) // High noise reduction, moderate detail
.focus_fix_level("Medium") // Medium focus fix for low light
.build()
}
/// Create a general purpose template with Proteus
pub fn general_purpose_proteus() -> Result<Template, TvaiError> {
TemplateBuilder::new("General Purpose Proteus")
.description("General purpose enhancement using Proteus AI")
.enable_enhancement("prob-4") // Proteus model
.ai_engine("proteus") // Set Proteus flags (default)
.enhancement_params(25, 30, 20) // Balanced settings
.enable_stabilization(60, 1) // Add stabilization
.resolution(1920, 1080)
.build()
}
}
impl Default for TvaiSdk {