MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / open_video

Method open_video

monai/data/video_dataset.py:113–130  ·  view source on GitHub ↗

Use OpenCV to open a video source from either file or capture device. Args: video_source: filename or index referring to capture device. Raises: RuntimeError: Source is a file but file not found. RuntimeError: Failed to open source.

(video_source: str | int)

Source from the content-addressed store, hash-verified

111
112 @staticmethod
113 def open_video(video_source: str | int):
114 """
115 Use OpenCV to open a video source from either file or capture device.
116
117 Args:
118 video_source: filename or index referring to capture device.
119
120 Raises:
121 RuntimeError: Source is a file but file not found.
122 RuntimeError: Failed to open source.
123 """
124 if isinstance(video_source, str) and not os.path.isfile(video_source):
125 raise RuntimeError("Video file does not exist: " + video_source)
126 with SuppressStderr():
127 cap = cv2.VideoCapture(video_source)
128 if not cap.isOpened():
129 raise RuntimeError(f"Failed to open video: {video_source}")
130 return cap
131
132 def _get_cap(self):
133 """Return the cap. If multiprocessing, create a new one. Else return the one from construction time."""

Callers 2

__init__Method · 0.95
_get_capMethod · 0.95

Calls 1

SuppressStderrClass · 0.85

Tested by

no test coverage detected