notRaphael commited on
Commit
89c35c3
·
verified ·
1 Parent(s): abb7d19

fix: frame_extractor - add max(1,...) guard for frame_interval

Browse files
video_intelligence/frame_extractor.py CHANGED
@@ -25,12 +25,12 @@ def extract_frames(
25
  ) -> List[ExtractedFrame]:
26
  """
27
  Extract frames from video at given FPS.
28
-
29
  Args:
30
  video_path: Path to video file
31
  fps: Frames per second to extract (default 1.0)
32
  max_frames: Maximum number of frames to extract
33
-
34
  Returns:
35
  List of ExtractedFrame objects with PIL images and timestamps
36
  """
@@ -43,8 +43,8 @@ def extract_frames(
43
  duration_sec = total_frames / video_fps if video_fps > 0 else 0
44
 
45
  # Calculate which frames to extract
46
- frame_interval = int(video_fps / fps) if fps < video_fps else 1
47
-
48
  print(f"📹 Video: {video_path}")
49
  print(f" Duration: {duration_sec:.1f}s | FPS: {video_fps:.1f} | Total frames: {total_frames}")
50
  print(f" Extracting every {frame_interval}th frame ({fps} fps) ...")
@@ -61,7 +61,7 @@ def extract_frames(
61
  # Convert BGR (OpenCV) to RGB (PIL)
62
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
63
  pil_image = Image.fromarray(rgb_frame)
64
- timestamp = frame_count / video_fps
65
 
66
  frames.append(ExtractedFrame(
67
  image=pil_image,
 
25
  ) -> List[ExtractedFrame]:
26
  """
27
  Extract frames from video at given FPS.
28
+
29
  Args:
30
  video_path: Path to video file
31
  fps: Frames per second to extract (default 1.0)
32
  max_frames: Maximum number of frames to extract
33
+
34
  Returns:
35
  List of ExtractedFrame objects with PIL images and timestamps
36
  """
 
43
  duration_sec = total_frames / video_fps if video_fps > 0 else 0
44
 
45
  # Calculate which frames to extract
46
+ frame_interval = max(1, int(video_fps / fps)) if fps < video_fps else 1
47
+
48
  print(f"📹 Video: {video_path}")
49
  print(f" Duration: {duration_sec:.1f}s | FPS: {video_fps:.1f} | Total frames: {total_frames}")
50
  print(f" Extracting every {frame_interval}th frame ({fps} fps) ...")
 
61
  # Convert BGR (OpenCV) to RGB (PIL)
62
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
63
  pil_image = Image.fromarray(rgb_frame)
64
+ timestamp = frame_count / video_fps if video_fps > 0 else 0
65
 
66
  frames.append(ExtractedFrame(
67
  image=pil_image,