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

Method get_available_codecs

monai/data/video_dataset.py:168–185  ·  view source on GitHub ↗

Try different codecs, see which are available. Returns a dictionary with of available codecs with codecs as keys and file extensions as values.

()

Source from the content-addressed store, hash-verified

166
167 @staticmethod
168 def get_available_codecs() -> dict[str, str]:
169 """Try different codecs, see which are available.
170 Returns a dictionary with of available codecs with codecs as keys and file extensions as values."""
171 if not has_cv2:
172 return {}
173 all_codecs = {"mp4v": ".mp4", "X264": ".avi", "H264": ".mp4", "MP42": ".mp4", "MJPG": ".mjpeg", "DIVX": ".avi"}
174 codecs = {}
175 with SuppressStderr():
176 with tempfile.TemporaryDirectory() as tmp_dir:
177 for codec, ext in all_codecs.items():
178 writer = cv2.VideoWriter()
179 fname = os.path.join(tmp_dir, f"test{ext}")
180 fourcc = cv2.VideoWriter_fourcc(*codec) # type: ignore[attr-defined]
181 noviderr = writer.open(fname, fourcc, 1, (10, 10))
182 if noviderr:
183 codecs[codec] = ext
184 writer.release()
185 return codecs
186
187 def get_num_frames(self) -> int:
188 """

Callers 2

setUpClassMethod · 0.80
test_available_codecsMethod · 0.80

Calls 1

SuppressStderrClass · 0.85

Tested by 2

setUpClassMethod · 0.64
test_available_codecsMethod · 0.64