204 lines
6.1 KiB
Rust
204 lines
6.1 KiB
Rust
// Standalone Scene VLM Test Tool
|
|
// This tool manually triggers Scene VLM processing for testing
|
|
|
|
use anyhow::Result;
|
|
use momentry_core::core::db::PostgresDb;
|
|
use momentry_core::core::processor::scene_vlm::SceneVlmProcessor;
|
|
use momentry_core::Database;
|
|
use sqlx::postgres::PgPoolOptions;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
// Initialize tracing
|
|
tracing_subscriber::fmt::init();
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
if args.len() < 2 {
|
|
eprintln!("Usage: {} <file_uuid>", args[0]);
|
|
std::process::exit(1);
|
|
}
|
|
|
|
let uuid = &args[1];
|
|
let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR")
|
|
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string());
|
|
|
|
println!("=== Scene VLM Test Tool ===");
|
|
println!("UUID: {}", uuid);
|
|
println!("Output: {}", output_dir);
|
|
println!();
|
|
|
|
// Load config
|
|
let (enabled, interval_sec, samples, use_cuts, max_workers) =
|
|
momentry_core::core::config::get_scene_vlm_config();
|
|
|
|
println!("Config:");
|
|
println!(" Enabled: {}", enabled);
|
|
println!(" Interval: {}s", interval_sec);
|
|
println!(" Samples: {}", samples);
|
|
println!(" Use CUTs: {}", use_cuts);
|
|
println!(" Max Workers: {}", max_workers);
|
|
println!();
|
|
|
|
if !enabled {
|
|
println!("❌ Scene VLM is disabled");
|
|
println!("Set MOMENTRY_SCENE_VLM_ENABLED=true to enable");
|
|
return Ok(());
|
|
}
|
|
|
|
// Load video metadata
|
|
println!("Loading video metadata...");
|
|
let db_url = momentry_core::core::config::DATABASE_URL.clone();
|
|
let pool = PgPoolOptions::new()
|
|
.max_connections(5)
|
|
.connect(&db_url)
|
|
.await?;
|
|
let db = PostgresDb::from_pool(pool);
|
|
|
|
let video = db
|
|
.get_video_by_uuid(uuid)
|
|
.await?
|
|
.ok_or_else(|| anyhow::anyhow!("Video not found: {}", uuid))?;
|
|
|
|
let fps = video.fps;
|
|
let duration = video.duration;
|
|
let width = video.width;
|
|
let height = video.height;
|
|
let total_frames = video.total_frames as u32;
|
|
let video_path = video.file_path.clone();
|
|
|
|
println!("Video:");
|
|
println!(" Path: {}", video_path);
|
|
println!(" Duration: {}s", duration);
|
|
println!(" FPS: {}", fps);
|
|
println!(" Resolution: {}x{}", width, height);
|
|
println!(" Total frames: {}", total_frames);
|
|
println!();
|
|
|
|
// Load CUT data
|
|
println!("Loading CUT data...");
|
|
let cut_path = format!("{}/{}.cut.json", output_dir, uuid);
|
|
let cut_data = if std::path::Path::new(&cut_path).exists() {
|
|
let json = std::fs::read_to_string(&cut_path)?;
|
|
let data: serde_json::Value = serde_json::from_str(&json)?;
|
|
let scene_count = data
|
|
.get("scenes")
|
|
.and_then(|s| s.as_array())
|
|
.map(|a| a.len())
|
|
.unwrap_or(0);
|
|
println!(" Scenes: {}", scene_count);
|
|
data
|
|
} else {
|
|
println!(" ⚠️ No CUT data, using empty");
|
|
serde_json::json!({"scenes": []})
|
|
};
|
|
println!();
|
|
|
|
// Create processor
|
|
let processor = SceneVlmProcessor::new(samples, use_cuts, max_workers);
|
|
|
|
// Generate profile
|
|
println!("Generating scene profile...");
|
|
let start = std::time::Instant::now();
|
|
let profile = processor
|
|
.generate_scene_profile(
|
|
&video_path,
|
|
uuid,
|
|
&output_dir,
|
|
interval_sec,
|
|
&cut_data,
|
|
fps,
|
|
duration,
|
|
width,
|
|
height,
|
|
total_frames,
|
|
)
|
|
.await?;
|
|
let elapsed = start.elapsed();
|
|
|
|
println!(" ✅ Generated in {:.2}s", elapsed.as_secs_f64());
|
|
println!(" Total scenes: {}", profile.total_scenes);
|
|
println!();
|
|
|
|
// Extract frames
|
|
println!("Extracting frames...");
|
|
let start = std::time::Instant::now();
|
|
let extracted =
|
|
SceneVlmProcessor::extract_scene_frames(&video_path, &output_dir, uuid, &profile.scenes)
|
|
.await?;
|
|
let elapsed = start.elapsed();
|
|
|
|
println!(
|
|
" ✅ Extracted {} frames in {:.2}s",
|
|
extracted.len(),
|
|
elapsed.as_secs_f64()
|
|
);
|
|
println!();
|
|
|
|
// Generate VLM descriptions
|
|
println!("Generating VLM descriptions...");
|
|
let start = std::time::Instant::now();
|
|
let mut profile = profile;
|
|
|
|
match SceneVlmProcessor::generate_vlm_descriptions(
|
|
&output_dir,
|
|
uuid,
|
|
&mut profile.scenes,
|
|
max_workers,
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => {
|
|
let elapsed = start.elapsed();
|
|
println!(
|
|
" ✅ Generated VLM descriptions in {:.2}s",
|
|
elapsed.as_secs_f64()
|
|
);
|
|
}
|
|
Err(e) => {
|
|
println!(" ⚠️ VLM generation failed: {}", e);
|
|
}
|
|
}
|
|
println!();
|
|
|
|
// Save profile
|
|
println!("Saving profile...");
|
|
SceneVlmProcessor::save_scene_profile(&profile, &output_dir)?;
|
|
println!(" ✅ Saved to {}/{}.scenes.json", output_dir, uuid);
|
|
println!();
|
|
|
|
// Print summary
|
|
println!("=== Summary ===");
|
|
println!("Total frames: {}", profile.total_scenes);
|
|
println!("Processing time: {:.2}s", elapsed.as_secs_f64());
|
|
println!();
|
|
|
|
// Print first 5 scenes with VLM status
|
|
println!("First 5 scenes:");
|
|
for scene in profile.scenes.iter().take(5) {
|
|
let vlm_desc = scene.vlm_description.as_deref().unwrap_or("N/A");
|
|
let vlm_status = match scene.vlm_status {
|
|
momentry_core::core::file_profile::VlmStatus::Pending => "pending",
|
|
momentry_core::core::file_profile::VlmStatus::Processing => "processing",
|
|
momentry_core::core::file_profile::VlmStatus::Completed => "completed",
|
|
momentry_core::core::file_profile::VlmStatus::Failed => "failed",
|
|
};
|
|
println!(
|
|
" {}: {}s (frame {}, blur={:.2}) [VLM: {}]",
|
|
scene.index,
|
|
scene.timestamp_sec,
|
|
scene.frame_number,
|
|
scene.quality_score.unwrap_or(0.0),
|
|
vlm_status
|
|
);
|
|
if scene.vlm_description.is_some() {
|
|
println!(
|
|
" Description: {}...",
|
|
&vlm_desc[..vlm_desc.len().min(80)]
|
|
);
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|