From a79a0b6dde22d8ae8f6031b03030f9265a6d167f Mon Sep 17 00:00:00 2001 From: Nathan van Beelen Date: Wed, 9 Aug 2023 11:16:15 +0200 Subject: [PATCH 1/5] Retrieve frame count differently --- stytra/offline/track_video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stytra/offline/track_video.py b/stytra/offline/track_video.py index 0984d8f5..f6ffd7b8 100644 --- a/stytra/offline/track_video.py +++ b/stytra/offline/track_video.py @@ -71,7 +71,7 @@ def track(self): output_name = str(self.output_path) + "." + fileformat self.diag_track.show() - l = reader.get_length() + l = reader.count_frames() if not (0 < l < 100000): l = 1 self.diag_track.prog_track.setMaximum(l) From 58e8b1f9932c51e820d7c7b805d89699d5acd75f Mon Sep 17 00:00:00 2001 From: Nathan van Beelen Date: Wed, 9 Aug 2023 11:46:22 +0200 Subject: [PATCH 2/5] Make frame_count() is available --- stytra/offline/track_video.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stytra/offline/track_video.py b/stytra/offline/track_video.py index f6ffd7b8..bbde78b2 100644 --- a/stytra/offline/track_video.py +++ b/stytra/offline/track_video.py @@ -65,13 +65,16 @@ def track(self): fileformat = self.cmb_fmt.currentText() self.exp.camera.kill_event.set() - reader = imageio.get_reader(str(self.input_path)) + reader = imageio.get_reader(str(self.input_path), 'ffmpeg') data = [] self.exp.window_main.stream_plot.toggle_freeze() output_name = str(self.output_path) + "." + fileformat self.diag_track.show() - l = reader.count_frames() + if (hasattr(reader, 'count_frames')): + l = reader.count_frames() + else: + l = reader.get_length() if not (0 < l < 100000): l = 1 self.diag_track.prog_track.setMaximum(l) From 9956203643dd1912392c19adeff20601a53e3842 Mon Sep 17 00:00:00 2001 From: Nathan van Beelen Date: Wed, 9 Aug 2023 11:54:34 +0200 Subject: [PATCH 3/5] Black formatting --- stytra/offline/track_video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stytra/offline/track_video.py b/stytra/offline/track_video.py index bbde78b2..8201be2e 100644 --- a/stytra/offline/track_video.py +++ b/stytra/offline/track_video.py @@ -65,13 +65,13 @@ def track(self): fileformat = self.cmb_fmt.currentText() self.exp.camera.kill_event.set() - reader = imageio.get_reader(str(self.input_path), 'ffmpeg') + reader = imageio.get_reader(str(self.input_path), "ffmpeg") data = [] self.exp.window_main.stream_plot.toggle_freeze() output_name = str(self.output_path) + "." + fileformat self.diag_track.show() - if (hasattr(reader, 'count_frames')): + if hasattr(reader, "count_frames"): l = reader.count_frames() else: l = reader.get_length() From 5a6b956c9f6f8bdd66d35a6cbe1a8d5625b1e84c Mon Sep 17 00:00:00 2001 From: Nathan van Beelen Date: Wed, 9 Aug 2023 14:44:06 +0200 Subject: [PATCH 4/5] Prevent hanging/crashing after offline analysis This is a slight modification of the changes proposed by @MadCatX. --- stytra/experiments/tracking_experiments.py | 3 ++- stytra/hardware/video/__init__.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stytra/experiments/tracking_experiments.py b/stytra/experiments/tracking_experiments.py index 894c5e46..787b92b6 100644 --- a/stytra/experiments/tracking_experiments.py +++ b/stytra/experiments/tracking_experiments.py @@ -161,7 +161,8 @@ def wrap_up(self, *args, **kwargs) -> None: for q in [self.camera.frame_queue]: q.clear() - self.camera.join() + if self.camera.is_alive(): + self.camera.join() def _setup_frame_dispatcher(self, recording_event: Event = None) -> DispatchProcess: """ diff --git a/stytra/hardware/video/__init__.py b/stytra/hardware/video/__init__.py index 8e801298..84978932 100644 --- a/stytra/hardware/video/__init__.py +++ b/stytra/hardware/video/__init__.py @@ -331,8 +331,11 @@ def run(self): container.streams.video[0].thread_count = 1 prt = None - while self.loop: + while not self.kill_event.is_set(): for framedata in container.decode(video=0): + if self.kill_event.is_set(): + break + messages = [] if self.paused: frame = self.old_frame From d6fc1a0db532115dd3c846630230d41895f4c20f Mon Sep 17 00:00:00 2001 From: Nathan van Beelen Date: Wed, 9 Aug 2023 15:28:54 +0200 Subject: [PATCH 5/5] Remove video frame number constraint --- stytra/offline/track_video.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/stytra/offline/track_video.py b/stytra/offline/track_video.py index 8201be2e..0e0efb4b 100644 --- a/stytra/offline/track_video.py +++ b/stytra/offline/track_video.py @@ -75,8 +75,6 @@ def track(self): l = reader.count_frames() else: l = reader.get_length() - if not (0 < l < 100000): - l = 1 self.diag_track.prog_track.setMaximum(l) self.diag_track.lbl_status.setText("Tracking to " + output_name)