ziv-conntour commited on
Commit
4e5fd61
·
verified ·
1 Parent(s): 8df568e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -282,22 +282,39 @@ def analyze_stream(prompt, chatbot):
282
  print("Desired start_frame =", start_frame)
283
  print("Video start, fps, base_start_time =", video_start, fps, base_start_time)
284
 
285
- # --- Manual frame skipping ---
286
- # Read and discard frames until we reach `start_frame`
287
- if start_frame > 0:
288
- print(f"Skipping {start_frame} frames...")
 
 
 
 
 
 
 
 
 
 
 
289
  for _ in range(start_frame):
290
  ret, _ = cap.read()
291
  if not ret:
292
- # If the video ends or fails before skipping all frames, break
293
- print("Failed before reaching start_frame.")
294
  break
295
-
296
- print("Starting capture from the current position now.")
297
 
298
  frames = []
299
  start_time = time.time()
300
  clip_id = 0
 
 
 
 
 
 
 
301
 
302
  while not stop_capture:
303
  ret, frame = cap.read()
 
282
  print("Desired start_frame =", start_frame)
283
  print("Video start, fps, base_start_time =", video_start, fps, base_start_time)
284
 
285
+ print("Local file detected. Attempting direct frame seek...")
286
+
287
+ # Attempt to seek
288
+ success = cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
289
+
290
+ # Check if seeking was actually successful by reading a frame
291
+ ret, test_frame = cap.read()
292
+
293
+ if not success or not ret:
294
+ # If seeking failed, fall back to manual skipping
295
+ print(f"Direct seek to frame {start_frame} failed. Falling back to manual skipping.")
296
+ # Reset capture to start
297
+ cap.release()
298
+ cap = cv2.VideoCapture(stream)
299
+ # Skip frames manually
300
  for _ in range(start_frame):
301
  ret, _ = cap.read()
302
  if not ret:
303
+ print("Failed before reaching start_frame (manual skip).")
 
304
  break
305
+ # We'll use 'test_frame' from the final read below
306
+ ret, test_frame = cap.read()
307
 
308
  frames = []
309
  start_time = time.time()
310
  clip_id = 0
311
+
312
+ print("Starting capture from the current position now.")
313
+ if ret and test_frame is not None:
314
+ # We already read one frame after seeking, so store it
315
+ frames.append(test_frame)
316
+
317
+
318
 
319
  while not stop_capture:
320
  ret, frame = cap.read()