fix: generate traces field when face.json already has trace_id
問題: - face.json 已包含 trace_id (來自 Rust face_tracker) - store_traced_faces.py 直接複製,跳過 traces 字段生成 - Worker 檢查 traces 字段判斷 trace_done - 因缺少 traces 字段,trace_done=false,阻塞 TKG 構建 修復: - ✅ 即使 face.json 有 trace_id,仍生成 traces 字段 - ✅ 從 faces 提取 trace_id,構建 traces dict - ✅ 包含 start_frame, end_frame, duration 等信息 - ✅ Worker 可正確判斷 trace_done 影響: - 修復 020.mp4 卡在 40% 的問題 - 確保 TKG 和後續流程可以繼續
This commit is contained in:
@@ -139,9 +139,46 @@ def run_face_tracker(
|
|||||||
|
|
||||||
if has_trace:
|
if has_trace:
|
||||||
print(f"[TRACE] face.json already contains trace_id, skipping tracking")
|
print(f"[TRACE] face.json already contains trace_id, skipping tracking")
|
||||||
# Copy face.json to traced_json_path (no re-tracking needed)
|
# Build traces dict from existing trace_ids before copying
|
||||||
|
traces = defaultdict(list)
|
||||||
|
if isinstance(frames_to_check, list):
|
||||||
|
for frame in frames_to_check:
|
||||||
|
for face in frame.get("faces", []):
|
||||||
|
trace_id = face.get("trace_id")
|
||||||
|
if trace_id is not None and trace_id > 0:
|
||||||
|
traces[trace_id].append(face)
|
||||||
|
else:
|
||||||
|
for frame_data in frames_to_check.values():
|
||||||
|
for face in frame_data.get("faces", []):
|
||||||
|
trace_id = face.get("trace_id")
|
||||||
|
if trace_id is not None and trace_id > 0:
|
||||||
|
traces[trace_id].append(face)
|
||||||
|
|
||||||
|
# Add traces field to face_data
|
||||||
|
face_data["traces"] = {}
|
||||||
|
fps = face_data.get("fps", 30.0)
|
||||||
|
for trace_id, trace_faces in traces.items():
|
||||||
|
if len(trace_faces) == 0:
|
||||||
|
continue
|
||||||
|
frames_list = [f.get("frame", f.get("frame_number", 0)) for f in trace_faces]
|
||||||
|
frame_indices = sorted([f if isinstance(f, int) else int(f) for f in frames_list])
|
||||||
|
duration_frames = len(frame_indices)
|
||||||
|
duration_seconds = duration_frames / fps if fps > 0 else 0
|
||||||
|
|
||||||
|
face_data["traces"][str(trace_id)] = {
|
||||||
|
"trace_id": int(trace_id),
|
||||||
|
"start_frame": frame_indices[0] if frame_indices else 0,
|
||||||
|
"end_frame": frame_indices[-1] if frame_indices else 0,
|
||||||
|
"duration_frames": duration_frames,
|
||||||
|
"duration_seconds": round(duration_seconds, 2),
|
||||||
|
}
|
||||||
|
|
||||||
|
print(f"[TRACE] Built {len(traces)} traces from existing trace_ids")
|
||||||
|
|
||||||
|
# Write to traced_json_path
|
||||||
import shutil
|
import shutil
|
||||||
shutil.copy(face_json_path, traced_json_path)
|
with open(traced_json_path, "w") as f:
|
||||||
|
json.dump(strip_embeddings_and_round(face_data), f, indent=2, ensure_ascii=False)
|
||||||
return traced_json_path
|
return traced_json_path
|
||||||
|
|
||||||
# V2.0 uses list format (FaceResult), convert to dict for face_tracker
|
# V2.0 uses list format (FaceResult), convert to dict for face_tracker
|
||||||
|
|||||||
Reference in New Issue
Block a user