jschwab21 commited on
Commit
6bcace2
·
verified ·
1 Parent(s): b954aad

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +4 -8
video_processing.py CHANGED
@@ -66,19 +66,15 @@ def download_video(url):
66
  def sanitize_filename(filename):
67
  return "".join([c if c.isalnum() or c in " .-_()" else "_" for c in filename])
68
 
69
- def find_scenes(video_path, sample_rate=3, downscale_factor=2.2):
70
  video_manager = VideoManager([video_path])
71
  scene_manager = SceneManager()
72
- scene_manager.add_detector(ContentDetector(threshold=33))
73
-
74
- video_manager.set_downscale_factor(downscale_factor)
75
- video_manager.set_duration(start_time=None, end_time=None, frame_skip=sample_rate) # Skip frames
76
  video_manager.start()
77
-
78
  scene_manager.detect_scenes(frame_source=video_manager)
79
  scene_list = scene_manager.get_scene_list()
80
  video_manager.release()
81
-
82
  scenes = [(start.get_timecode(), end.get_timecode()) for start, end in scene_list]
83
  return scenes
84
 
@@ -92,7 +88,7 @@ def extract_frames(video_path, start_time, end_time):
92
  end_seconds = convert_timestamp_to_seconds(end_time)
93
  video_clip = VideoFileClip(video_path).subclip(start_seconds, end_seconds)
94
  # Extract more frames: every frame in the scene
95
- for frame_time in range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 10)):
96
  frame = video_clip.get_frame(frame_time / video_clip.fps)
97
  frames.append(frame)
98
  return frames
 
66
  def sanitize_filename(filename):
67
  return "".join([c if c.isalnum() or c in " .-_()" else "_" for c in filename])
68
 
69
+ def find_scenes(video_path, downscale_factor=2.2):
70
  video_manager = VideoManager([video_path])
71
  scene_manager = SceneManager()
72
+ scene_manager.add_detector(ContentDetector(threshold=33)) # Adjusted threshold for finer segmentation
73
+ video_manager.set_downscale_factor(donwscale_factor)
 
 
74
  video_manager.start()
 
75
  scene_manager.detect_scenes(frame_source=video_manager)
76
  scene_list = scene_manager.get_scene_list()
77
  video_manager.release()
 
78
  scenes = [(start.get_timecode(), end.get_timecode()) for start, end in scene_list]
79
  return scenes
80
 
 
88
  end_seconds = convert_timestamp_to_seconds(end_time)
89
  video_clip = VideoFileClip(video_path).subclip(start_seconds, end_seconds)
90
  # Extract more frames: every frame in the scene
91
+ for frame_time in range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 20)):
92
  frame = video_clip.get_frame(frame_time / video_clip.fps)
93
  frames.append(frame)
94
  return frames