feat: face fix deployment + trace_* regeneration + executor stderr filter fix

- swift_face.swift: frame rounding (.rounded()), conf 0.75, min_size 64
- trace_* directories regenerated for KOBA (37 traces, start_frame 5307)
- executor.rs: stderr filter now logs all non-empty stderr (was discarding)
- VAD not skippable in ASRX (main_fixed.py Step 2 always runs)
- Step 2.5 sentence boundary refinement added
- Cluster agent async endpoints + similarity transparency
- Keyword search: relationship text extraction, priority ordering
- Face fix handoff doc for Studio team
This commit is contained in:
Accusys
2026-08-05 00:13:50 +08:00
parent 36a704e3d3
commit 3d13a06bd9
42 changed files with 3447 additions and 778 deletions
+184 -50
View File
@@ -1,7 +1,8 @@
#!/opt/homebrew/bin/python3.11
#! /opt/homebrew/bin/python3.11
"""
CUT Processor - Scene Detection & Video Quality Check
Uses ffprobe for video analysis. Always produces at least 1 scene.
Dual-detector: ffprobe scene filter + PySceneDetect ContentDetector (merged).
Always produces at least 1 scene.
"""
import json
@@ -13,14 +14,32 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from redis_publisher import RedisPublisher
try:
from scenedetect import open_video, SceneManager
from scenedetect.detectors import ContentDetector, AdaptiveDetector
HAS_SCENEDETECT = True
except ImportError:
HAS_SCENEDETECT = False
def get_video_info(video_path: str) -> dict:
"""Get video info via ffprobe"""
try:
result = subprocess.run(
["ffprobe", "-v", "quiet", "-print_format", "json",
"-show_format", "-show_streams", video_path],
capture_output=True, text=True, timeout=30,
[
"ffprobe",
"-v",
"quiet",
"-print_format",
"json",
"-show_format",
"-show_streams",
video_path,
],
capture_output=True,
text=True,
timeout=30,
)
info = json.loads(result.stdout)
for stream in info.get("streams", []):
@@ -50,69 +69,167 @@ def get_video_info(video_path: str) -> dict:
"codec": stream.get("codec_name", ""),
}
return {
"frame_count": 0, "fps": 0.0, "duration": dur,
"width": 0, "height": 0, "codec": "",
"frame_count": 0,
"fps": 0.0,
"duration": dur,
"width": 0,
"height": 0,
"codec": "",
}
return {"frame_count": 0, "fps": 0.0, "duration": 0, "width": 0, "height": 0, "codec": ""}
return {
"frame_count": 0,
"fps": 0.0,
"duration": 0,
"width": 0,
"height": 0,
"codec": "",
}
except Exception:
return {"frame_count": 0, "fps": 0.0, "duration": 0, "width": 0, "height": 0, "codec": ""}
return {
"frame_count": 0,
"fps": 0.0,
"duration": 0,
"width": 0,
"height": 0,
"codec": "",
}
def detect_scenes_ffmpeg(video_path: str, fps: float, duration: float) -> list:
"""Detect scene changes using ffmpeg scene filter"""
"""Detect scene change times using ffmpeg scene filter
Returns:
List of cut times in seconds (empty if failed or no cuts found)
"""
try:
result = subprocess.run(
["ffprobe", "-v", "quiet", "-show_entries", "frame=pts_time",
"-of", "default=nk=0",
"-f", "lavfi",
f"movie={video_path},select='gt(scene\\,0.3)',showinfo",
"-show_frames"],
capture_output=True, text=True, timeout=300,
[
"ffprobe",
"-v",
"quiet",
"-show_entries",
"frame=pts_time",
"-of",
"default=nk=0",
"-f",
"lavfi",
f"movie={video_path},select='gt(scene\\,0.3)',showinfo",
"-show_frames",
],
capture_output=True,
text=True,
timeout=300,
)
times = []
times = set()
for line in (result.stderr + "\n" + result.stdout).split("\n"):
for prefix in ("pts_time=", "pts_time:"):
if prefix in line:
rest = line.split(prefix)[1].split()[0]
try:
t = float(rest)
times.append(t)
times.add(t)
except ValueError:
pass
return sorted(times)
except Exception:
return []
scenes = []
prev_time = 0.0
for i, t in enumerate(times):
end_frame = round(t * fps)
start_frame = round(prev_time * fps)
if end_frame > start_frame:
scenes.append({
"scene_number": i + 1,
"start_frame": start_frame,
def detect_scenes_scenedetect(video_path: str, fps: float, duration: float) -> list:
"""Detect scene change times using PySceneDetect (ContentDetector + AdaptiveDetector)
Runs both detectors and merges results for maximum recall.
Returns:
List of cut times in seconds (empty if failed or no cuts found)
"""
if not HAS_SCENEDETECT:
return []
try:
all_times = set()
# ContentDetector with lower threshold for higher recall
video = open_video(video_path)
sm = SceneManager()
sm.add_detector(ContentDetector(threshold=15.0))
sm.detect_scenes(video)
for i, (start_tc, _) in enumerate(sm.get_scene_list()):
if i == 0:
continue
t = start_tc.get_seconds()
if 0 < t < duration:
all_times.add(t)
# AdaptiveDetector (self-tuning, catches gradual transitions)
video = open_video(video_path)
sm = SceneManager()
sm.add_detector(AdaptiveDetector())
sm.detect_scenes(video)
for i, (start_tc, _) in enumerate(sm.get_scene_list()):
if i == 0:
continue
t = start_tc.get_seconds()
if 0 < t < duration:
all_times.add(t)
return sorted(all_times)
except Exception as e:
print(f"[CUT] scenedetect failed: {e}", file=sys.stderr)
return []
def rebuild_scenes(
cut_times: list, fps: float, total_frames: int, duration: float
) -> list:
"""Rebuild scene list from sorted cut times
Args:
cut_times: Sorted list of cut times in seconds
fps: Frames per second
total_frames: Total frame count
duration: Video duration in seconds
Returns:
List of {scene_number, start_frame, end_frame, start_time, end_time}
"""
scenes = []
prev_time = 0.0
prev_frame = 0
for i, t in enumerate(cut_times):
end_frame = round(t * fps)
if end_frame > prev_frame:
scenes.append(
{
"scene_number": len(scenes) + 1,
"start_frame": prev_frame,
"end_frame": end_frame - 1,
"start_time": prev_time,
"end_time": t - (1.0 / fps) if fps > 0 else t,
})
prev_time = t
}
)
prev_time = t
prev_frame = end_frame
last_frame = round(duration * fps) if fps > 0 else 0
prev_frame = round(prev_time * fps) if fps > 0 else 0
if last_frame > prev_frame:
scenes.append({
# Final scene
last_frame = total_frames
if last_frame > prev_frame:
scenes.append(
{
"scene_number": len(scenes) + 1,
"start_frame": prev_frame,
"end_frame": last_frame - 1,
"start_time": prev_time,
"end_time": duration,
})
}
)
return scenes
except Exception:
return []
return scenes
def process_cut(video_path: str, output_path: str, uuid: str = ""):
"""Process video for scene detection and quality verification"""
"""Process video for scene detection using dual detectors (ffmpeg + scenedetect)"""
publisher = RedisPublisher(uuid) if uuid else None
if publisher:
@@ -121,26 +238,40 @@ def process_cut(video_path: str, output_path: str, uuid: str = ""):
vinfo = get_video_info(video_path)
if publisher:
publisher.info("cut", f"fps={vinfo['fps']}, frames={vinfo['frame_count']}, codec={vinfo['codec']}")
publisher.info(
"cut",
f"fps={vinfo['fps']}, frames={vinfo['frame_count']}, codec={vinfo['codec']}",
)
total_frames = vinfo["frame_count"]
fps = vinfo["fps"]
duration = vinfo["duration"]
# Try ffmpeg scene detection
scenes = detect_scenes_ffmpeg(video_path, fps, duration)
# Phase 1: ffmpeg scene filter
cut_times_ffmpeg = detect_scenes_ffmpeg(video_path, fps, duration)
# Phase 2: scenedetect ContentDetector
cut_times_sd = detect_scenes_scenedetect(video_path, fps, duration)
# Merge: union of cut points from both detectors
all_cut_times = sorted(set(cut_times_ffmpeg + cut_times_sd))
scenes = rebuild_scenes(all_cut_times, fps, total_frames, duration)
# Always ensure at least 1 scene
if not scenes and total_frames > 0:
scenes = [{
"scene_number": 1,
"start_frame": 0,
"end_frame": total_frames - 1,
"start_time": 0.0,
"end_time": duration,
}]
scenes = [
{
"scene_number": 1,
"start_frame": 0,
"end_frame": total_frames - 1,
"start_time": 0.0,
"end_time": duration,
}
]
if publisher:
publisher.info("cut", "No scene changes detected, using whole video as single scene")
publisher.info(
"cut", "No scene changes detected, using whole video as single scene"
)
result = {
"frame_count": total_frames,
@@ -152,7 +283,10 @@ def process_cut(video_path: str, output_path: str, uuid: str = ""):
json.dump(result, f, indent=2)
if publisher:
publisher.complete("cut", f"{len(scenes)} scenes")
publisher.complete(
"cut",
f"{len(scenes)} scenes ({len(cut_times_ffmpeg)} ffmpeg + {len(cut_times_sd)} scenedetect)",
)
return result