集成测试套件 - 创建完整的集成测试 (integration_tests.rs) - 测试库初始化和配置管理 - 测试 GPU 检测和优化功能 - 测试性能监控和基准测试 - 测试错误处理和用户友好消息 - 测试配置文件持久化 - 测试模型和参数验证 - 测试临时文件管理 - 所有测试通过 性能基准测试 - 创建完整的基准测试套件 (performance_benchmarks.rs) - GPU 检测性能: ~193ms - 设置保存/加载: ~1.56ms - 预设查找: ~29ns (超快) - 临时文件管理: ~96μs - 参数验证: ~3.6ns (极快) - 错误消息生成: ~266ns - 模型操作: ~1.9ns (极快) - 系统检测: 24μs - 30ms 完整 API 文档 - 创建详细的 API 文档 (docs/API.md) - 核心组件使用指南 - 所有方法和参数说明 - 代码示例和最佳实践 - 错误处理指南 - 性能优化建议 用户指南 - 创建完整的用户指南 (docs/USER_GUIDE.md) - 快速入门教程 - 常见用例和场景 - 配置管理指南 - 模型选择指南 - 性能优化技巧 - 故障排除指南 更新项目文档 - 更新主 README.md - 标记项目为 100% 完成 - 添加文档链接和使用指南 - 添加性能和测试信息 - 添加开发设置说明 - 添加变更日志 测试结果总结 - 单元测试: 6/6 通过 - 集成测试: 10/10 通过 - 文档测试: 1/1 通过 - 基准测试: 13/13 完成 - 所有示例运行成功 最终项目统计 - **总代码行数**: 4,127行 - **模块文件**: 25个 - **示例文件**: 6个 - **测试文件**: 2个 (单元 + 集成) - **基准测试**: 1个 (13项基准) - **文档文件**: 3个 (API + 用户指南 + README) 功能完整性 (100%) - 视频处理 (超分辨率 + 插值) - 图片处理 (超分辨率 + 批量) - 格式转换 (视频 图片序列) - 便捷接口 (一键处理函数) - 配置管理 (全局设置 + 预设) - 性能优化 (GPU检测 + 监控) - 错误处理 (用户友好消息) - 文档和测试 (完整覆盖) 项目状态: 完成 (COMPLETE) 所有六个开发阶段已完成,tvai 库已准备好用于生产环境!
227 lines
8.7 KiB
Rust
227 lines
8.7 KiB
Rust
//! Video processing examples demonstrating all video enhancement features
|
|
|
|
use tvai::*;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
println!("Topaz Video AI Library - Video Processing Examples");
|
|
|
|
// Detect Topaz installation
|
|
if let Some(topaz_path) = detect_topaz_installation() {
|
|
println!("Found Topaz Video AI at: {}", topaz_path.display());
|
|
|
|
// Create configuration
|
|
let config = TvaiConfig::builder()
|
|
.topaz_path(topaz_path)
|
|
.use_gpu(true)
|
|
.build()?;
|
|
|
|
// Create processor
|
|
let mut processor = TvaiProcessor::new(config)?;
|
|
println!("Processor created successfully");
|
|
|
|
// Demonstrate video upscaling
|
|
demonstrate_video_upscaling(&mut processor).await?;
|
|
|
|
// Demonstrate frame interpolation
|
|
demonstrate_frame_interpolation(&mut processor).await?;
|
|
|
|
// Demonstrate combined enhancement
|
|
demonstrate_combined_enhancement(&mut processor).await?;
|
|
|
|
// Demonstrate format conversion
|
|
demonstrate_format_conversion(&mut processor).await?;
|
|
|
|
// Demonstrate quick functions
|
|
demonstrate_quick_functions().await?;
|
|
|
|
println!("All video processing examples completed successfully!");
|
|
} else {
|
|
println!("Topaz Video AI not found. Please install it first.");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn demonstrate_video_upscaling(processor: &mut TvaiProcessor) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
println!("\n=== Video Upscaling Demo ===");
|
|
|
|
// Create upscaling parameters for different scenarios
|
|
let scenarios = vec![
|
|
("General Purpose", VideoUpscaleParams {
|
|
scale_factor: 2.0,
|
|
model: UpscaleModel::Iris3,
|
|
compression: 0.0,
|
|
blend: 0.1,
|
|
quality_preset: QualityPreset::HighQuality,
|
|
}),
|
|
("Old Video Restoration", VideoUpscaleParams::for_old_video()),
|
|
("Game Content", VideoUpscaleParams::for_game_content()),
|
|
("Animation", VideoUpscaleParams::for_animation()),
|
|
("Portrait Video", VideoUpscaleParams::for_portrait()),
|
|
];
|
|
|
|
for (name, params) in scenarios {
|
|
println!("Scenario: {}", name);
|
|
println!(" Model: {} ({})", params.model.as_str(), params.model.description());
|
|
println!(" Scale: {}x", params.scale_factor);
|
|
println!(" Compression: {}", params.compression);
|
|
println!(" Blend: {}", params.blend);
|
|
println!(" Quality: {:?}", params.quality_preset);
|
|
|
|
// In a real scenario, you would call:
|
|
// let result = processor.upscale_video(input, output, params, Some(&progress_callback)).await?;
|
|
// println!(" Processing time: {:?}", result.processing_time);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn demonstrate_frame_interpolation(processor: &mut TvaiProcessor) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
println!("\n=== Frame Interpolation Demo ===");
|
|
|
|
// Create interpolation parameters for different scenarios
|
|
let scenarios = vec![
|
|
("Slow Motion (24fps -> 60fps)", InterpolationParams {
|
|
input_fps: 24,
|
|
multiplier: 2.5,
|
|
model: InterpolationModel::Apo8,
|
|
target_fps: Some(60),
|
|
}),
|
|
("Animation Smoothing", InterpolationParams::for_animation(12, 2.0)),
|
|
("High Quality Slow Motion", InterpolationParams::for_slow_motion(30, 4.0)),
|
|
("Fast Processing", InterpolationParams {
|
|
input_fps: 24,
|
|
multiplier: 2.0,
|
|
model: InterpolationModel::Apf1,
|
|
target_fps: None,
|
|
}),
|
|
];
|
|
|
|
for (name, params) in scenarios {
|
|
let target_fps = params.target_fps.unwrap_or((params.input_fps as f32 * params.multiplier) as u32);
|
|
|
|
println!("Scenario: {}", name);
|
|
println!(" Model: {} ({})", params.model.as_str(), params.model.description());
|
|
println!(" Input FPS: {}", params.input_fps);
|
|
println!(" Multiplier: {}x", params.multiplier);
|
|
println!(" Target FPS: {}", target_fps);
|
|
|
|
// In a real scenario, you would call:
|
|
// let result = processor.interpolate_video(input, output, params, Some(&progress_callback)).await?;
|
|
// println!(" Processing time: {:?}", result.processing_time);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn demonstrate_combined_enhancement(processor: &mut TvaiProcessor) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
println!("\n=== Combined Enhancement Demo ===");
|
|
|
|
// Create combined enhancement parameters
|
|
let scenarios = vec![
|
|
("Complete Enhancement", VideoEnhanceParams {
|
|
upscale: Some(VideoUpscaleParams {
|
|
scale_factor: 2.0,
|
|
model: UpscaleModel::Iris3,
|
|
compression: 0.0,
|
|
blend: 0.1,
|
|
quality_preset: QualityPreset::HighQuality,
|
|
}),
|
|
interpolation: Some(InterpolationParams {
|
|
input_fps: 24,
|
|
multiplier: 2.0,
|
|
model: InterpolationModel::Apo8,
|
|
target_fps: Some(48),
|
|
}),
|
|
}),
|
|
("Upscale Only", VideoEnhanceParams {
|
|
upscale: Some(VideoUpscaleParams::for_old_video()),
|
|
interpolation: None,
|
|
}),
|
|
("Interpolation Only", VideoEnhanceParams {
|
|
upscale: None,
|
|
interpolation: Some(InterpolationParams::for_slow_motion(30, 2.0)),
|
|
}),
|
|
];
|
|
|
|
for (name, params) in scenarios {
|
|
println!("Scenario: {}", name);
|
|
if let Some(ref upscale) = params.upscale {
|
|
println!(" Upscale: {} @ {}x", upscale.model.as_str(), upscale.scale_factor);
|
|
}
|
|
if let Some(ref interpolation) = params.interpolation {
|
|
let target_fps = interpolation.target_fps.unwrap_or((interpolation.input_fps as f32 * interpolation.multiplier) as u32);
|
|
println!(" Interpolation: {} ({}fps -> {}fps)",
|
|
interpolation.model.as_str(),
|
|
interpolation.input_fps,
|
|
target_fps
|
|
);
|
|
}
|
|
|
|
// In a real scenario, you would call:
|
|
// let result = processor.enhance_video(input, output, params, Some(&progress_callback)).await?;
|
|
// println!(" Processing time: {:?}", result.processing_time);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn demonstrate_format_conversion(processor: &mut TvaiProcessor) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
println!("\n=== Format Conversion Demo ===");
|
|
|
|
// Demonstrate image sequence to video conversion
|
|
println!("Image Sequence to Video:");
|
|
println!(" - Collect image files in sequence");
|
|
println!(" - Set target FPS (e.g., 24, 30, 60)");
|
|
println!(" - Choose quality preset");
|
|
println!(" - Generate video file");
|
|
|
|
// In a real scenario:
|
|
// let image_paths = vec![/* image file paths */];
|
|
// let result = processor.images_to_video(&image_paths, output_video, 30.0, QualityPreset::HighQuality, Some(&progress_callback)).await?;
|
|
|
|
println!("\nVideo to Image Sequence:");
|
|
println!(" - Extract all frames from video");
|
|
println!(" - Choose output format (PNG, JPG, etc.)");
|
|
println!(" - Set quality level");
|
|
println!(" - Generate numbered image files");
|
|
|
|
// In a real scenario:
|
|
// let image_paths = processor.video_to_images(input_video, output_dir, "png", 95, Some(&progress_callback)).await?;
|
|
// println!(" Extracted {} frames", image_paths.len());
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn demonstrate_quick_functions() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
println!("\n=== Quick Functions Demo ===");
|
|
|
|
println!("Quick Upscale Video:");
|
|
println!(" - One-line video upscaling");
|
|
println!(" - Automatic Topaz detection");
|
|
println!(" - Default high-quality settings");
|
|
println!(" - Usage: quick_upscale_video(input, output, 2.0).await?");
|
|
|
|
println!("\nAuto Enhance Video:");
|
|
println!(" - Intelligent enhancement detection");
|
|
println!(" - Automatic parameter selection");
|
|
println!(" - Based on video characteristics");
|
|
println!(" - Usage: auto_enhance_video(input, output).await?");
|
|
|
|
// In a real scenario:
|
|
// let result = quick_upscale_video(Path::new("input.mp4"), Path::new("output.mp4"), 2.0).await?;
|
|
// let result = auto_enhance_video(Path::new("input.mp4"), Path::new("enhanced.mp4")).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
// Progress callback example
|
|
fn create_progress_callback(operation_name: &str) -> ProgressCallback {
|
|
let name = operation_name.to_string();
|
|
Box::new(move |progress| {
|
|
let percentage = (progress * 100.0) as u32;
|
|
println!("{}: {}%", name, percentage);
|
|
})
|
|
}
|