jschwab21 commited on
Commit
79e5fc0
·
verified ·
1 Parent(s): 9fc3eba

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +5 -3
video_processing.py CHANGED
@@ -82,11 +82,11 @@ def convert_timestamp_to_seconds(timestamp):
82
  h, m, s = map(float, timestamp.split(':'))
83
  return int(h) * 3600 + int(m) * 60 + s
84
 
85
- def extract_frames(video_path, start_time, end_time):
86
  frames = []
87
  start_seconds = convert_timestamp_to_seconds(start_time)
88
  end_seconds = convert_timestamp_to_seconds(end_time)
89
- video_clip = VideoFileClip(video_path).subclip(start_seconds, end_seconds)
90
 
91
  for frame_time in range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 3)):
92
  frame = video_clip.get_frame(frame_time / video_clip.fps)
@@ -108,8 +108,10 @@ def analyze_scenes(video_path, scenes, description):
108
  text_features = model.get_text_features(**text_inputs).detach()
109
  positive_feature, negative_features = text_features[0], text_features[1:]
110
 
 
 
111
  for scene_num, (start_time, end_time) in enumerate(scenes):
112
- frames = extract_frames(video_path, start_time, end_time)
113
  if not frames:
114
  print(f"Scene {scene_num + 1}: Start={start_time}, End={end_time} - No frames extracted")
115
  continue
 
82
  h, m, s = map(float, timestamp.split(':'))
83
  return int(h) * 3600 + int(m) * 60 + s
84
 
85
+ def extract_frames(video, start_time, end_time):
86
  frames = []
87
  start_seconds = convert_timestamp_to_seconds(start_time)
88
  end_seconds = convert_timestamp_to_seconds(end_time)
89
+ video_clip = video.subclip(start_seconds, end_seconds)
90
 
91
  for frame_time in range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 3)):
92
  frame = video_clip.get_frame(frame_time / video_clip.fps)
 
108
  text_features = model.get_text_features(**text_inputs).detach()
109
  positive_feature, negative_features = text_features[0], text_features[1:]
110
 
111
+ video = VideoFileClip(video_path)
112
+
113
  for scene_num, (start_time, end_time) in enumerate(scenes):
114
+ frames = extract_frames(video, start_time, end_time)
115
  if not frames:
116
  print(f"Scene {scene_num + 1}: Start={start_time}, End={end_time} - No frames extracted")
117
  continue