feat: asrx recovery + pipeline fixes + face trace improvements
- ASR-ASRX unified processor (asr_asrx → asrx), output .asrx.json - ffmpeg -vsync → -fps_mode (swift_ocr, swift_hand, swift_pose, frame_cache) - ffprobe absolute path for probe - PYTHONPATH + PATH added to executor subprocesses - cut processor path fix (cut/cut_processor.py) - scene_vlm fallback when blur_scores empty + ffmpeg absolute path - rust_store_traced_faces generates key_face.jpg with --video-path - face group representative trace picks highest best_confidence - Studio: move FS doesn't remove from unassigned, always reload after move - Studio: confirmMoveFaceToNewGroup simplified to just rename - Studio: scene_vlm added to processors list - Studio: scene_vlm shows (0) when ready but no scenes - admin_config asr_config block added
This commit is contained in:
+1
-1
@@ -1279,7 +1279,7 @@ struct ReScanRequest {
|
||||
processors: Option<Vec<String>>,
|
||||
#[serde(default)]
|
||||
face_settings: Option<FaceSettings>,
|
||||
#[serde(default)]
|
||||
#[serde(default, alias = "autoPipeline")]
|
||||
auto_pipeline: Option<bool>,
|
||||
#[serde(default)]
|
||||
trigger_source: Option<String>,
|
||||
|
||||
+68
-12
@@ -1346,6 +1346,7 @@ pub async fn get_face_groups_handler(
|
||||
Path(file_uuid): Path<String>,
|
||||
Query(q): Query<FaceGroupsQuery>,
|
||||
) -> Result<Json<FaceGroupsResponse>, StatusCode> {
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let tkg_table = schema::table_name("tkg_nodes");
|
||||
let tp_table = schema::table_name("trace_profiles");
|
||||
let v_table = schema::table_name("videos");
|
||||
@@ -1422,20 +1423,48 @@ pub async fn get_face_groups_handler(
|
||||
|
||||
let include_trace_ids = q.include_trace_ids.unwrap_or(true);
|
||||
|
||||
// Load best_confidence per trace from face_traced.json
|
||||
let mut trace_best_conf: std::collections::HashMap<i32, f64> = std::collections::HashMap::new();
|
||||
let traced_path = format!("{}/{}.face_traced.json", output_dir.trim_end_matches('/'), file_uuid);
|
||||
if let Ok(content) = std::fs::read_to_string(&traced_path) {
|
||||
if let Ok(traced) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
if let Some(traces) = traced.get("traces").and_then(|v| v.as_array()) {
|
||||
for t in traces {
|
||||
if let (Some(tid), Some(conf)) = (
|
||||
t.get("trace_id").and_then(|v| v.as_i64()),
|
||||
t.get("best_confidence").or(t.get("avg_confidence")).and_then(|v| v.as_f64()),
|
||||
) {
|
||||
trace_best_conf.insert(tid as i32, conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let face_groups: Vec<FaceGroup> = filtered_groups
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, (name, trace_ids))| FaceGroup {
|
||||
group_id: (idx + 1) as i32,
|
||||
name,
|
||||
trace_count: trace_ids.len() as i32,
|
||||
representative_trace: trace_ids.first().copied().unwrap_or(0),
|
||||
trace_ids: if include_trace_ids {
|
||||
Some(trace_ids)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
editable: true,
|
||||
.map(|(idx, (name, trace_ids))| {
|
||||
// Pick representative trace: highest best_confidence among group traces
|
||||
let rep_trace = trace_ids.iter()
|
||||
.filter_map(|tid| trace_best_conf.get(tid).map(|c| (tid, c)))
|
||||
.max_by(|a, b| a.1.partial_cmp(b.1).unwrap_or(std::cmp::Ordering::Equal))
|
||||
.map(|(tid, _)| *tid)
|
||||
.or_else(|| trace_ids.first().copied())
|
||||
.unwrap_or(0);
|
||||
|
||||
FaceGroup {
|
||||
group_id: (idx + 1) as i32,
|
||||
name,
|
||||
trace_count: trace_ids.len() as i32,
|
||||
representative_trace: rep_trace,
|
||||
trace_ids: if include_trace_ids {
|
||||
Some(trace_ids)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
editable: true,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -1654,6 +1683,28 @@ pub async fn get_cluster_results_handler(
|
||||
map
|
||||
};
|
||||
|
||||
// Load best_confidence per trace from face_traced.json (for representative selection)
|
||||
let cluster_trace_conf: HashMap<i32, f64> = {
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let mut map = HashMap::new();
|
||||
let traced_path = format!("{}/{}.face_traced.json", output_dir, file_uuid);
|
||||
if let Ok(content) = std::fs::read_to_string(&traced_path) {
|
||||
if let Ok(traced) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
if let Some(traces) = traced.get("traces").and_then(|v| v.as_array()) {
|
||||
for t in traces {
|
||||
if let (Some(tid), Some(conf)) = (
|
||||
t.get("trace_id").and_then(|v| v.as_i64()),
|
||||
t.get("best_confidence").or(t.get("avg_confidence")).and_then(|v| v.as_f64()),
|
||||
) {
|
||||
map.insert(tid as i32, conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
map
|
||||
};
|
||||
|
||||
// Build trace_id -> name mapping before consuming filtered_groups
|
||||
let trace_to_name: HashMap<i32, String> = filtered_groups
|
||||
.iter()
|
||||
@@ -1672,7 +1723,12 @@ pub async fn get_cluster_results_handler(
|
||||
cluster_id: group_id,
|
||||
name,
|
||||
trace_count: trace_ids.len() as i32,
|
||||
representative_trace: trace_ids.first().copied().unwrap_or(0),
|
||||
representative_trace: trace_ids.iter()
|
||||
.filter_map(|tid| cluster_trace_conf.get(tid).map(|c| (tid, c)))
|
||||
.max_by(|a, b| a.1.partial_cmp(b.1).unwrap_or(std::cmp::Ordering::Equal))
|
||||
.map(|(tid, _)| *tid)
|
||||
.or_else(|| trace_ids.first().copied())
|
||||
.unwrap_or(0),
|
||||
trace_ids,
|
||||
similarity,
|
||||
}
|
||||
|
||||
@@ -150,10 +150,10 @@ async fn fetch_asr_segments(
|
||||
) -> Result<Vec<AsrSegment>> {
|
||||
let query = format!(
|
||||
r#"
|
||||
SELECT
|
||||
SELECT
|
||||
start_frame, end_frame, start_time, end_time, data
|
||||
FROM {}
|
||||
WHERE file_uuid = $1 AND processor_type = 'asrx'
|
||||
WHERE file_uuid = $1 AND processor_type IN ('asrx', 'asr', 'asr_asrx')
|
||||
ORDER BY start_frame
|
||||
"#,
|
||||
table
|
||||
|
||||
@@ -550,6 +550,7 @@ pub enum PipelineType {
|
||||
pub enum ProcessorType {
|
||||
Cut,
|
||||
Asr,
|
||||
AsrAsrx,
|
||||
Ocr,
|
||||
Face,
|
||||
Pose,
|
||||
@@ -588,11 +589,14 @@ impl ProcessorType {
|
||||
match self {
|
||||
ProcessorType::Cut => "cut",
|
||||
ProcessorType::Asr => "asr",
|
||||
// Unified ASR+diarization processor writes {uuid}.asrx.json and is
|
||||
// exposed to the UI/queue under the legacy "asrx" name.
|
||||
ProcessorType::AsrAsrx => "asrx",
|
||||
ProcessorType::Ocr => "ocr",
|
||||
ProcessorType::Face => "face",
|
||||
ProcessorType::Pose => "pose",
|
||||
ProcessorType::Hand => "hand",
|
||||
ProcessorType::Asrx => "asrx",
|
||||
ProcessorType::Asrx => "asrx_legacy",
|
||||
ProcessorType::Scene => "scene_vlm",
|
||||
ProcessorType::Appearance => "appearance",
|
||||
ProcessorType::FaceCluster => "face_cluster",
|
||||
@@ -605,11 +609,12 @@ impl ProcessorType {
|
||||
match s {
|
||||
"cut" => Some(ProcessorType::Cut),
|
||||
"asr" => Some(ProcessorType::Asr),
|
||||
"asrx" | "asr_asrx" => Some(ProcessorType::AsrAsrx),
|
||||
"asrx_legacy" => Some(ProcessorType::Asrx),
|
||||
"ocr" => Some(ProcessorType::Ocr),
|
||||
"face" => Some(ProcessorType::Face),
|
||||
"pose" => Some(ProcessorType::Pose),
|
||||
"hand" => Some(ProcessorType::Hand),
|
||||
"asrx" => Some(ProcessorType::Asrx),
|
||||
"scene" => Some(ProcessorType::Scene),
|
||||
"scene_vlm" => Some(ProcessorType::Scene), // Alias for scene
|
||||
"appearance" => Some(ProcessorType::Appearance),
|
||||
@@ -624,6 +629,7 @@ impl ProcessorType {
|
||||
match self {
|
||||
ProcessorType::Cut => 0.5,
|
||||
ProcessorType::Asr => 0.5,
|
||||
ProcessorType::AsrAsrx => 1.2,
|
||||
ProcessorType::Ocr => 0.8,
|
||||
ProcessorType::Face => 0.6,
|
||||
ProcessorType::Pose => 0.4,
|
||||
@@ -648,6 +654,7 @@ impl ProcessorType {
|
||||
match self {
|
||||
ProcessorType::Cut => 512,
|
||||
ProcessorType::Asr => 1024,
|
||||
ProcessorType::AsrAsrx => 2048,
|
||||
ProcessorType::Ocr => 1024,
|
||||
ProcessorType::Face => 1536,
|
||||
ProcessorType::Pose => 1024,
|
||||
@@ -665,6 +672,7 @@ impl ProcessorType {
|
||||
match self {
|
||||
ProcessorType::Cut => None,
|
||||
ProcessorType::Asr => Some("whisper-small"),
|
||||
ProcessorType::AsrAsrx => Some("whisper-small-mlx"),
|
||||
ProcessorType::Ocr => Some("paddleocr"),
|
||||
ProcessorType::Face => Some("insightface/buffalo_l"),
|
||||
ProcessorType::Pose => Some("mediapipe/pose"),
|
||||
@@ -680,6 +688,7 @@ impl ProcessorType {
|
||||
|
||||
pub fn dependencies(&self) -> Vec<ProcessorType> {
|
||||
match self {
|
||||
ProcessorType::AsrAsrx => vec![ProcessorType::Cut],
|
||||
ProcessorType::Asrx => vec![ProcessorType::Cut, ProcessorType::Asr],
|
||||
ProcessorType::Scene => vec![ProcessorType::Cut],
|
||||
ProcessorType::Pose => vec![ProcessorType::Face],
|
||||
@@ -694,8 +703,9 @@ impl ProcessorType {
|
||||
pub fn all() -> Vec<ProcessorType> {
|
||||
vec![
|
||||
ProcessorType::Cut,
|
||||
ProcessorType::Asr,
|
||||
ProcessorType::Asrx,
|
||||
// Unified ASR+diarization (rust_asr_asrx). Legacy Asr/Asrx are no
|
||||
// longer offered: "asrx" now resolves to AsrAsrx via from_db_str.
|
||||
ProcessorType::AsrAsrx,
|
||||
ProcessorType::Ocr,
|
||||
ProcessorType::Face,
|
||||
ProcessorType::FaceTrace,
|
||||
@@ -721,6 +731,7 @@ impl ProcessorType {
|
||||
|
||||
ProcessorType::Cut
|
||||
| ProcessorType::Asr
|
||||
| ProcessorType::AsrAsrx
|
||||
| ProcessorType::Asrx
|
||||
| ProcessorType::Scene => PipelineType::Time,
|
||||
}
|
||||
@@ -2496,6 +2507,7 @@ impl PostgresDb {
|
||||
SELECT id FROM {}
|
||||
WHERE status = 'pending'
|
||||
AND queue_name = 'internal.file'
|
||||
AND command_type IN ('register', 'unregister')
|
||||
ORDER BY priority ASC, created_at ASC
|
||||
FOR UPDATE SKIP LOCKED LIMIT $1
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ impl FrameManager {
|
||||
&video_path,
|
||||
"-vf",
|
||||
&format!("select=not(mod(n\\,{})),scale=320:-2", sample_interval),
|
||||
"-vsync",
|
||||
"-fps_mode",
|
||||
"vfr",
|
||||
"-q:v",
|
||||
"15",
|
||||
|
||||
@@ -164,7 +164,7 @@ impl PipelineFlows {
|
||||
for stage in stages.iter().filter(|s| s.enabled) {
|
||||
// Map stage names to processor names
|
||||
let mapped = match stage.name.as_str() {
|
||||
"asr_asrx" => vec!["asr".to_string(), "asrx".to_string()],
|
||||
"asr_asrx" => vec!["asrx".to_string()],
|
||||
"scene_vlm" => vec!["scene_vlm".to_string()],
|
||||
"tkg" => vec!["tkg".to_string()],
|
||||
other => vec![other.to_string()],
|
||||
|
||||
@@ -34,8 +34,8 @@ pub struct FormatInfo {
|
||||
}
|
||||
|
||||
pub fn probe_video(video_path: &str) -> Result<ProbeResult> {
|
||||
// Use FFPROBE_PATH environment variable, fallback to "ffprobe"
|
||||
let ffprobe_path = std::env::var("FFPROBE_PATH").unwrap_or_else(|_| "ffprobe".to_string());
|
||||
// Use FFPROBE_PATH environment variable, fallback to absolute path on Apple Silicon
|
||||
let ffprobe_path = std::env::var("FFPROBE_PATH").unwrap_or_else(|_| "/opt/homebrew/bin/ffprobe".to_string());
|
||||
|
||||
let output = Command::new(&ffprobe_path)
|
||||
.args([
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AsrAsrxSegment {
|
||||
pub id: usize,
|
||||
pub start: f64,
|
||||
pub end: f64,
|
||||
pub text: String,
|
||||
pub speaker_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AsrAsrxResult {
|
||||
pub language: String,
|
||||
pub segments: Vec<AsrAsrxSegment>,
|
||||
pub recovery: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
pub async fn process_asr_asrx(
|
||||
video_path: &str,
|
||||
output_path: &str,
|
||||
uuid: Option<&str>,
|
||||
) -> Result<AsrAsrxResult> {
|
||||
let binary = "tools/cli/rust/target/release/rust_asr_asrx";
|
||||
let model = "/Users/accusys/models/whisper-small-mlx";
|
||||
|
||||
let mut cmd = Command::new(binary);
|
||||
cmd.env("PATH", "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin");
|
||||
cmd.args([
|
||||
"--input", video_path,
|
||||
"--output", output_path,
|
||||
"--model", model,
|
||||
]);
|
||||
cmd.arg("--diarize");
|
||||
if let Some(u) = uuid {
|
||||
cmd.env("FILE_UUID", u);
|
||||
}
|
||||
|
||||
let output = cmd.output().context("Failed to run rust_asr_asrx")?;
|
||||
if !output.status.success() {
|
||||
anyhow::bail!(
|
||||
"rust_asr_asrx failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
let json_path = output_path;
|
||||
if !Path::new(json_path).exists() {
|
||||
anyhow::bail!("rust_asr_asrx output not found: {}", json_path);
|
||||
}
|
||||
|
||||
let content = std::fs::read_to_string(json_path)
|
||||
.context("Failed to read asr_asrx output")?;
|
||||
let json: serde_json::Value = serde_json::from_str(&content)
|
||||
.context("Failed to parse asr_asrx output")?;
|
||||
|
||||
let language = json["language"].as_str().unwrap_or("unknown").to_string();
|
||||
let recovery = json.get("recovery").cloned();
|
||||
|
||||
let segments: Vec<AsrAsrxSegment> = json["segments"]
|
||||
.as_array()
|
||||
.map(|arr| {
|
||||
arr.iter()
|
||||
.enumerate()
|
||||
.map(|(i, s)| AsrAsrxSegment {
|
||||
id: s["id"].as_u64().unwrap_or(i as u64) as usize,
|
||||
start: s["start"].as_f64().unwrap_or(0.0),
|
||||
end: s["end"].as_f64().unwrap_or(0.0),
|
||||
text: s["text"].as_str().unwrap_or("").to_string(),
|
||||
speaker_id: s["speaker_id"].as_str().map(|s| s.to_string()),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(AsrAsrxResult {
|
||||
language,
|
||||
segments,
|
||||
recovery,
|
||||
})
|
||||
}
|
||||
@@ -84,7 +84,7 @@ pub async fn process_cut(
|
||||
// Fallback: Python scenedetect
|
||||
tracing::warn!("[CUT] Native impl failed, falling back to Python");
|
||||
let executor = PythonExecutor::new()?;
|
||||
let script_path = executor.script_path("cut_processor.py");
|
||||
let script_path = executor.script_path("cut/cut_processor.py");
|
||||
|
||||
if !script_path.exists() {
|
||||
let mut empty_result = CutResult {
|
||||
@@ -102,7 +102,7 @@ pub async fn process_cut(
|
||||
|
||||
executor
|
||||
.run(
|
||||
"cut_processor.py",
|
||||
"cut/cut_processor.py",
|
||||
&[video_path, output_path],
|
||||
uuid,
|
||||
"CUT",
|
||||
|
||||
@@ -333,6 +333,8 @@ impl PythonExecutor {
|
||||
});
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("PYTHONPATH", &self.scripts_dir);
|
||||
cmd.env("PATH", "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin");
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
cmd.env("DATABASE_SCHEMA", &*DATABASE_SCHEMA);
|
||||
cmd.env("MOMENTRY_DB_SCHEMA", &*DATABASE_SCHEMA);
|
||||
@@ -503,6 +505,8 @@ impl PythonExecutor {
|
||||
});
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("PYTHONPATH", &self.scripts_dir);
|
||||
cmd.env("PATH", "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin");
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
cmd.env("DATABASE_SCHEMA", &*DATABASE_SCHEMA);
|
||||
cmd.env("MOMENTRY_DB_SCHEMA", &*DATABASE_SCHEMA);
|
||||
@@ -717,6 +721,8 @@ impl PythonExecutor {
|
||||
});
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("PYTHONPATH", &self.scripts_dir);
|
||||
cmd.env("PATH", "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin");
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
cmd.env("DATABASE_SCHEMA", &*DATABASE_SCHEMA);
|
||||
cmd.env("MOMENTRY_DB_SCHEMA", &*DATABASE_SCHEMA);
|
||||
@@ -939,6 +945,8 @@ impl PythonExecutor {
|
||||
});
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("PYTHONPATH", &self.scripts_dir);
|
||||
cmd.env("PATH", "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin");
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
cmd.env("DATABASE_SCHEMA", &*DATABASE_SCHEMA);
|
||||
cmd.env("MOMENTRY_DB_SCHEMA", &*DATABASE_SCHEMA);
|
||||
|
||||
@@ -862,8 +862,13 @@ pub async fn store_face_embeddings_to_qdrant(
|
||||
|
||||
tracing::info!("[FACE] Stored {} embeddings to Qdrant", total_points);
|
||||
|
||||
// Keep embeddings in JSON (JSON is source of truth)
|
||||
// No longer remove embeddings from JSON
|
||||
// Remove embeddings from JSON to keep file size manageable
|
||||
// Vectors are stored in Qdrant, JSON only keeps metadata
|
||||
for frame in &mut face_result.frames {
|
||||
for face in &mut frame.faces {
|
||||
face.embedding = None;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(total_points)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod appearance;
|
||||
pub mod asr;
|
||||
pub mod asr_asrx;
|
||||
pub mod asrx;
|
||||
pub mod caption;
|
||||
pub mod cascade_vision;
|
||||
@@ -162,6 +163,7 @@ pub use appearance::{
|
||||
process_appearance, AppearanceFrame, AppearancePerson, AppearanceResult, BBox, BodyPart,
|
||||
};
|
||||
pub use asr::{process_asr, AsrResult, AsrSegment};
|
||||
pub use asr_asrx::{process_asr_asrx, AsrAsrxResult, AsrAsrxSegment};
|
||||
pub use asrx::{process_asrx, AsrxResult, AsrxSegment};
|
||||
pub use caption::{process_caption, CaptionResult, CaptionSummary, FrameCaption};
|
||||
pub use cascade_vision::{CascadeDetectionResult, CascadeVisionProcessor};
|
||||
|
||||
@@ -30,20 +30,32 @@ impl SceneVlmProcessor {
|
||||
fps: f64,
|
||||
samples: usize,
|
||||
) -> Vec<u32> {
|
||||
if samples == 0 {
|
||||
return vec![];
|
||||
}
|
||||
let sample_interval = interval_sec / samples as f64;
|
||||
|
||||
(0..samples)
|
||||
let frames: Vec<u32> = (0..samples)
|
||||
.map(|i| {
|
||||
let time = interval_start_sec + (i as f64 + 0.5) * sample_interval;
|
||||
(time * fps).round() as u32
|
||||
})
|
||||
.collect()
|
||||
.collect();
|
||||
|
||||
// Ensure at least frame 0 is included for short videos
|
||||
if frames.is_empty() || frames.iter().all(|&f| f > 0) {
|
||||
let mut result = vec![0u32];
|
||||
result.extend(frames.into_iter().filter(|&f| f > 0));
|
||||
result
|
||||
} else {
|
||||
frames
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn calculate_blur_single(video_path: &str, frame: u32, fps: f64) -> Result<f64> {
|
||||
let time_sec = frame as f64 / fps;
|
||||
|
||||
let output = Command::new("ffmpeg")
|
||||
let output = Command::new("/opt/homebrew/bin/ffmpeg")
|
||||
.args([
|
||||
"-ss",
|
||||
&format!("{:.2}", time_sec),
|
||||
@@ -173,6 +185,32 @@ impl SceneVlmProcessor {
|
||||
vlm_tags: Vec::new(),
|
||||
embedding_status: EmbeddingStatus::Pending,
|
||||
});
|
||||
} else if let Some(&frame) = sample_frames.first() {
|
||||
// Fallback: use first sample frame when blur detection yields no scores
|
||||
let timestamp = frame as f64 / fps;
|
||||
selected_frames.push(SceneFrame {
|
||||
index: 0,
|
||||
filename: format!("scene_{:03}.jpg", 0),
|
||||
timestamp_sec: timestamp,
|
||||
frame_number: frame,
|
||||
selection_reason: SelectionReason::Default,
|
||||
quality_score: None,
|
||||
quality_source: None,
|
||||
scene_info: None,
|
||||
face_count: 0,
|
||||
person_traces: Vec::new(),
|
||||
has_cut: false,
|
||||
cut_count: 0,
|
||||
vlm_status: VlmStatus::Pending,
|
||||
vlm_description: None,
|
||||
vlm_description_localized: None,
|
||||
vlm_scene_type: None,
|
||||
vlm_location: None,
|
||||
vlm_objects: Vec::new(),
|
||||
vlm_attributes: None,
|
||||
vlm_tags: Vec::new(),
|
||||
embedding_status: EmbeddingStatus::Pending,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let cut = &cuts[0];
|
||||
@@ -376,7 +414,7 @@ impl SceneVlmProcessor {
|
||||
|
||||
let time_sec = scene.timestamp_sec;
|
||||
|
||||
let status = Command::new("ffmpeg")
|
||||
let status = Command::new("/opt/homebrew/bin/ffmpeg")
|
||||
.args([
|
||||
"-y",
|
||||
"-ss",
|
||||
|
||||
@@ -2135,7 +2135,7 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
let tkg_edges_t = schema::table_name("tkg_edges");
|
||||
|
||||
let has_asr_or_asrx =
|
||||
job_processors.is_empty() || job_processors.iter().any(|p| p == "asrx" || p == "asr");
|
||||
job_processors.is_empty() || job_processors.iter().any(|p| p == "asrx" || p == "asr" || p == "asr_asrx");
|
||||
let has_face = job_processors.is_empty() || job_processors.iter().any(|p| p == "face");
|
||||
let has_cut = job_processors.is_empty() || job_processors.iter().any(|p| p == "cut");
|
||||
|
||||
@@ -2147,6 +2147,9 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
UNION ALL \
|
||||
SELECT asr_status FROM {pr_t} pr JOIN {mj_t} mj ON pr.job_id = mj.id \
|
||||
WHERE mj.uuid = $1 AND pr.processor = 'asr' AND asr_status IS NOT NULL \
|
||||
UNION ALL \
|
||||
SELECT asr_status FROM {pr_t} pr JOIN {mj_t} mj ON pr.job_id = mj.id \
|
||||
WHERE mj.uuid = $1 AND pr.processor = 'asr_asrx' AND asr_status IS NOT NULL \
|
||||
LIMIT 1",
|
||||
mj_t = schema::table_name("monitor_jobs")
|
||||
))
|
||||
@@ -2172,7 +2175,7 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
if status_from_db {
|
||||
true
|
||||
} else {
|
||||
// Fallback: check asr.json file directly
|
||||
// Fallback: check asr.json / asr_asrx.json file directly
|
||||
let asr_path = format!(
|
||||
"{}/{}.asr.json",
|
||||
crate::core::config::OUTPUT_DIR
|
||||
@@ -2180,7 +2183,16 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
.trim_end_matches('/'),
|
||||
uuid
|
||||
);
|
||||
if let Ok(content) = std::fs::read_to_string(&asr_path) {
|
||||
let asr_asrx_path = format!(
|
||||
"{}/{}.asr_asrx.json",
|
||||
crate::core::config::OUTPUT_DIR
|
||||
.as_str()
|
||||
.trim_end_matches('/'),
|
||||
uuid
|
||||
);
|
||||
let content = std::fs::read_to_string(&asr_path)
|
||||
.or_else(|_| std::fs::read_to_string(&asr_asrx_path));
|
||||
if let Ok(content) = content {
|
||||
if let Ok(data) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
match data.get("status").and_then(|s| s.as_str()) {
|
||||
Some("no_audio_track") | Some("silent_audio") => true,
|
||||
@@ -2397,6 +2409,7 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
// (completed + failed) == total_scenes 才代表全部 scene 都處理完,
|
||||
// 否則 job 保持 running 由 poll 重試。
|
||||
let scene_vlm_done: bool = if has_cut {
|
||||
// Check if scenes.json exists first
|
||||
if let Ok(scenes_json) =
|
||||
std::fs::read_to_string(format!("{}/{}.scenes.json", output_dir, uuid))
|
||||
{
|
||||
@@ -2406,7 +2419,6 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
.and_then(|v| v.as_i64())
|
||||
.unwrap_or(0);
|
||||
if total == 0 {
|
||||
// 無 scene 可選(例如極短或全部 blur 失敗)視為完成
|
||||
true
|
||||
} else {
|
||||
let completed = scenes_data
|
||||
@@ -2429,7 +2441,18 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
// scenes.json not found — check processor_results for scene_vlm completion
|
||||
// (e.g. "completed" due to invalid metadata / not applicable)
|
||||
let mj_t = schema::table_name("monitor_jobs");
|
||||
let pr_t = schema::table_name("processor_results");
|
||||
let svlm_done: Option<String> = sqlx::query_scalar(&format!(
|
||||
"SELECT status FROM {pr_t} WHERE job_id = (SELECT id FROM {mj_t} WHERE uuid = $1) AND processor = 'scene_vlm' LIMIT 1"
|
||||
))
|
||||
.bind(uuid)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
svlm_done.as_deref() == Some("completed")
|
||||
}
|
||||
} else {
|
||||
true
|
||||
@@ -2532,7 +2555,7 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
// 例如:Rule 1 只需 ASR+ASRX 完成即可觸發,不須等 face/pose/story 完成
|
||||
|
||||
// 定義必要 processor(必須完成的才算 job 成功)
|
||||
let essential_processors = ["cut", "asr", "asrx"];
|
||||
let essential_processors = ["cut", "asr", "asrx", "asr_asrx"];
|
||||
|
||||
let essential_failed = essential_processors.iter().any(|ep| {
|
||||
results.iter().any(|r| {
|
||||
@@ -2911,8 +2934,8 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
|
||||
let has_asr_or_asrx = completed_processors
|
||||
.iter()
|
||||
.any(|p| p == "asrx" || p == "asr");
|
||||
let has_asrx = completed_processors.iter().any(|p| p == "asrx");
|
||||
.any(|p| p == "asrx" || p == "asr" || p == "asr_asrx");
|
||||
let has_asrx = completed_processors.iter().any(|p| p == "asrx" || p == "asr_asrx");
|
||||
let has_cut = completed_processors.iter().any(|p| p == "cut");
|
||||
let has_face = completed_processors.iter().any(|p| p == "face");
|
||||
let has_ocr = completed_processors.iter().any(|p| p == "ocr");
|
||||
@@ -3376,13 +3399,27 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
||||
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
|
||||
// Get video path from DB for face crop extraction
|
||||
let video_path: Option<String> = db_clone
|
||||
.get_video_by_uuid(&uuid_clone)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|v| v.file_path);
|
||||
|
||||
let mut face_args = vec![uuid_clone.as_str(), "--output-dir", output_dir];
|
||||
if let Some(ref vp) = video_path {
|
||||
face_args.push("--video-path");
|
||||
face_args.push(vp.as_str());
|
||||
}
|
||||
|
||||
let result = match executor.rust_binary_path("rust_store_traced_faces") {
|
||||
Some(bin) => {
|
||||
tracing::info!("[FACE_TRACE] Using Rust binary: {:?}", bin);
|
||||
executor
|
||||
.run_rust_with_output_idx_and_frames(
|
||||
&bin,
|
||||
&[&uuid_clone, "--output-dir", output_dir],
|
||||
&face_args,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -1098,6 +1098,62 @@ impl ProcessorPool {
|
||||
total_faces: 0,
|
||||
})
|
||||
}
|
||||
ProcessorType::AsrAsrx => {
|
||||
let asr_asrx_result = processor::process_asr_asrx(
|
||||
video_path,
|
||||
output_path.to_str().unwrap(),
|
||||
uuid,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Convert to AsrResult for storage
|
||||
let asr_segments: Vec<processor::AsrSegment> = asr_asrx_result
|
||||
.segments
|
||||
.iter()
|
||||
.map(|s| processor::AsrSegment {
|
||||
start_time: s.start,
|
||||
end_time: s.end,
|
||||
start_frame: None,
|
||||
end_frame: None,
|
||||
text: s.text.clone(),
|
||||
confidence: 1.0,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut asr_result = processor::AsrResult {
|
||||
metadata: None,
|
||||
status: None,
|
||||
language: Some(asr_asrx_result.language.clone()),
|
||||
language_probability: None,
|
||||
segments: asr_segments,
|
||||
segment_count: 0,
|
||||
};
|
||||
asr_result.compute_status();
|
||||
|
||||
let chunks_produced = asr_result.segments.len() as i32;
|
||||
let lang = asr_result.language.clone();
|
||||
tracing::info!(
|
||||
"ASR_ASRX completed, language={}, {} segments for {}",
|
||||
lang.as_deref().unwrap_or("unknown"),
|
||||
chunks_produced,
|
||||
job.uuid
|
||||
);
|
||||
if let Err(e) = Self::store_asr_chunks(db, &job.uuid, &asr_result).await {
|
||||
tracing::error!("Failed to store ASR_ASRX chunks for {}: {}", job.uuid, e);
|
||||
}
|
||||
Ok(ProcessorOutput {
|
||||
data: serde_json::Value::Null,
|
||||
chunks_produced,
|
||||
frames_processed: total_frames,
|
||||
total_frames,
|
||||
retry_count: 0,
|
||||
pid: 0,
|
||||
asr_status: asr_result.status.clone(),
|
||||
segment_count: asr_result.segment_count,
|
||||
face_status: None,
|
||||
total_faces: 0,
|
||||
})
|
||||
}
|
||||
ProcessorType::Asrx => {
|
||||
let mut result =
|
||||
processor::process_asrx(video_path, output_path.to_str().unwrap(), uuid)
|
||||
|
||||
Reference in New Issue
Block a user