From 5e3c8753a63568ce2966c161d0954819f6275720 Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Sun, 21 Dec 2025 15:59:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=A3=80=E7=B4=A2=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=8E=E8=A7=86=E9=A2=91=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E5=A4=84=E7=90=86=E5=B8=A7=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E6=9C=AA=E5=A4=84=E7=90=86=E5=B8=A7=EF=BC=8C?= =?UTF-8?q?=E5=B8=A7=E7=8E=87=E6=8E=A7=E5=88=B6=E5=9C=A815-23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/video_check_biz.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/video_check_biz.py b/src/video_check_biz.py index 0a4007f..ae069f9 100644 --- a/src/video_check_biz.py +++ b/src/video_check_biz.py @@ -279,7 +279,7 @@ class VideoCheckBiz(BaseFaceBiz): results = [] # 确保使用黑名单模式 - self.set_list_mode("blacklist") + self.set_list_mode("0") print(f"🎯 开始批量处理视频: 共{len(video_paths)}个视频") print(f"🔍 检测模式: 黑名单模式, 跳帧数: {frame_skip}") @@ -332,6 +332,7 @@ class VideoCheckBiz(BaseFaceBiz): def _process_single_video_with_detection(self, video_path: str, frame_skip: int, suffix: str) -> Optional[Dict]: """ 处理单个视频,进行黑名单检测并保存结果 + 只保留处理的帧,帧率控制在15-23帧之间 参数: video_path: 视频文件路径 @@ -356,30 +357,36 @@ class VideoCheckBiz(BaseFaceBiz): return None # 获取视频信息 - fps = cap.get(cv2.CAP_PROP_FPS) + original_fps = cap.get(cv2.CAP_PROP_FPS) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) + # 计算输出视频的帧率 + # 目标帧率在15-23帧之间 + target_fps = min(max(original_fps / frame_skip, 15), 23) + # 创建输出路径 video_dir = os.path.dirname(video_path) video_name = os.path.splitext(os.path.basename(video_path))[0] output_path = os.path.join(video_dir, f"{video_name}{suffix}.mp4") - # 创建视频写入器 + # 创建视频写入器,使用计算出的目标帧率 fourcc = cv2.VideoWriter_fourcc(*'mp4v') - out = cv2.VideoWriter(output_path, fourcc, fps, (width, height)) + out = cv2.VideoWriter(output_path, fourcc, target_fps, (width, height)) if not out.isOpened(): print(f"❌ 无法创建输出文件: {output_path}") cap.release() return None - print(f"📹 视频信息: {width}x{height}, {fps:.1f}FPS, {total_frames}帧") + print(f"📹 原视频信息: {width}x{height}, {original_fps:.1f}FPS, {total_frames}帧") + print(f"🎯 输出视频帧率: {target_fps:.1f}FPS (目标范围: 15-23FPS)") frame_index = 0 processed_frames = 0 detection_count = 0 + processed_frames_list = [] # 记录处理过的帧 while True: ret, frame = cap.read() @@ -421,9 +428,15 @@ class VideoCheckBiz(BaseFaceBiz): # 绘制检测结果 if results: frame = self.draw_detections(frame, results) + + # 只写入处理过的帧 + out.write(frame) + processed_frames_list.append({ + 'frame_index': frame_index, + 'has_detection': len(results) > 0, + 'has_blacklist_match': any(r['is_match'] for r in results) + }) - # 写入处理后的帧 - out.write(frame) frame_index += 1 # 显示进度 @@ -434,7 +447,11 @@ class VideoCheckBiz(BaseFaceBiz): cap.release() out.release() + # 统计处理结果 + frames_with_blacklist = sum(1 for f in processed_frames_list if f['has_blacklist_match']) + print(f"📊 处理统计: 处理{processed_frames}帧, 检测到{detection_count}次黑名单匹配") + print(f"🎬 输出视频: {len(processed_frames_list)}帧, {target_fps:.1f}FPS") # 返回详细结果 return { @@ -443,6 +460,8 @@ class VideoCheckBiz(BaseFaceBiz): 'has_blacklist_match': detection_count > 0, 'detection_count': detection_count, 'total_frames_processed': processed_frames, + 'output_fps': target_fps, + 'output_frame_count': len(processed_frames_list), 'blacklist_matches': [{ 'frame_index': frame_index, 'best_match': result['best_match'], @@ -512,7 +531,7 @@ class VideoCheckBiz(BaseFaceBiz): best_name, similarity = self.find_best_match(face.embedding) # 根据名单模式判断是否匹配 - if self.list_mode == "blacklist": + if self.list_mode == "0": is_match = best_name is not None and similarity >= self.similarity_threshold else: # whitelist is_match = best_name is not None and similarity >= self.similarity_threshold