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:
Accusys
2026-11-06 10:00:24 +08:00
parent e56e2892d0
commit c6cbb5d1fb
139 changed files with 27117 additions and 151 deletions
+2 -2
View File
@@ -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
+16 -4
View File
@@ -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
)
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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()],
+2 -2
View File
@@ -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([
+84
View File
@@ -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,
})
}
+2 -2
View File
@@ -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",
+8
View File
@@ -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);
+7 -2
View File
@@ -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)
}
+2
View File
@@ -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};
+42 -4
View File
@@ -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",