jschwab21 commited on
Commit
bafb131
·
verified ·
1 Parent(s): b86b5dd

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +17 -21
video_processing.py CHANGED
@@ -44,32 +44,28 @@ def ensure_video_format(video_path):
44
  return None
45
 
46
  def find_scenes(video_path):
47
- print(f"Processing video for scene detection: {video_path}")
48
- video_path = ensure_video_format(video_path)
49
- print(f"Video formatted at path: {video_path}")
50
-
51
- try:
52
- video_manager = open_video(video_path)
53
- except Exception as e:
54
- print(f"Failed to open video: {e}")
55
- return []
56
-
57
  scene_manager = SceneManager()
58
- scene_manager.add_detector(ContentDetector(threshold=30.0))
59
 
60
- try:
61
- scene_manager.detect_scenes(video_manager)
62
- except Exception as e:
63
- print(f"Error during scene detection: {e}")
64
- return []
65
 
 
 
 
 
 
 
 
66
  scene_list = scene_manager.get_scene_list()
67
- if not scene_list:
68
- print("No scenes detected.")
69
- return []
70
 
71
- scenes = [(scene[0].get_seconds(), scene[1].get_seconds()) for scene in scene_list]
72
- print(f"Detected scenes: {scenes}")
 
73
  return scenes
74
 
75
 
 
44
  return None
45
 
46
  def find_scenes(video_path):
47
+ # Ensure video path is a list, as required by VideoManager
48
+ video_manager = VideoManager([video_path])
 
 
 
 
 
 
 
 
49
  scene_manager = SceneManager()
 
50
 
51
+ # Add ContentDetector with an adjusted threshold for finer segmentation
52
+ scene_manager.add_detector(ContentDetector(threshold=33))
 
 
 
53
 
54
+ # Begin processing the video
55
+ video_manager.start()
56
+
57
+ # Detect scenes
58
+ scene_manager.detect_scenes(frame_source=video_manager)
59
+
60
+ # Get the list of detected scenes
61
  scene_list = scene_manager.get_scene_list()
62
+
63
+ # Release the video manager resources
64
+ video_manager.release()
65
 
66
+ # Convert scene list to timecodes
67
+ scenes = [(start.get_timecode(), end.get_timecode()) for start, end in scene_list]
68
+
69
  return scenes
70
 
71