diff --git a/doco/src/doco/video_split.py b/doco/src/doco/video_split.py index 7f73b0f..ede3b3a 100644 --- a/doco/src/doco/video_split.py +++ b/doco/src/doco/video_split.py @@ -543,10 +543,11 @@ def split_video( debug_csv=debug_csv_path, ) - # 统计各 decision + # 统计各 decision(frame_analysis 已包含所有非空白帧的 decision) for frame_idx, data in frame_analysis.items(): decision_stats[data["decision"]] = decision_stats.get(data["decision"], 0) + # 从 frame_analysis 统计中取 duplicate 相关计数(blank_count 已在上方单独统计) duplicate_iou = decision_stats.get("duplicate(iou)", 0) duplicate_hash = decision_stats.get("duplicate(hash)", 0) total_duplicate = blank_count + duplicate_iou + duplicate_hash @@ -555,11 +556,25 @@ def split_video( print(f"[video_split] 检测到 {len(keyframes)} 个关键帧") print(f"[video_split] 诊断CSV写入: {debug_csv_path}") - # 确认 frames/ 目录文件数与 total_extracted 一致 + # ---- 删除非关键帧,只保留最终关键帧 PNG ---- + # 建立应保留的帧索引集合 + keyframe_indices = set(kf["frame_index"] for kf in keyframes) + all_frame_files = sorted(frames_dir.glob("frame_*.png")) + deleted_count = 0 + for frame_file in all_frame_files: + # 从文件名 frame_0001.png 提取帧索引 + frame_idx = int(frame_file.stem.split("_")[1]) + if frame_idx not in keyframe_indices: + frame_file.unlink() + deleted_count += 1 + + print(f"[video_split] 清理非关键帧完成,删除 {deleted_count} 张,保留 {len(keyframes)} 张关键帧") + + # 确认 frames/ 目录文件数与关键帧数一致 actual_frame_files = len(list(frames_dir.glob("frame_*.png"))) - print(f"[debug] frames/ 目录实际文件数: {actual_frame_files} (预期: {total_extracted})") - if actual_frame_files != total_extracted: - print(f"[WARNING] frames/ 文件数({actual_frame_files}) 与抽帧数({total_extracted})不一致!") + print(f"[debug] frames/ 目录实际文件数: {actual_frame_files} (预期: {len(keyframes)})") + if actual_frame_files != len(keyframes): + print(f"[WARNING] frames/ 文件数({actual_frame_files}) 与关键帧数({len(keyframes)})不一致!") if dry_run: print("[video_split] dry-run:跳过 OCR")