jschwab21 commited on
Commit
44fd805
·
verified ·
1 Parent(s): b5ce577

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +7 -8
video_processing.py CHANGED
@@ -103,19 +103,18 @@ def convert_timestamp_to_seconds(timestamp):
103
  h, m, s = map(float, timestamp.split(':'))
104
  return int(h) * 3600 + int(m) * 60 + s
105
 
106
- def extract_frames(video_path, start_time, end_time):
107
- start_seconds = convert_timestamp_to_seconds(start_time)
108
- end_seconds = convert_timestamp_to_seconds(end_time)
109
- video_clip = VideoFileClip(video_path).subclip(start_seconds, end_seconds)
110
-
111
- def extract_frame_at_time(t):
112
- return video_clip.get_frame(t / video_clip.fps)
113
 
 
 
114
  frame_times = range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 10))
115
 
116
  # Create a pool of workers to extract frames in parallel
117
  with Pool() as pool:
118
- frames = pool.map(extract_frame_at_time, frame_times)
 
119
 
120
  return frames
121
 
 
103
  h, m, s = map(float, timestamp.split(':'))
104
  return int(h) * 3600 + int(m) * 60 + s
105
 
106
+ def extract_frame_at_time(args):
107
+ video_clip, t = args
108
+ return video_clip.get_frame(t / video_clip.fps)
 
 
 
 
109
 
110
+ def extract_frames(video_path, start_time, end_time):
111
+ video_clip = VideoFileClip(video_path).subclip(start_time, end_time)
112
  frame_times = range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 10))
113
 
114
  # Create a pool of workers to extract frames in parallel
115
  with Pool() as pool:
116
+ # We need to pass video_clip and t to the function, wrap in tuple
117
+ frames = pool.map(extract_frame_at_time, ((video_clip, t) for t in frame_times))
118
 
119
  return frames
120