chaitanya.musale Claude Sonnet 4.5 commited on
Commit
9363ad6
·
1 Parent(s): ffe3fbc

Fix two bugs from post-implementation audit

Browse files

1. clip_extractor.py: snap loops were breaking on FIRST boundary within
tolerance instead of finding the NEAREST one. With a sorted boundary
list, this snapped to the lowest-valued boundary in range, not the
closest. Fixed by tracking best_dist and iterating all boundaries.

2. orchestrator.py: adjust_to_scene_boundaries() call was still passing
tolerance=5.0 and min/max_duration — leftover from the old heavy
implementation. The new method is a lightweight 1s safety snap that
ignores min/max_duration entirely. Removed stale kwargs so the call
uses the correct defaults.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Files changed (2) hide show
  1. core/clip_extractor.py +10 -6
  2. pipeline/orchestrator.py +0 -3
core/clip_extractor.py CHANGED
@@ -256,17 +256,21 @@ class ClipExtractor:
256
  new_start = candidate.start_time
257
  new_end = candidate.end_time
258
 
259
- # Snap start to nearest boundary within tolerance
 
260
  for boundary in scene_boundaries:
261
- if abs(boundary - candidate.start_time) <= tolerance:
 
 
262
  new_start = boundary
263
- break
264
 
265
- # Snap end to nearest boundary within tolerance
 
266
  for boundary in scene_boundaries:
267
- if abs(boundary - candidate.end_time) <= tolerance:
 
 
268
  new_end = boundary
269
- break
270
 
271
  # Sanity: don't snap if it collapses the clip
272
  if new_end <= new_start:
 
256
  new_start = candidate.start_time
257
  new_end = candidate.end_time
258
 
259
+ # Snap start to the NEAREST boundary within tolerance
260
+ best_start_dist = tolerance
261
  for boundary in scene_boundaries:
262
+ dist = abs(boundary - candidate.start_time)
263
+ if dist <= best_start_dist:
264
+ best_start_dist = dist
265
  new_start = boundary
 
266
 
267
+ # Snap end to the NEAREST boundary within tolerance
268
+ best_end_dist = tolerance
269
  for boundary in scene_boundaries:
270
+ dist = abs(boundary - candidate.end_time)
271
+ if dist <= best_end_dist:
272
+ best_end_dist = dist
273
  new_end = boundary
 
274
 
275
  # Sanity: don't snap if it collapses the clip
276
  if new_end <= new_start:
pipeline/orchestrator.py CHANGED
@@ -428,9 +428,6 @@ class PipelineOrchestrator:
428
  optimized_candidates = self._clip_extractor.adjust_to_scene_boundaries(
429
  optimized_candidates,
430
  scene_boundaries,
431
- tolerance=5.0, # Allow up to 5s adjustment for scene alignment
432
- min_duration=min_duration,
433
- max_duration=max_duration,
434
  )
435
  # Log the resulting duration distribution
436
  durations = [c.end_time - c.start_time for c in optimized_candidates]
 
428
  optimized_candidates = self._clip_extractor.adjust_to_scene_boundaries(
429
  optimized_candidates,
430
  scene_boundaries,
 
 
 
431
  )
432
  # Log the resulting duration distribution
433
  durations = [c.end_time - c.start_time for c in optimized_candidates]