Skip to content

live callbacks for live-streams. #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions scenedetect/scene_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,19 @@ def get_event_list(self, base_timecode):
for start, end in self._event_list]


def _process_frame(self, frame_num, frame_im):
def _process_frame(self, frame_num, frame_im, callback=None):
# type(int, numpy.ndarray) -> None
""" Adds any cuts detected with the current frame to the cutting list. """
for detector in self._detector_list:
self._cutting_list += detector.process_frame(frame_num, frame_im)
cuts = detector.process_frame(frame_num, frame_im)
if cuts and callback:
callback(frame_im, frame_num)
self._cutting_list += cuts
for detector in self._sparse_detector_list:
self._event_list += detector.process_frame(frame_num, frame_im)
events = detector.process_frame(frame_num, frame_im)
if events and callback:
callback(frame_im, frame_num)
self._event_list += events


def _is_processing_required(self, frame_num):
Expand All @@ -516,9 +522,9 @@ def _post_process(self, frame_num):


def detect_scenes(self, frame_source, end_time=None, frame_skip=0,
show_progress=True):
show_progress=True, callback=None):
# type: (VideoManager, Union[int, FrameTimecode],
# Optional[Union[int, FrameTimecode]], Optional[bool]) -> int
# Optional[Union[int, FrameTimecode]], Optional[bool], optional[callable[numpy.ndarray]) -> int
""" Perform scene detection on the given frame_source using the added SceneDetectors.

Blocks until all frames in the frame_source have been processed. Results can
Expand All @@ -540,6 +546,7 @@ def detect_scenes(self, frame_source, end_time=None, frame_skip=0,
show_progress (bool): If True, and the ``tqdm`` module is available, displays
a progress bar with the progress, framerate, and expected time to
complete processing the video frame source.
callback ((image_ndarray, frame_num: int) -> None): If not None, called after each scene/event detected.
Returns:
int: Number of frames read and processed from the frame source.
Raises:
Expand Down Expand Up @@ -600,7 +607,7 @@ def detect_scenes(self, frame_source, end_time=None, frame_skip=0,

if not ret_val:
break
self._process_frame(self._num_frames + start_frame, frame_im)
self._process_frame(self._num_frames + start_frame, frame_im, callback)

curr_frame += 1
self._num_frames += 1
Expand Down