fix: Face processor now saves status and total_faces to face.json
This commit is contained in:
+190
-6
@@ -1,10 +1,15 @@
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Version of the file profile schema.
|
||||
const PROFILE_VERSION: &str = "1.0";
|
||||
|
||||
/// Helper function to serialize f64 with 2 decimal places
|
||||
fn serialize_f64_2dec<S: Serializer>(value: &f64, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
serializer.serialize_f64((*value * 100.0).round() / 100.0)
|
||||
}
|
||||
|
||||
// ─── Data Types ───
|
||||
|
||||
/// Per-file face detection thresholds. `min_confidence` is 0–100 (%),
|
||||
@@ -15,7 +20,7 @@ pub struct FaceFilterSettings {
|
||||
pub min_size: i32,
|
||||
#[serde(default)]
|
||||
pub min_capture_quality: f64,
|
||||
|
||||
|
||||
// Single Frame Trace 配置
|
||||
#[serde(default = "default_true")]
|
||||
pub single_frame_trace_vlm_enabled: bool,
|
||||
@@ -23,21 +28,23 @@ pub struct FaceFilterSettings {
|
||||
pub single_frame_trace_group_enabled: bool,
|
||||
#[serde(default = "default_true")]
|
||||
pub single_frame_trace_unassigned_enabled: bool,
|
||||
|
||||
|
||||
// Single Trace Group 配置
|
||||
#[serde(default = "default_true")]
|
||||
pub single_trace_group_filter_enabled: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool { true }
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl FaceFilterSettings {
|
||||
/// Load defaults from admin config (processor_config.face).
|
||||
/// Falls back to hardcoded values if admin config unavailable.
|
||||
pub fn defaults() -> Self {
|
||||
let (min_confidence, min_size, min_capture_quality) =
|
||||
let (min_confidence, min_size, min_capture_quality) =
|
||||
crate::core::admin_config::get_face_filter_defaults();
|
||||
|
||||
|
||||
Self {
|
||||
min_confidence,
|
||||
min_size,
|
||||
@@ -613,6 +620,179 @@ pub fn count_face_artifacts(output_dir: &str, file_uuid: &str) -> FaceArtifactsC
|
||||
counts
|
||||
}
|
||||
|
||||
// ─── Scene VLM Profile ───
|
||||
|
||||
/// Scene VLM profile stored in `output/{file_uuid}.scenes.json`.
|
||||
/// Contains selected scene key frames and their VLM analysis results.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SceneProfile {
|
||||
pub version: String,
|
||||
pub file_uuid: String,
|
||||
pub status: SceneStatus,
|
||||
pub video_info: VideoInfo,
|
||||
pub config: SceneConfig,
|
||||
pub total_scenes: usize,
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub updated_at: chrono::DateTime<chrono::Utc>,
|
||||
pub scenes: Vec<SceneFrame>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SceneStatus {
|
||||
Pending,
|
||||
Ready,
|
||||
Processing,
|
||||
Completed,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SceneConfig {
|
||||
pub interval_sec: u32,
|
||||
pub use_cuts: bool,
|
||||
pub use_faces: bool,
|
||||
pub quality_metric: String,
|
||||
pub samples_per_interval: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SceneFrame {
|
||||
pub index: usize,
|
||||
pub filename: String,
|
||||
|
||||
#[serde(serialize_with = "serialize_f64_2dec")]
|
||||
pub timestamp_sec: f64,
|
||||
|
||||
pub frame_number: u32,
|
||||
pub selection_reason: SelectionReason,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub quality_score: Option<f64>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub quality_source: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub scene_info: Option<SceneInfo>,
|
||||
|
||||
pub face_count: u32,
|
||||
|
||||
#[serde(default)]
|
||||
pub person_traces: Vec<i64>,
|
||||
|
||||
pub has_cut: bool,
|
||||
pub cut_count: u32,
|
||||
|
||||
pub vlm_status: VlmStatus,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vlm_description: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vlm_description_localized: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vlm_scene_type: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vlm_location: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub vlm_objects: Vec<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vlm_attributes: Option<SceneAttributes>,
|
||||
|
||||
#[serde(default)]
|
||||
pub vlm_tags: Vec<String>,
|
||||
|
||||
pub embedding_status: EmbeddingStatus,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SceneInfo {
|
||||
pub scene_id: u32,
|
||||
pub scene_start_sec: f64,
|
||||
pub scene_end_sec: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SelectionReason {
|
||||
BestBlur,
|
||||
PreCutBestBlur,
|
||||
PostCutBestBlur,
|
||||
SceneStart,
|
||||
Default,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum VlmStatus {
|
||||
Pending,
|
||||
Processing,
|
||||
Completed,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum EmbeddingStatus {
|
||||
Pending,
|
||||
Completed,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SceneAttributes {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub lighting: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub weather: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub time_of_day: Option<String>,
|
||||
}
|
||||
|
||||
impl SceneProfile {
|
||||
pub fn new(file_uuid: &str, video_info: VideoInfo, config: SceneConfig) -> Self {
|
||||
Self {
|
||||
version: "1.0".to_string(),
|
||||
file_uuid: file_uuid.to_string(),
|
||||
status: SceneStatus::Pending,
|
||||
video_info,
|
||||
config,
|
||||
total_scenes: 0,
|
||||
created_at: chrono::Utc::now(),
|
||||
updated_at: chrono::Utc::now(),
|
||||
scenes: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scenes_path(output_dir: &str, file_uuid: &str) -> PathBuf {
|
||||
Path::new(output_dir).join(format!("{}.scenes.json", file_uuid))
|
||||
}
|
||||
|
||||
pub fn scenes_dir(output_dir: &str, file_uuid: &str) -> PathBuf {
|
||||
Path::new(output_dir).join(file_uuid).join("scenes")
|
||||
}
|
||||
|
||||
pub fn scene_frame_path(output_dir: &str, file_uuid: &str, filename: &str) -> PathBuf {
|
||||
Self::scenes_dir(output_dir, file_uuid).join(filename)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -808,6 +988,10 @@ mod tests {
|
||||
min_confidence: 85.0,
|
||||
min_size: 96,
|
||||
min_capture_quality: 0.0,
|
||||
single_frame_trace_vlm_enabled: true,
|
||||
single_frame_trace_group_enabled: true,
|
||||
single_frame_trace_unassigned_enabled: true,
|
||||
single_trace_group_filter_enabled: true,
|
||||
});
|
||||
let json = serde_json::to_string(&profile).unwrap();
|
||||
let restored: FileProfile = serde_json::from_str(&json).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user