shin0624 commited on
Commit
7eed2c3
·
verified ·
1 Parent(s): a983cb6

Update detector/frame_sampler.py

Browse files
Files changed (1) hide show
  1. detector/frame_sampler.py +5 -0
detector/frame_sampler.py CHANGED
@@ -4,6 +4,11 @@ import os
4
  def extract_keyframes(video, output_dir, target_frames=50):
5
  cap = cv2.VideoCapture(video)
6
  total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
 
 
 
 
 
7
  frame_step = max(1, total_frames // target_frames)
8
 
9
  os.makedirs(output_dir, exist_ok=True)
 
4
  def extract_keyframes(video, output_dir, target_frames=50):
5
  cap = cv2.VideoCapture(video)
6
  total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
7
+
8
+ if total_frames <= 0:
9
+ cap.release()
10
+ return []
11
+
12
  frame_step = max(1, total_frames // target_frames)
13
 
14
  os.makedirs(output_dir, exist_ok=True)