视频检索的处理后视频,只保留处理帧,不保留未处理帧,帧率控制在15-23
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user