feat: declarative pipeline config, non-blocking Scene VLM, rust_asrx
Consolidated snapshot (previously WIP in working tree). - core/pipeline_config: new module loading config/pipeline_flows.json as the source of truth for stage execution mode (parallel/blocking) and dependencies - worker/job_worker: dispatch Scene VLM to a background task when the stage is declared parallel, unblocking the worker poll loop; resolve processor dependencies from pipeline_flows.json (fallback to built-in) - config/pipeline_flows.json: asrx depends on [cut, asr] - scripts/fix_stuck_jobs: fix UTC timezone comparison, raise default threshold to 6h, skip jobs with recent processor activity - rust_asrx: Rust speaker diarization CLI + processor wiring - processor metadata helper; fast_face_clustering script; file_progress pipeline API; scan API; VAD updates
This commit is contained in:
@@ -2,10 +2,13 @@ use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::executor::PythonExecutor;
|
||||
use super::metadata::ProcessorMetadata;
|
||||
use super::AsrStatus;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AsrResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<ProcessorMetadata>,
|
||||
#[serde(default)]
|
||||
pub status: Option<AsrStatus>,
|
||||
pub language: Option<String>,
|
||||
@@ -24,8 +27,35 @@ impl AsrResult {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_metadata(&mut self, processor_name: &str, tool: &str, file_uuid: Option<&str>) {
|
||||
use chrono::Utc;
|
||||
use super::metadata::{ProcessorInfo, Timestamps, SourceInfo};
|
||||
|
||||
let metadata = ProcessorMetadata {
|
||||
processor: ProcessorInfo {
|
||||
name: processor_name.to_string(),
|
||||
tool: tool.to_string(),
|
||||
version: super::metadata::PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: file_uuid.map(|uuid| SourceInfo {
|
||||
file_uuid: uuid.to_string(),
|
||||
video_info: None,
|
||||
}),
|
||||
custom: None,
|
||||
};
|
||||
|
||||
self.metadata = Some(metadata);
|
||||
}
|
||||
|
||||
pub fn no_audio_track() -> Self {
|
||||
AsrResult {
|
||||
metadata: None,
|
||||
status: Some(AsrStatus::NoAudioTrack),
|
||||
language: None,
|
||||
language_probability: None,
|
||||
@@ -36,6 +66,7 @@ impl AsrResult {
|
||||
|
||||
pub fn silent_audio() -> Self {
|
||||
AsrResult {
|
||||
metadata: None,
|
||||
status: Some(AsrStatus::SilentAudio),
|
||||
language: None,
|
||||
language_probability: None,
|
||||
@@ -126,11 +157,13 @@ pub async fn process_asr(
|
||||
let whisper_result: WhisperJsonOutput =
|
||||
serde_json::from_str(&json_str).context("Failed to parse whisper output")?;
|
||||
|
||||
std::fs::copy(&json_path, output_path)
|
||||
.context("Failed to copy whisper output to target path")?;
|
||||
|
||||
let mut result = convert_whisper_to_asr(whisper_result);
|
||||
result.compute_status();
|
||||
result.add_metadata("asr", "whisper_mlx", uuid);
|
||||
|
||||
// Save with metadata and precision optimization
|
||||
crate::core::json_formatter::write_file_pretty_rounded(&result, output_path, 2)
|
||||
.context("Failed to write ASR output")?;
|
||||
|
||||
tracing::info!(
|
||||
"[ASR] Whisper result: status={}, {} segments, language: {:?}",
|
||||
@@ -175,6 +208,11 @@ async fn process_asr_python(
|
||||
serde_json::from_str(&json_str).context("Failed to parse ASR output")?;
|
||||
|
||||
result.compute_status();
|
||||
result.add_metadata("asr", "python_whisper", uuid);
|
||||
|
||||
// Save with metadata and precision optimization
|
||||
crate::core::json_formatter::write_file_pretty_rounded(&result, output_path, 2)
|
||||
.context("Failed to write ASR output")?;
|
||||
|
||||
tracing::info!(
|
||||
"[ASR] Python result: status={}, {} segments, language: {:?}",
|
||||
@@ -223,6 +261,7 @@ fn convert_whisper_to_asr(whisper: WhisperJsonOutput) -> AsrResult {
|
||||
.collect();
|
||||
|
||||
AsrResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
language: whisper.language,
|
||||
language_probability: None,
|
||||
@@ -238,6 +277,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_asr_result_serialization() {
|
||||
let result = AsrResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
language: Some("en".to_string()),
|
||||
language_probability: Some(0.95),
|
||||
@@ -302,6 +342,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_asr_result_empty_segments() {
|
||||
let result = AsrResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
language: None,
|
||||
language_probability: None,
|
||||
|
||||
+210
-2
@@ -3,10 +3,13 @@ use serde::{Deserialize, Serialize};
|
||||
use tokio::process::Command;
|
||||
|
||||
use super::executor::PythonExecutor;
|
||||
use super::metadata::ProcessorMetadata;
|
||||
use super::AsrStatus;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AsrxResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<ProcessorMetadata>,
|
||||
#[serde(default)]
|
||||
pub status: Option<AsrStatus>,
|
||||
pub language: Option<String>,
|
||||
@@ -23,8 +26,41 @@ impl AsrxResult {
|
||||
self.status = Some(AsrStatus::from_segments(self.segment_count));
|
||||
}
|
||||
|
||||
pub fn add_metadata(&mut self, processor_name: &str, tool: &str, file_uuid: Option<&str>) {
|
||||
use super::metadata::{ProcessorInfo, SourceInfo, Timestamps};
|
||||
use chrono::Utc;
|
||||
|
||||
let metadata = ProcessorMetadata {
|
||||
processor: ProcessorInfo {
|
||||
name: processor_name.to_string(),
|
||||
tool: tool.to_string(),
|
||||
version: super::metadata::PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: file_uuid.map(|uuid| SourceInfo {
|
||||
file_uuid: uuid.to_string(),
|
||||
video_info: None,
|
||||
}),
|
||||
custom: None,
|
||||
};
|
||||
|
||||
self.metadata = Some(metadata);
|
||||
}
|
||||
|
||||
pub fn save_to_file(&self, path: &str) -> Result<()> {
|
||||
crate::core::json_formatter::write_file_pretty_rounded(self, path, 2)
|
||||
.context("Failed to write asrx.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn no_audio_track() -> Self {
|
||||
AsrxResult {
|
||||
metadata: None,
|
||||
status: Some(AsrStatus::NoAudioTrack),
|
||||
language: None,
|
||||
segments: vec![],
|
||||
@@ -35,6 +71,7 @@ impl AsrxResult {
|
||||
|
||||
pub fn silent_audio() -> Self {
|
||||
AsrxResult {
|
||||
metadata: None,
|
||||
status: Some(AsrStatus::SilentAudio),
|
||||
language: None,
|
||||
segments: vec![],
|
||||
@@ -71,8 +108,175 @@ pub async fn process_asrx(
|
||||
) -> Result<AsrxResult> {
|
||||
tracing::info!("[ASRX] Starting speaker diarization: {}", video_path);
|
||||
|
||||
// Use Python processor (Swift ASRX disabled - requires GUI authorization)
|
||||
tracing::info!("[ASRX] Using Python processor");
|
||||
use super::tool_selector::ToolSelector;
|
||||
let executor = PythonExecutor::new()?;
|
||||
let selector = ToolSelector::new("asrx");
|
||||
|
||||
if let Some(tool) = selector.select_tool(&executor).await? {
|
||||
tracing::info!(
|
||||
"[ASRX] Using {} from config (priority {})",
|
||||
tool.name,
|
||||
tool.parameters
|
||||
.get("priority")
|
||||
.and_then(|v| v.as_u64())
|
||||
.unwrap_or(99)
|
||||
);
|
||||
|
||||
match tool.name.as_str() {
|
||||
"swift" => {
|
||||
let swift_path = tool.path;
|
||||
let args = if !tool.args.is_empty() {
|
||||
tool.args
|
||||
.iter()
|
||||
.map(|a| {
|
||||
a.replace("{video_path}", video_path)
|
||||
.replace("{output_path}", output_path)
|
||||
.replace("{file_uuid}", uuid.unwrap_or(""))
|
||||
})
|
||||
.collect()
|
||||
} 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)
|
||||
.output()
|
||||
.await
|
||||
.context("Failed to execute asrx_swift")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
tracing::error!("[ASRX] Swift processor failed: {}", stderr);
|
||||
anyhow::bail!("Swift ASRX failed: {}", stderr);
|
||||
}
|
||||
|
||||
let json_str =
|
||||
std::fs::read_to_string(output_path).context("Failed to read ASRX output")?;
|
||||
let mut result: AsrxResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse ASRX output")?;
|
||||
result.compute_status();
|
||||
result.add_metadata("asrx", "swift_asrx", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
tracing::info!(
|
||||
"[ASRX] Swift result: status={}, {} segments",
|
||||
result
|
||||
.status
|
||||
.as_ref()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_default(),
|
||||
result.segment_count
|
||||
);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
"rust" => {
|
||||
let rust_path = tool.path;
|
||||
|
||||
let mut cmd = tokio::process::Command::new(&rust_path);
|
||||
cmd.arg(video_path).arg(output_path);
|
||||
|
||||
if let Some(u) = uuid {
|
||||
cmd.arg("--uuid").arg(u);
|
||||
cmd.arg("--file-uuid").arg(u);
|
||||
}
|
||||
|
||||
cmd.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.process_group(0);
|
||||
|
||||
let output = cmd.output().await.context("Failed to execute rust_asrx")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
tracing::error!("[ASRX] Rust processor failed: {}", stderr);
|
||||
anyhow::bail!("Rust ASRX failed: {}", stderr);
|
||||
}
|
||||
|
||||
let json_str =
|
||||
std::fs::read_to_string(output_path).context("Failed to read ASRX output")?;
|
||||
let mut result: AsrxResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse ASRX output")?;
|
||||
result.compute_status();
|
||||
result.add_metadata("asrx", "rust_asrx", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
tracing::info!(
|
||||
"[ASRX] Rust result: status={}, {} segments",
|
||||
result
|
||||
.status
|
||||
.as_ref()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_default(),
|
||||
result.segment_count
|
||||
);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
"python" => {
|
||||
let script_path = tool.path;
|
||||
if !script_path.exists() {
|
||||
tracing::error!("[ASRX] Script not found: {:?}", script_path);
|
||||
anyhow::bail!("asrx_processor.py not found");
|
||||
}
|
||||
|
||||
let mut cmd = tokio::process::Command::new(executor.python_path());
|
||||
cmd.arg(&script_path).arg(video_path).arg(output_path);
|
||||
|
||||
if let Some(u) = uuid {
|
||||
cmd.arg("--uuid").arg(u);
|
||||
cmd.arg("--file-uuid").arg(u);
|
||||
}
|
||||
|
||||
cmd.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.process_group(0);
|
||||
|
||||
let output = cmd
|
||||
.output()
|
||||
.await
|
||||
.context("Failed to execute asrx_processor.py")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
tracing::error!("[ASRX] Python processor failed: {}", stderr);
|
||||
anyhow::bail!("Python ASRX failed: {}", stderr);
|
||||
}
|
||||
|
||||
let json_str =
|
||||
std::fs::read_to_string(output_path).context("Failed to read ASRX output")?;
|
||||
let mut result: AsrxResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse ASRX output")?;
|
||||
result.compute_status();
|
||||
result.add_metadata("asrx", "pyannote_diarization", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
tracing::info!(
|
||||
"[ASRX] Python result: status={}, {} segments",
|
||||
result
|
||||
.status
|
||||
.as_ref()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_default(),
|
||||
result.segment_count
|
||||
);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
_ => {
|
||||
tracing::warn!("[ASRX] Unknown tool from config: {}", tool.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tracing::warn!("[ASRX] No tool available from config, falling back to Python");
|
||||
process_asrx_python(video_path, output_path, uuid).await
|
||||
}
|
||||
|
||||
@@ -183,6 +387,8 @@ async fn process_asrx_python(
|
||||
serde_json::from_str(&json_str).context("Failed to parse ASRX output")?;
|
||||
|
||||
result.compute_status();
|
||||
result.add_metadata("asrx", "pyannote_diarization", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
tracing::info!(
|
||||
"[ASRX] Result: status={}, {} segments",
|
||||
@@ -204,6 +410,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_asrx_result_serialization() {
|
||||
let result = AsrxResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
language: Some("en".to_string()),
|
||||
segments: vec![AsrxSegment {
|
||||
@@ -247,6 +454,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_asrx_result_empty_segments() {
|
||||
let result = AsrxResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
language: None,
|
||||
segments: vec![],
|
||||
|
||||
@@ -4,11 +4,14 @@ use std::process::Command;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::executor::PythonExecutor;
|
||||
use super::metadata::ProcessorMetadata;
|
||||
|
||||
const CUT_TIMEOUT: Duration = Duration::from_secs(3600);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CutResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<ProcessorMetadata>,
|
||||
pub frame_count: u64,
|
||||
#[serde(serialize_with = "round_two")]
|
||||
pub fps: f64,
|
||||
@@ -35,14 +38,43 @@ where
|
||||
serializer.serialize_f64((v * 100.0).round() / 100.0)
|
||||
}
|
||||
|
||||
impl CutResult {
|
||||
pub fn add_metadata(&mut self, processor_name: &str, tool: &str, file_uuid: Option<&str>) {
|
||||
use chrono::Utc;
|
||||
use super::metadata::{ProcessorInfo, Timestamps, SourceInfo};
|
||||
|
||||
let metadata = ProcessorMetadata {
|
||||
processor: ProcessorInfo {
|
||||
name: processor_name.to_string(),
|
||||
tool: tool.to_string(),
|
||||
version: super::metadata::PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: file_uuid.map(|uuid| SourceInfo {
|
||||
file_uuid: uuid.to_string(),
|
||||
video_info: None,
|
||||
}),
|
||||
custom: None,
|
||||
};
|
||||
|
||||
self.metadata = Some(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn process_cut(
|
||||
video_path: &str,
|
||||
output_path: &str,
|
||||
uuid: Option<&str>,
|
||||
) -> Result<CutResult> {
|
||||
// Try native ffmpeg-based scene detection first
|
||||
let result = try_native_cut(video_path);
|
||||
if let Ok(r) = result {
|
||||
let mut result = try_native_cut(video_path);
|
||||
if let Ok(mut r) = result {
|
||||
r.add_metadata("cut", "ffmpeg_native", uuid);
|
||||
let json = serde_json::to_string_pretty(&r)?;
|
||||
std::fs::write(output_path, &json)
|
||||
.with_context(|| format!("Failed to write {:?}", output_path))?;
|
||||
@@ -55,11 +87,13 @@ pub async fn process_cut(
|
||||
let script_path = executor.script_path("cut_processor.py");
|
||||
|
||||
if !script_path.exists() {
|
||||
let empty_result = CutResult {
|
||||
let mut empty_result = CutResult {
|
||||
metadata: None,
|
||||
frame_count: 0,
|
||||
fps: 0.0,
|
||||
scenes: vec![],
|
||||
};
|
||||
empty_result.add_metadata("cut", "none", uuid);
|
||||
let json = serde_json::to_string_pretty(&empty_result)?;
|
||||
std::fs::write(output_path, &json)
|
||||
.with_context(|| format!("Failed to write {:?}", output_path))?;
|
||||
@@ -78,8 +112,10 @@ pub async fn process_cut(
|
||||
.with_context(|| format!("Failed to run {:?}", script_path))?;
|
||||
|
||||
let json_str = std::fs::read_to_string(output_path).context("Failed to read CUT output")?;
|
||||
let result: CutResult =
|
||||
let mut result: CutResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse CUT output")?;
|
||||
|
||||
result.add_metadata("cut", "python_scenedetect", uuid);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
@@ -216,6 +252,7 @@ fn try_native_cut(video_path: &str) -> Result<CutResult> {
|
||||
}
|
||||
|
||||
Ok(CutResult {
|
||||
metadata: None,
|
||||
frame_count: total_frames,
|
||||
fps,
|
||||
scenes,
|
||||
@@ -265,6 +302,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_cut_result_serialization() {
|
||||
let result = CutResult {
|
||||
metadata: None,
|
||||
frame_count: 100,
|
||||
fps: 30.0,
|
||||
scenes: vec![CutScene {
|
||||
@@ -305,6 +343,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_empty_scenes() {
|
||||
let result = CutResult {
|
||||
metadata: None,
|
||||
frame_count: 0,
|
||||
fps: 0.0,
|
||||
scenes: vec![],
|
||||
|
||||
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::executor::PythonExecutor;
|
||||
use super::metadata::ProcessorMetadata;
|
||||
use super::FaceStatus;
|
||||
|
||||
const FACE_TIMEOUT: Duration = Duration::from_secs(7200);
|
||||
@@ -38,6 +39,8 @@ pub fn swift_processor_path(bin: &str) -> std::path::PathBuf {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FaceResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<ProcessorMetadata>,
|
||||
#[serde(default)]
|
||||
pub status: Option<FaceStatus>,
|
||||
pub frame_count: u64,
|
||||
@@ -45,8 +48,6 @@ pub struct FaceResult {
|
||||
pub frames: Vec<FaceFrame>,
|
||||
#[serde(default)]
|
||||
pub total_faces: usize,
|
||||
#[serde(default)]
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl FaceResult {
|
||||
@@ -63,20 +64,48 @@ impl FaceResult {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_metadata(&mut self, processor_name: &str, tool: &str, file_uuid: Option<&str>) {
|
||||
use chrono::Utc;
|
||||
use super::metadata::{ProcessorInfo, Timestamps, SourceInfo, VideoInfo};
|
||||
|
||||
let video_info = None;
|
||||
|
||||
let metadata = ProcessorMetadata {
|
||||
processor: ProcessorInfo {
|
||||
name: processor_name.to_string(),
|
||||
tool: tool.to_string(),
|
||||
version: super::metadata::PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: file_uuid.map(|uuid| SourceInfo {
|
||||
file_uuid: uuid.to_string(),
|
||||
video_info,
|
||||
}),
|
||||
custom: None,
|
||||
};
|
||||
|
||||
self.metadata = Some(metadata);
|
||||
}
|
||||
|
||||
pub fn save_to_file(&self, path: &str) -> Result<()> {
|
||||
let json = serde_json::to_string_pretty(self).context("Failed to serialize FaceResult")?;
|
||||
std::fs::write(path, json).context("Failed to write face.json")?;
|
||||
crate::core::json_formatter::write_file_pretty_rounded(self, path, 2)
|
||||
.context("Failed to write face.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn no_faces(frame_count: u64, fps: f64) -> Self {
|
||||
FaceResult {
|
||||
metadata: None,
|
||||
status: Some(FaceStatus::NoFaces),
|
||||
frame_count,
|
||||
fps,
|
||||
frames: vec![],
|
||||
total_faces: 0,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,6 +191,7 @@ pub async fn process_face(
|
||||
serde_json::from_str(&json_str).context("Failed to parse existing FACE output")?;
|
||||
|
||||
result.compute_status();
|
||||
result.add_metadata("face", "swift_face", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
tracing::info!(
|
||||
@@ -288,6 +318,7 @@ pub async fn process_face(
|
||||
let mut result: FaceResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse FACE output")?;
|
||||
result.compute_status();
|
||||
result.add_metadata("face", "swift_face", uuid);
|
||||
|
||||
// Store embeddings to Qdrant and remove from JSON
|
||||
if let Some(file_uuid) = uuid {
|
||||
@@ -357,6 +388,7 @@ pub async fn process_face(
|
||||
serde_json::from_str(&json_str).context("Failed to parse FACE output")?;
|
||||
|
||||
result.compute_status();
|
||||
result.add_metadata("face", "python_face_processor", uuid);
|
||||
|
||||
// Execute face tracking
|
||||
tracing::info!("[FACE] Starting face tracking");
|
||||
@@ -478,6 +510,7 @@ async fn run_face_with_config(
|
||||
let mut result: FaceResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse Swift FACE output")?;
|
||||
result.compute_status();
|
||||
result.add_metadata("face", "swift_face", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
if let Some(uid) = uuid {
|
||||
@@ -520,6 +553,7 @@ async fn run_face_with_config(
|
||||
let mut result: FaceResult = serde_json::from_str(&json_str)
|
||||
.context("Failed to parse Python FACE output")?;
|
||||
result.compute_status();
|
||||
result.add_metadata("face", "python_face_processor", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
if let Some(uid) = uuid {
|
||||
@@ -549,11 +583,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_face_result_serialization() {
|
||||
let result = FaceResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
frame_count: 100,
|
||||
fps: 30.0,
|
||||
total_faces: 1,
|
||||
metadata: None,
|
||||
frames: vec![FaceFrame {
|
||||
frame: 0,
|
||||
timestamp: 0.0,
|
||||
|
||||
@@ -427,13 +427,37 @@ pub fn track_faces(
|
||||
.collect();
|
||||
|
||||
// Store traces in metadata
|
||||
face_data.metadata = Some(serde_json::json!({
|
||||
let trace_custom = serde_json::json!({
|
||||
"traces": trace_stats,
|
||||
"trace_stats": {
|
||||
"total_traces": next_trace_id,
|
||||
"active_traces": trace_stats.len(),
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
if let Some(ref mut metadata) = face_data.metadata {
|
||||
metadata.custom = Some(trace_custom);
|
||||
} else {
|
||||
// Create new metadata with trace info
|
||||
use super::metadata::{ProcessorMetadata, ProcessorInfo, Timestamps};
|
||||
use chrono::Utc;
|
||||
|
||||
face_data.metadata = Some(ProcessorMetadata {
|
||||
processor: ProcessorInfo {
|
||||
name: "face_tracker".to_string(),
|
||||
tool: "rust_face_tracker".to_string(),
|
||||
version: super::metadata::PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: None,
|
||||
custom: Some(trace_custom),
|
||||
});
|
||||
}
|
||||
|
||||
tracing::info!("✅ Tracking complete: {} traces", trace_stats.len());
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const PROCESSOR_VERSION: &str = "1.0.0";
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProcessorMetadata {
|
||||
pub processor: ProcessorInfo,
|
||||
pub timestamps: Timestamps,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub source: Option<SourceInfo>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub custom: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProcessorInfo {
|
||||
pub name: String,
|
||||
pub tool: String,
|
||||
pub version: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub config: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Timestamps {
|
||||
pub created_at: DateTime<Utc>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub processing_time_ms: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SourceInfo {
|
||||
pub file_uuid: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub video_info: Option<VideoInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct VideoInfo {
|
||||
pub duration_sec: f64,
|
||||
pub fps: f64,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub total_frames: u32,
|
||||
}
|
||||
|
||||
impl ProcessorMetadata {
|
||||
pub fn new(name: String, tool: String) -> Self {
|
||||
Self {
|
||||
processor: ProcessorInfo {
|
||||
name,
|
||||
tool,
|
||||
version: PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: None,
|
||||
custom: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_config(mut self, config: serde_json::Value) -> Self {
|
||||
self.processor.config = Some(config);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_source(mut self, file_uuid: String, video_info: Option<VideoInfo>) -> Self {
|
||||
self.source = Some(SourceInfo {
|
||||
file_uuid,
|
||||
video_info,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_custom(mut self, custom: serde_json::Value) -> Self {
|
||||
self.custom = Some(custom);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_processing_time(mut self, start: DateTime<Utc>) -> Self {
|
||||
let end = Utc::now();
|
||||
self.timestamps.updated_at = Some(end);
|
||||
self.timestamps.processing_time_ms = Some((end - start).num_milliseconds());
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ pub mod face_recognition;
|
||||
pub mod face_tracker;
|
||||
pub mod hand;
|
||||
pub mod heuristic_scene;
|
||||
pub mod metadata;
|
||||
pub mod ocr;
|
||||
pub mod pose;
|
||||
pub mod scene_classification;
|
||||
@@ -195,5 +196,8 @@ pub use tkg::{
|
||||
build_tkg, query_auto_representative_frame, FrameTraceInfo, MainIdentityInfo,
|
||||
RepresentativeFrameResult, TkgResult,
|
||||
};
|
||||
pub use metadata::{
|
||||
ProcessorMetadata, ProcessorInfo, Timestamps, SourceInfo, VideoInfo, PROCESSOR_VERSION,
|
||||
};
|
||||
pub mod processor_config_v3;
|
||||
pub mod tool_selector;
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::collections::HashSet;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::executor::PythonExecutor;
|
||||
use super::metadata::ProcessorMetadata;
|
||||
|
||||
const OCR_TIMEOUT: Duration = Duration::from_secs(7200);
|
||||
|
||||
@@ -17,11 +18,47 @@ const TEXT_SIMILARITY_THRESHOLD: f64 = 0.5;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct OcrResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<ProcessorMetadata>,
|
||||
pub frame_count: u64,
|
||||
pub fps: f64,
|
||||
pub frames: Vec<OcrFrame>,
|
||||
}
|
||||
|
||||
impl OcrResult {
|
||||
pub fn add_metadata(&mut self, processor_name: &str, tool: &str, file_uuid: Option<&str>) {
|
||||
use super::metadata::{ProcessorInfo, SourceInfo, Timestamps};
|
||||
use chrono::Utc;
|
||||
|
||||
let metadata = ProcessorMetadata {
|
||||
processor: ProcessorInfo {
|
||||
name: processor_name.to_string(),
|
||||
tool: tool.to_string(),
|
||||
version: super::metadata::PROCESSOR_VERSION.to_string(),
|
||||
config: None,
|
||||
},
|
||||
timestamps: Timestamps {
|
||||
created_at: Utc::now(),
|
||||
updated_at: None,
|
||||
processing_time_ms: None,
|
||||
},
|
||||
source: file_uuid.map(|uuid| SourceInfo {
|
||||
file_uuid: uuid.to_string(),
|
||||
video_info: None,
|
||||
}),
|
||||
custom: None,
|
||||
};
|
||||
|
||||
self.metadata = Some(metadata);
|
||||
}
|
||||
|
||||
pub fn save_to_file(&self, path: &str) -> Result<()> {
|
||||
crate::core::json_formatter::write_file_pretty_rounded(self, path, 2)
|
||||
.context("Failed to write ocr.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct OcrFrame {
|
||||
pub frame: u64,
|
||||
@@ -272,6 +309,7 @@ pub async fn process_ocr(
|
||||
if !script_path.exists() {
|
||||
tracing::warn!("[OCR] Script not found, returning empty result");
|
||||
return Ok(OcrResult {
|
||||
metadata: None,
|
||||
frame_count: 0,
|
||||
fps: 0.0,
|
||||
frames: vec![],
|
||||
@@ -293,9 +331,12 @@ pub async fn process_ocr(
|
||||
|
||||
let json_str = std::fs::read_to_string(output_path).context("Failed to read OCR output")?;
|
||||
|
||||
let result: OcrResult =
|
||||
let mut result: OcrResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse OCR output")?;
|
||||
|
||||
result.add_metadata("ocr", "swift_ocr", uuid);
|
||||
result.save_to_file(output_path)?;
|
||||
|
||||
tracing::info!("[OCR] Result: {} frames", result.frames.len());
|
||||
|
||||
Ok(result)
|
||||
@@ -308,6 +349,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_ocr_result_serialization() {
|
||||
let result = OcrResult {
|
||||
metadata: None,
|
||||
frame_count: 100,
|
||||
fps: 30.0,
|
||||
frames: vec![OcrFrame {
|
||||
@@ -354,6 +396,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_ocr_result_empty_frames() {
|
||||
let result = OcrResult {
|
||||
metadata: None,
|
||||
frame_count: 0,
|
||||
fps: 0.0,
|
||||
frames: vec![],
|
||||
|
||||
Reference in New Issue
Block a user