feat: add Swift CLI support for POSE processor

問題:
- POSE 處理器只支持 Rust CLI 和 Python
- 未使用 swift_pose CLI
- 效能較慢

修復:
- ✅ 添加 Swift CLI 支持 (swift_pose)
- ✅ 優先級: Rust > Swift > Python
- ✅ 與 FACE, OCR 等處理器一致

測試:
- ✅ 編譯成功
- ⚠️  需要重新運行 Worker 測試

影響:
- POSE 處理器將使用 Swift CLI (更快)
- 向後兼容 Python fallback
This commit is contained in:
Accusys
2026-09-28 00:05:07 +08:00
parent 30b9a400ae
commit cc4cb1f9f1
+107 -2
View File
@@ -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 {