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
@@ -641,8 +641,8 @@ fn extract_frames(
.arg(video_path)
.arg("-vf")
.arg(&filter)
.arg("-vsync")
.arg("0")
.arg("-fps_mode")
.arg("vfr")
.arg("-f")
.arg("image2")
.arg(&out_pattern)
@@ -32,6 +32,12 @@ struct Args {
/// IoU threshold for bbox overlap
#[arg(long, default_value = "0.3")]
iou_threshold: f64,
/// Video file path (for extracting face crops)
#[arg(long)]
video_path: Option<String>,
/// DB URL for looking up video path (fallback)
#[arg(long)]
db_url: Option<String>,
}
fn env_var(name: &str, default: &str) -> String {
@@ -230,6 +236,86 @@ fn bboxes_match(b1: &BBox, b2: &BBox, tolerance: i32) -> bool {
(b1.height - b2.height).abs() <= tolerance
}
/// Extract key_face.jpg for each trace using ffmpeg crop.
/// Uses the highest-confidence frame's bbox from the trace.
fn extract_face_jpegs(
file_uuid: &str,
output_dir: &std::path::Path,
face_data: &FaceData,
traces: &[TraceInfo],
video_path: &str,
) -> Result<()> {
let base_dir = output_dir.join(file_uuid);
for trace in traces {
let trace_dir = base_dir.join(format!("trace_{}", trace.trace_id));
std::fs::create_dir_all(&trace_dir).ok();
// Find the best face (highest confidence) for this trace
let mut best_face: Option<(usize, &FaceDetection)> = None;
for frame in &face_data.frames {
for face in &frame.faces {
if let Some(tid) = face.trace_id {
if tid == trace.trace_id as i32 {
let frame_num = frame.frame as usize;
if let Some((_, bf)) = &best_face {
if face.confidence > bf.confidence {
best_face = Some((frame_num, face));
}
} else {
best_face = Some((frame_num, face));
}
}
}
}
}
// Extract key_face.jpg from the best frame
if let Some((frame_num, face)) = best_face {
if face.bbox.width > 0 && face.bbox.height > 0 {
let out_path = trace_dir.join("key_face.jpg");
if let Err(e) = extract_face_crop(video_path, frame_num, face, &out_path) {
println!("[TRACE_STORE] WARN key_face.jpg for trace {}: {}", trace.trace_id, e);
}
}
}
}
Ok(())
}
/// Use ffmpeg to extract a single cropped face frame.
fn extract_face_crop(video_path: &str, frame_num: usize, face: &FaceDetection, output: &std::path::Path) -> Result<()> {
let x = face.bbox.x;
let y = face.bbox.y;
let w = face.bbox.width;
let h = face.bbox.height;
let status = std::process::Command::new("/opt/homebrew/bin/ffmpeg")
.args([
"-y", "-v", "quiet",
"-i", video_path,
"-vf", &format!("select=eq(n\\,{}),crop={}:{}:{}:{}", frame_num, w, h, x, y),
"-frames:v", "1",
"-q:v", "3",
"-f", "image2",
output.to_str().unwrap(),
])
.status()
.context("Failed to run ffmpeg")?;
if !status.success() {
anyhow::bail!("ffmpeg exit code: {:?}", status.code());
}
if !output.exists() {
anyhow::bail!("ffmpeg did not produce output");
}
Ok(())
}
fn main() -> Result<()> {
let args = Args::parse();
@@ -391,6 +477,13 @@ fn main() -> Result<()> {
0.0
};
// Extract face crop JPEGs for each trace (before traced_data takes ownership)
let video_path = args.video_path.clone()
.or_else(|| std::env::var("MOMENTRY_VIDEO_PATH").ok());
if let Some(ref video) = video_path {
extract_face_jpegs(&args.file_uuid, &args.output_dir, &face_data, &traces_v2, video)?;
}
// Create output (v2 format)
let traced_data = FaceTracedData {
schema_version: "2.0".to_string(),