feat: 修复tvai调用问题
This commit is contained in:
134
cargos/tvai/examples/migration_demo.rs
Normal file
134
cargos/tvai/examples/migration_demo.rs
Normal file
@@ -0,0 +1,134 @@
|
||||
//! Migration Demo: From Old Presets to New Template System
|
||||
//!
|
||||
//! This example shows how to migrate from the old preset system
|
||||
//! to the new Topaz template system.
|
||||
|
||||
use tvai::*;
|
||||
use std::path::Path;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== Migration from Old Presets to New Template System ===\n");
|
||||
|
||||
// Show old preset system (now empty)
|
||||
println!("Old Preset System (deprecated):");
|
||||
let old_presets = global_presets().lock().unwrap();
|
||||
let video_presets = old_presets.list_video_presets();
|
||||
let image_presets = old_presets.list_image_presets();
|
||||
|
||||
if video_presets.is_empty() && image_presets.is_empty() {
|
||||
println!(" ⚠ No presets available (moved to template system)");
|
||||
} else {
|
||||
println!(" Video presets: {:?}", video_presets);
|
||||
println!(" Image presets: {:?}", image_presets);
|
||||
}
|
||||
drop(old_presets);
|
||||
println!();
|
||||
|
||||
// Show new template system
|
||||
println!("New Template System (recommended):");
|
||||
let templates = list_available_templates();
|
||||
println!(" Available templates: {}", templates.len());
|
||||
|
||||
for (i, template_name) in templates.iter().take(5).enumerate() {
|
||||
if let Some((name, description)) = get_template_info(template_name) {
|
||||
println!(" {}. {} ({})", i + 1, name, template_name);
|
||||
println!(" {}", description);
|
||||
}
|
||||
}
|
||||
|
||||
if templates.len() > 5 {
|
||||
println!(" ... and {} more templates", templates.len() - 5);
|
||||
}
|
||||
println!();
|
||||
|
||||
// Migration examples
|
||||
println!("=== Migration Examples ===\n");
|
||||
|
||||
// Example 1: Video upscaling migration
|
||||
println!("1. Video Upscaling Migration:");
|
||||
println!(" Old way (deprecated):");
|
||||
println!(" let presets = global_presets().lock().unwrap();");
|
||||
println!(" let preset = presets.get_video_preset(\"general_2x\");");
|
||||
println!();
|
||||
println!(" New way (recommended):");
|
||||
println!(" upscale_to_4k(input, output).await?;");
|
||||
println!(" // or");
|
||||
println!(" process_with_template(input, output, \"upscale_to_4k\").await?;");
|
||||
println!();
|
||||
|
||||
// Example 2: Slow motion migration
|
||||
println!("2. Slow Motion Migration:");
|
||||
println!(" Old way (deprecated):");
|
||||
println!(" let presets = global_presets().lock().unwrap();");
|
||||
println!(" let preset = presets.get_video_preset(\"slow_motion_4x\");");
|
||||
println!();
|
||||
println!(" New way (recommended):");
|
||||
println!(" slow_motion_4x(input, output).await?;");
|
||||
println!(" // or");
|
||||
println!(" process_with_template(input, output, \"4x_slow_motion\").await?;");
|
||||
println!();
|
||||
|
||||
// Example 3: Custom processing migration
|
||||
println!("3. Custom Processing Migration:");
|
||||
println!(" Old way (deprecated):");
|
||||
println!(" let mut presets = global_presets().lock().unwrap();");
|
||||
println!(" presets.add_video_preset(name, custom_preset);");
|
||||
println!();
|
||||
println!(" New way (recommended):");
|
||||
println!(" let manager = global_topaz_templates().lock().unwrap();");
|
||||
println!(" manager.load_from_file(name, \"template.json\")?;");
|
||||
println!(" process_with_template(input, output, name).await?;");
|
||||
println!();
|
||||
|
||||
// Show advantages of new system
|
||||
println!("=== Advantages of New Template System ===");
|
||||
println!("✅ Based on official Topaz Video AI templates");
|
||||
println!("✅ Complete parameter coverage (all Topaz settings)");
|
||||
println!("✅ JSON format compatible with Topaz Video AI");
|
||||
println!("✅ Built-in validation and error handling");
|
||||
println!("✅ Easy template sharing and customization");
|
||||
println!("✅ Convenient API functions for common tasks");
|
||||
println!("✅ Better performance and memory usage");
|
||||
println!();
|
||||
|
||||
// Demonstrate template application
|
||||
println!("=== Template Application Demo ===");
|
||||
let manager = global_topaz_templates().lock().unwrap();
|
||||
|
||||
if let Ok(applied) = manager.apply_template("upscale_to_4k") {
|
||||
println!("Applied template: {}", applied.name);
|
||||
println!("Description: {}", applied.description);
|
||||
|
||||
if let Some(upscale) = &applied.enhance_params.upscale {
|
||||
println!("Upscale settings:");
|
||||
println!(" • Scale factor: {}x", upscale.scale_factor);
|
||||
println!(" • AI Model: {:?}", upscale.model);
|
||||
println!(" • Quality preset: {:?}", upscale.quality_preset);
|
||||
}
|
||||
|
||||
if let Some(interpolation) = &applied.enhance_params.interpolation {
|
||||
println!("Interpolation settings:");
|
||||
println!(" • Multiplier: {}x", interpolation.multiplier);
|
||||
println!(" • Model: {:?}", interpolation.model);
|
||||
}
|
||||
}
|
||||
drop(manager);
|
||||
println!();
|
||||
|
||||
// Migration checklist
|
||||
println!("=== Migration Checklist ===");
|
||||
println!("□ Replace global_presets() calls with global_topaz_templates()");
|
||||
println!("□ Use template-based functions: upscale_to_4k(), convert_to_60fps(), etc.");
|
||||
println!("□ Convert custom presets to JSON template format");
|
||||
println!("□ Update error handling for new template system");
|
||||
println!("□ Test with new template validation");
|
||||
println!("□ Update documentation and examples");
|
||||
println!();
|
||||
|
||||
println!("=== Migration Complete! ===");
|
||||
println!("The new template system provides better functionality and compatibility.");
|
||||
println!("See docs/TEMPLATES.md for detailed documentation.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user