API Bot commited on
Commit
e2338af
·
1 Parent(s): def90a3

Force frame calculation from timestamp only, ignore client frame index

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -692,18 +692,23 @@ def process_video_api(
692
  # Step 2: Apply each annotation
693
  for i, ann in enumerate(annotations):
694
  object_id = ann.get("object_id", 1)
695
- frame_idx = ann.get("frame", 0)
696
  timestamp_ms = ann.get("timestamp_ms", None)
 
697
  x = ann.get("x", 0)
698
  y = ann.get("y", 0)
699
  label = ann.get("label", "positive")
700
 
701
- # If timestamp is provided and there's an FPS mismatch, recalculate frame index
702
  if timestamp_ms is not None and space_fps and space_fps > 0:
703
- recalculated_frame = int((timestamp_ms / 1000.0) * space_fps)
704
- if recalculated_frame != frame_idx:
705
- print(f"[API] ℹ️ Recalculating frame: Client frame {frame_idx} @ {timestamp_ms}ms Space frame {recalculated_frame}")
706
- frame_idx = recalculated_frame
 
 
 
 
 
707
 
708
  print(f"[API] Adding annotation {i+1}/{len(annotations)}: "
709
  f"Object {object_id}, Frame {frame_idx}, ({x}, {y}), {label}")
 
692
  # Step 2: Apply each annotation
693
  for i, ann in enumerate(annotations):
694
  object_id = ann.get("object_id", 1)
 
695
  timestamp_ms = ann.get("timestamp_ms", None)
696
+ frame_idx = ann.get("frame", None)
697
  x = ann.get("x", 0)
698
  y = ann.get("y", 0)
699
  label = ann.get("label", "positive")
700
 
701
+ # Calculate frame from timestamp using Space's FPS (more accurate)
702
  if timestamp_ms is not None and space_fps and space_fps > 0:
703
+ calculated_frame = int((timestamp_ms / 1000.0) * space_fps)
704
+ if frame_idx is not None and calculated_frame != frame_idx:
705
+ print(f"[API] Using timestamp: {timestamp_ms}ms Frame {calculated_frame} (client sent frame {frame_idx})")
706
+ else:
707
+ print(f"[API] ✅ Calculated frame from timestamp: {timestamp_ms}ms → Frame {calculated_frame}")
708
+ frame_idx = calculated_frame
709
+ elif frame_idx is None:
710
+ print(f"[API] ⚠️ Warning: No timestamp or frame provided, using frame 0")
711
+ frame_idx = 0
712
 
713
  print(f"[API] Adding annotation {i+1}/{len(annotations)}: "
714
  f"Object {object_id}, Frame {frame_idx}, ({x}, {y}), {label}")