diff --git a/src/core/processor/pose.rs b/src/core/processor/pose.rs index 352207cc..e6fdf39b 100644 --- a/src/core/processor/pose.rs +++ b/src/core/processor/pose.rs @@ -189,10 +189,49 @@ pub async fn process_pose( return Ok(result); } tracing::warn!( - "[POSE] MOMENTRY_USE_RUST_PROCESSORS=1 but rust_pose binary not found, falling back to Python" + "[POSE] MOMENTRY_USE_RUST_PROCESSORS=1 but rust_pose binary not found, falling back to Swift" ); } + // Swift processor path (preferred over Python) + let swift_pose_path = std::path::Path::new( + "/Users/accusys/momentry_core/scripts/swift_processors/.build/release/swift_pose" + ); + + if swift_pose_path.exists() { + tracing::info!("[POSE] Using Swift processor: {:?}", swift_pose_path); + + let mut args = vec![video_path.to_string(), output_path.to_string()]; + if let Some(u) = uuid { + args.push("--uuid".to_string()); + args.push(u.to_string()); + } + + let output = tokio::process::Command::new(swift_pose_path) + .args(&args) + .output() + .await + .context("Failed to execute swift_pose")?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + tracing::error!("[POSE] Swift processor failed: {}", stderr); + anyhow::bail!("Swift pose processor failed"); + } + + let json_str = std::fs::read_to_string(output_path) + .context("Failed to read Swift POSE output")?; + let result: PoseResult = serde_json::from_str(&json_str) + .context("Failed to parse Swift POSE output")?; + tracing::info!( + "[POSE] Swift processor completed: {} frames", + result.frames.len() + ); + return Ok(result); + } + + tracing::info!("[POSE] Swift processor not found, falling back to Python"); + // Call Python pose_processor.py for interpolation let script_path = executor.script_path("pose_processor.py"); @@ -229,10 +268,76 @@ pub async fn process_pose( } let executor = PythonExecutor::new()?; - let script_path = executor.script_path("pose_processor.py"); tracing::info!("[POSE] Starting pose estimation: {}", video_path); + // Rust processor path (MOMENTRY_USE_RUST_PROCESSORS=1) + if *USE_RUST_PROCESSORS { + if let Some(rust_bin) = executor.rust_binary_path("rust_pose") { + tracing::info!("[POSE] Using Rust binary: {:?}", rust_bin); + executor + .run_rust_with_output_idx_and_frames( + &rust_bin, + &[video_path, output_path, output_path], + Some(2), + uuid, + None, + "POSE", + Some(POSE_TIMEOUT), + ) + .await + .with_context(|| format!("Failed to run Rust binary {:?}", rust_bin))?; + + let json_str = std::fs::read_to_string(output_path) + .context("Failed to read POSE output")?; + let result: PoseResult = serde_json::from_str(&json_str) + .context("Failed to parse POSE output")?; + tracing::info!("[POSE] Rust processor completed: {} frames", result.frames.len()); + return Ok(result); + } + tracing::warn!( + "[POSE] MOMENTRY_USE_RUST_PROCESSORS=1 but rust_pose binary not found, falling back to Swift" + ); + } + + // Swift processor path (preferred over Python) + let swift_pose_path = std::path::Path::new( + "/Users/accusys/momentry_core/scripts/swift_processors/.build/release/swift_pose" + ); + + if swift_pose_path.exists() { + tracing::info!("[POSE] Using Swift processor: {:?}", swift_pose_path); + + let mut args = vec![video_path.to_string(), output_path.to_string()]; + if let Some(u) = uuid { + args.push("--uuid".to_string()); + args.push(u.to_string()); + } + + let output = tokio::process::Command::new(swift_pose_path) + .args(&args) + .output() + .await + .context("Failed to execute swift_pose")?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + tracing::error!("[POSE] Swift processor failed: {}", stderr); + anyhow::bail!("Swift pose processor failed"); + } + + let json_str = std::fs::read_to_string(output_path) + .context("Failed to read Swift POSE output")?; + let result: PoseResult = serde_json::from_str(&json_str) + .context("Failed to parse Swift POSE output")?; + tracing::info!("[POSE] Swift processor completed: {} frames", result.frames.len()); + return Ok(result); + } + + tracing::info!("[POSE] Swift processor not found, falling back to Python"); + + let script_path = executor.script_path("pose_processor.py"); + if !script_path.exists() { tracing::warn!("[POSE] Script not found, returning empty result"); return Ok(PoseResult {