Repository navigation
detect_scenes seems to fail when used with callback #416
Copy link
Copy link
Closed
Description
Description:
After running for about 1/3 of the video, the code throws the following unexpected exception. The same run works fine if the callback on detect_scenes is removed.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[20], line 9
6 def on_new_scene(frame_img: np.ndarray, frame_num: int):
7 print(frame_num, video.duration.get_frames())
----> 9 scene_manager.detect_scenes(video, callback=on_new_scene)
11 scene_manager.get_scene_list()
File ~/anaconda3/envs/jupyter/lib/python3.10/site-packages/scenedetect/scene_manager.py:889, in SceneManager.detect_scenes(self, video, duration, end_time, frame_skip, show_progress, callback, frame_source)
887 if not next_frame is None:
888 frame_im = next_frame
--> 889 new_cuts = self._process_frame(position.frame_num, frame_im, callback)
890 if progress_bar is not None:
891 if new_cuts:
File ~/anaconda3/envs/jupyter/lib/python3.10/site-packages/scenedetect/scene_manager.py:762, in SceneManager._process_frame(self, frame_num, frame_im, callback)
760 for cut_frame_num in cuts:
761 buffer_index = cut_frame_num - (frame_num + 1)
--> 762 callback(self._frame_buffer[buffer_index], cut_frame_num)
763 for detector in self._sparse_detector_list:
764 events = detector.process_frame(frame_num, frame_im)
IndexError: list index out of rangeExample:
Include code samples that demonstrate the issue:
import scenedetect
import numpy as np
scene_manager = scenedetect.SceneManager()
scene_manager.add_detector(scenedetect.ContentDetector())
def on_new_scene(frame_img: np.ndarray, frame_num: int):
print(frame_num, video.duration.get_frames())
scene_manager.detect_scenes(video, callback=on_new_scene)
scene_manager.get_scene_list()Environment:
[PySceneDetect] PySceneDetect 0.6.4
System Info
------------------------------------------------------------
OS Linux-5.15.0-119-generic-x86_64-with-glibc2.35
Python 3.10.14
Packages
------------------------------------------------------------
av 12.0.0
click 8.1.7
cv2 4.9.0
moviepy Not Installed
numpy 1.26.4
platformdirs 3.10.0
scenedetect 0.6.4
tqdm 4.66.2
Tools
------------------------------------------------------------
ffmpeg 4.3
mkvmerge Not Installed
Media/Files:
I cannot share the video file, but it is similar to this one: https://www.youtube.com/watch?app=desktop&v=2JIfwsv28Es
Reacted by Brandon Castellano
Activity
Breakthrough commentedon Sep 3, 2024
Thanks for sharing this, there's definitely a bug here. Will look into this as soon as possible.
I suspect the fix will be closely tied with resolving #408.
Breakthrough commentedon Sep 3, 2024
Sorry this is unrelated to that actually. The issue is that with the new flash filter, ContentDetector isn't reporting the correct event buffer size. Will have this fixed for the next release, sorry for the troubles. In the meantime here's a few workarounds.
Workarounds
Use
AdaptiveDetectorinstead:Set flash filter mode to SUPPRESS:
Root Cause
This new filter was added as part of #35. The underlying issue is because
ContentDetectordoesn't override theevent_buffer_lengthproperty, but this is required with the new filter mode.Thanks for the report!
[detectors] Fix not compensating for filter buffer length
[detectors] Fix not compensating for filter buffer length (Breakthrou…