From cd0eff17682c794afa55ce929f893ec00ff24e32 Mon Sep 17 00:00:00 2001 From: Accusys Date: Mon, 28 Sep 2026 11:25:03 +0800 Subject: [PATCH] feat: update pose and face processors to use tool.args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改進: - pose.rs: Rust 和 Swift 支持 tool.args - face.rs: Swift 支持 tool.args 邏輯: - 如果 tool.args 不為空,使用配置中的 args - 否則,使用舊的手動構建方式(向後兼容) 優勢: - 參數配置化(從 config 讀取) - 減少硬編碼 - 支持 V3 配置變量替換 示例: - V3 config: args = ["--video", "{video_path}", "--output", "{output_path}"] - 變量替換: {video_path} → /path/to/video.mp4 - 最終 args: ["--video", "/path/to/video.mp4", "--output", "/path/to/output.json"] 下一步: - 測試完整流程 - 驗證 V3 配置工作 --- src/core/processor/face.rs | 16 +++++++---- src/core/processor/pose.rs | 56 ++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/core/processor/face.rs b/src/core/processor/face.rs index 98d9ac52..935a3dc8 100644 --- a/src/core/processor/face.rs +++ b/src/core/processor/face.rs @@ -358,11 +358,17 @@ async fn run_face_with_config( let swift_path = &tool.path; tracing::info!("[FACE] Using Swift processor from config: {:?}", swift_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 args = if !tool.args.is_empty() { + tracing::info!("[FACE] Using args from config: {:?}", tool.args); + tool.args.clone() + } else { + 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()); + } + args + }; let output = tokio::process::Command::new(swift_path) .args(&args) diff --git a/src/core/processor/pose.rs b/src/core/processor/pose.rs index cb36c0c5..6e46e22c 100644 --- a/src/core/processor/pose.rs +++ b/src/core/processor/pose.rs @@ -524,11 +524,17 @@ async fn run_pose_with_config( let swift_path = &tool.path; tracing::info!("[POSE] Using Swift processor from config: {:?}", swift_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 args = if !tool.args.is_empty() { + tracing::info!("[POSE] Using args from config: {:?}", tool.args); + tool.args.clone() + } else { + 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()); + } + args + }; let output = tokio::process::Command::new(swift_path) .args(&args) @@ -553,18 +559,34 @@ async fn run_pose_with_config( let rust_path = &tool.path; tracing::info!("[POSE] Using Rust processor from config: {:?}", rust_path); - executor - .run_rust_with_output_idx_and_frames( - rust_path, - &[video_path, output_path, output_path], - Some(2), - uuid, - None, - "POSE", - Some(POSE_TIMEOUT), - ) - .await - .with_context(|| format!("Failed to run Rust binary {:?}", rust_path))?; + if !tool.args.is_empty() { + tracing::info!("[POSE] Using args from config: {:?}", tool.args); + + let output = tokio::process::Command::new(rust_path) + .args(&tool.args) + .output() + .await + .context("Failed to execute rust_pose")?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + tracing::error!("[POSE] Rust processor failed: {}", stderr); + anyhow::bail!("Rust pose processor failed"); + } + } else { + executor + .run_rust_with_output_idx_and_frames( + rust_path, + &[video_path, output_path, output_path], + Some(2), + uuid, + None, + "POSE", + Some(POSE_TIMEOUT), + ) + .await + .with_context(|| format!("Failed to run Rust binary {:?}", rust_path))?; + } let json_str = std::fs::read_to_string(output_path) .context("Failed to read POSE output")?;