txarst commited on
Commit
b06cacb
Β·
1 Parent(s): e67e464

gradio opencv debugging

Browse files
Files changed (1) hide show
  1. gradio_utils.py +46 -0
gradio_utils.py CHANGED
@@ -40,14 +40,60 @@ def load_model(model_configs, device="cpu"):
40
 
41
  def extract_frames(video_path):
42
  """Extracts frames from a video file."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  vidcap = cv2.VideoCapture(video_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  frames = []
 
45
  success, image = vidcap.read()
 
 
 
46
  while success:
47
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
48
  frames.append(image_rgb)
49
  success, image = vidcap.read()
 
 
 
 
 
 
50
  vidcap.release()
 
 
51
  return frames
52
 
53
 
 
40
 
41
  def extract_frames(video_path):
42
  """Extracts frames from a video file."""
43
+ import os
44
+
45
+ # Debug: Check if file exists and get info
46
+ print(f"πŸ” DEBUG: Attempting to extract frames from: {video_path}")
47
+ print(f"πŸ” DEBUG: File exists: {os.path.exists(video_path)}")
48
+
49
+ if os.path.exists(video_path):
50
+ file_size = os.path.getsize(video_path)
51
+ print(f"πŸ” DEBUG: File size: {file_size} bytes")
52
+ print(f"πŸ” DEBUG: File permissions: {oct(os.stat(video_path).st_mode)}")
53
+ else:
54
+ print(f"❌ DEBUG: File does not exist at path: {video_path}")
55
+ return []
56
+
57
+ # Debug: Try to open with OpenCV
58
+ print(f"πŸ” DEBUG: Creating VideoCapture object...")
59
  vidcap = cv2.VideoCapture(video_path)
60
+
61
+ # Debug: Check if VideoCapture opened successfully
62
+ is_opened = vidcap.isOpened()
63
+ print(f"πŸ” DEBUG: VideoCapture opened successfully: {is_opened}")
64
+
65
+ if not is_opened:
66
+ print(f"❌ DEBUG: Failed to open video with OpenCV")
67
+ vidcap.release()
68
+ return []
69
+
70
+ # Debug: Get video properties
71
+ frame_count = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
72
+ fps = vidcap.get(cv2.CAP_PROP_FPS)
73
+ width = int(vidcap.get(cv2.CAP_PROP_FRAME_WIDTH))
74
+ height = int(vidcap.get(cv2.CAP_PROP_FRAME_HEIGHT))
75
+
76
+ print(f"πŸ” DEBUG: Video properties - Frames: {frame_count}, FPS: {fps}, Size: {width}x{height}")
77
+
78
  frames = []
79
+ frame_index = 0
80
  success, image = vidcap.read()
81
+
82
+ print(f"πŸ” DEBUG: First frame read success: {success}")
83
+
84
  while success:
85
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
86
  frames.append(image_rgb)
87
  success, image = vidcap.read()
88
+ frame_index += 1
89
+
90
+ # Debug: Log progress every 10 frames
91
+ if frame_index % 10 == 0:
92
+ print(f"πŸ” DEBUG: Extracted {frame_index} frames so far...")
93
+
94
  vidcap.release()
95
+
96
+ print(f"βœ… DEBUG: Successfully extracted {len(frames)} frames from video")
97
  return frames
98
 
99