From 068f3beefa38533ed85d71194cac024ac43e65ac Mon Sep 17 00:00:00 2001 From: JK-rez Date: Sun, 2 Feb 2025 13:12:32 +0000 Subject: [PATCH] modified videodataset for window multiprocessing --- monai/data/video_dataset.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/monai/data/video_dataset.py b/monai/data/video_dataset.py index 031e85db26..511235b5df 100644 --- a/monai/data/video_dataset.py +++ b/monai/data/video_dataset.py @@ -140,7 +140,13 @@ def get_fps(self) -> int: def get_frame(self) -> Any: """Get next frame. For a file, this will be the next frame, whereas for a camera source, it will be the next available frame.""" - ret, frame = self._get_cap().read() + #Assign explicit videocapture object to cap to realease file to avoid error in multiprocessing + if self.multiprocessing: + cap = self._get_cap() + ret, frame = cap.read() + cap.release() + else: + ret, frame = self._get_cap().read() if not ret: raise RuntimeError("Failed to read frame.") # Switch color order if desired