mixvideo-v2/cargos/tvai/examples/simple_usage.rs

128 lines
4.4 KiB
Rust

//! Simple Usage Examples
//!
//! This example shows the simplest ways to use the tvai template system
//! for common video processing tasks.
use tvai::*;
use std::path::Path;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
println!("=== Simple Usage Examples ===\n");
// Example 1: Upscale a video to 4K
println!("1. Upscaling to 4K:");
println!(" upscale_to_4k(input, output).await?;");
if Path::new("input.mp4").exists() {
match upscale_to_4k(Path::new("input.mp4"), Path::new("output_4k.mp4")).await {
Ok(_) => println!(" ✓ Successfully upscaled to 4K!"),
Err(e) => println!(" ✗ Error: {}", e),
}
} else {
println!(" (input.mp4 not found - example only)");
}
println!();
// Example 2: Convert to 60fps
println!("2. Converting to 60fps:");
println!(" convert_to_60fps(input, output).await?;");
if Path::new("input.mp4").exists() {
match convert_to_60fps(Path::new("input.mp4"), Path::new("output_60fps.mp4")).await {
Ok(_) => println!(" ✓ Successfully converted to 60fps!"),
Err(e) => println!(" ✗ Error: {}", e),
}
} else {
println!(" (input.mp4 not found - example only)");
}
println!();
// Example 3: Remove noise
println!("3. Removing noise:");
println!(" remove_noise(input, output).await?;");
if Path::new("noisy_video.mp4").exists() {
match remove_noise(Path::new("noisy_video.mp4"), Path::new("clean_video.mp4")).await {
Ok(_) => println!(" ✓ Successfully removed noise!"),
Err(e) => println!(" ✗ Error: {}", e),
}
} else {
println!(" (noisy_video.mp4 not found - example only)");
}
println!();
// Example 4: Create slow motion
println!("4. Creating 4x slow motion:");
println!(" slow_motion_4x(input, output).await?;");
if Path::new("action_video.mp4").exists() {
match slow_motion_4x(Path::new("action_video.mp4"), Path::new("slow_motion.mp4")).await {
Ok(_) => println!(" ✓ Successfully created slow motion!"),
Err(e) => println!(" ✗ Error: {}", e),
}
} else {
println!(" (action_video.mp4 not found - example only)");
}
println!();
// Example 5: Stabilize shaky video
println!("5. Stabilizing shaky video:");
println!(" auto_crop_stabilization(input, output).await?;");
if Path::new("shaky_video.mp4").exists() {
match auto_crop_stabilization(Path::new("shaky_video.mp4"), Path::new("stable_video.mp4")).await {
Ok(_) => println!(" ✓ Successfully stabilized video!"),
Err(e) => println!(" ✗ Error: {}", e),
}
} else {
println!(" (shaky_video.mp4 not found - example only)");
}
println!();
// Example 6: Using any template by name
println!("6. Using any template by name:");
println!(" process_with_template(input, output, \"template_name\").await?;");
if Path::new("film_footage.mp4").exists() {
match process_with_template(
Path::new("film_footage.mp4"),
Path::new("enhanced_film.mp4"),
"film_stock_4k_strong"
).await {
Ok(_) => println!(" ✓ Successfully processed with film stock template!"),
Err(e) => println!(" ✗ Error: {}", e),
}
} else {
println!(" (film_footage.mp4 not found - example only)");
}
println!();
// Show available templates
println!("Available templates:");
let templates = list_available_templates();
for template_name in templates.iter().take(5) {
if let Some((name, _)) = get_template_info(template_name) {
println!("{} ({})", name, template_name);
}
}
if templates.len() > 5 {
println!(" ... and {} more templates", templates.len() - 5);
}
println!();
// Show how to get template information
println!("Getting template information:");
if let Some((name, description)) = get_template_info("upscale_to_4k") {
println!(" Template: {}", name);
println!(" Description: {}", description);
}
println!();
println!("=== That's it! ===");
println!("The tvai template system makes video processing simple and powerful.");
println!("Just choose the right function for your task and let the AI do the work!");
Ok(())
}