feat: 修复tvai调用问题

This commit is contained in:
imeepos
2025-08-14 13:01:43 +08:00
parent 97bada92d9
commit c36e0d3bac
99 changed files with 11098 additions and 8658 deletions

View File

@@ -11,6 +11,9 @@ A Rust library for integrating with Topaz Video AI to perform video and image en
- 🔧 **Multiple AI Models**: 16 upscaling and 4 interpolation models
- 📦 **Batch Processing**: Process multiple files efficiently
- 🎛️ **Flexible Configuration**: Fine-tune processing parameters
- 📋 **Template System**: Built-in templates from Topaz Video AI examples
- 🚀 **Easy API**: Simple functions for common video processing tasks
-**FFmpeg Integration**: Generate FFmpeg commands from templates
## Requirements
@@ -30,7 +33,61 @@ tvai = "0.1.0"
## Quick Start
### Video Upscaling
### Using Built-in Templates (Recommended)
```rust
use tvai::*;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Upscale to 4K using built-in template
upscale_to_4k(
Path::new("input.mp4"),
Path::new("output_4k.mp4")
).await?;
// Convert to 60fps
convert_to_60fps(
Path::new("input.mp4"),
Path::new("output_60fps.mp4")
).await?;
// Remove noise
remove_noise(
Path::new("noisy_video.mp4"),
Path::new("clean_video.mp4")
).await?;
// Create slow motion
slow_motion_4x(
Path::new("action_video.mp4"),
Path::new("slow_motion.mp4")
).await?;
Ok(())
}
```
### Using Any Template by Name
```rust
use tvai::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Process with any built-in template
process_with_template(
Path::new("input.mp4"),
Path::new("output.mp4"),
"film_stock_4k_strong"
).await?;
Ok(())
}
```
### Traditional API (Still Available)
```rust
use tvai::*;
@@ -43,7 +100,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::path::Path::new("output.mp4"),
2.0,
).await?;
Ok(())
}
```
@@ -155,14 +212,73 @@ let gpu_info = detect_gpu_support();
let ffmpeg_info = detect_ffmpeg();
```
## Error Handling
## Template System
The library uses the `anyhow` crate for error handling:
The library includes a comprehensive template system with built-in templates from Topaz Video AI examples:
### Available Templates
- **Upscaling**: `upscale_to_4k`, `upscale_to_fhd`, `upscale_4k_convert_60fps`
- **Frame Rate**: `convert_to_60fps`, `4x_slow_motion`, `8x_super_slow_motion`
- **Enhancement**: `remove_noise`, `film_stock_4k_light/medium/strong`
- **Restoration**: `deinterlace_upscale_fhd`, `minidv_hd_int_basic`, `auto_crop_stabilization`
### Template Management
```rust
use tvai::*;
match quick_upscale_video(input, output, 2.0).await {
// List all available templates
let templates = list_available_templates();
for template_name in templates {
if let Some((name, description)) = get_template_info(&template_name) {
println!("{}: {}", name, description);
}
}
// Load custom templates
let manager = global_topaz_templates().lock().unwrap();
manager.load_from_file("my_template".to_string(), "path/to/template.json")?;
manager.load_examples_templates("templates_directory/")?;
```
### Custom Templates
You can create and load custom templates in Topaz Video AI JSON format. See [Template Documentation](docs/TEMPLATES.md) for details.
### FFmpeg Command Generation
Generate FFmpeg commands from templates for external use:
```rust
use tvai::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let manager = global_topaz_templates().lock().unwrap();
// Generate basic command
let cmd = manager.quick_ffmpeg_command("upscale_to_4k", "input.mp4", "output.mp4")?;
println!("{}", cmd);
// GPU-specific commands
let nvidia_cmd = manager.gpu_ffmpeg_command("convert_to_60fps", "input.mp4", "output.mp4", "nvidia")?;
let amd_cmd = manager.gpu_ffmpeg_command("remove_noise", "input.mp4", "output.mp4", "amd")?;
// Custom quality
let hq_cmd = manager.quality_ffmpeg_command("film_stock_4k_strong", "input.mp4", "output.mp4", 15, "slow")?;
Ok(())
}
```
## Error Handling
The library uses comprehensive error handling with user-friendly messages:
```rust
use tvai::*;
match upscale_to_4k(input, output).await {
Ok(result) => println!("Success: {:?}", result),
Err(TvaiError::TopazNotFound(path)) => {
eprintln!("Topaz not found at: {}", path);
@@ -170,7 +286,10 @@ match quick_upscale_video(input, output, 2.0).await {
Err(TvaiError::FfmpegError(msg)) => {
eprintln!("FFmpeg error: {}", msg);
},
Err(e) => eprintln!("Other error: {}", e),
Err(e) => {
eprintln!("Error: {}", e);
eprintln!("Suggestion: {}", e.user_friendly_message());
},
}
```
@@ -188,16 +307,19 @@ match quick_upscale_video(input, output, 2.0).await {
- [x] Progress callbacks and monitoring
- [x] Global configuration management
- [x] Preset management system
- [x] Template system with built-in Topaz Video AI templates
- [x] Convenient API functions for common tasks
- [x] Performance optimization
- [x] Enhanced error handling
- [x] Comprehensive testing (unit + integration + benchmarks)
- [x] Complete documentation (API + User Guide)
- [x] Complete documentation (API + User Guide + Templates)
## Documentation
### English
- 📖 [API Documentation](docs/API.md) - Complete API reference
- 📚 [User Guide](docs/USER_GUIDE.md) - Comprehensive usage guide
- 📋 [Template Documentation](docs/TEMPLATES.md) - Template system guide
### 中文文档
- 📖 [API 文档](docs/API文档.md) - 完整 API 参考