docstr: 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.
docstr_tok: ["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","."]
code: def open_video(video_source: str | int):
      """
      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.
      """
      if isinstance(video_source, str) and not os.path.isfile(
          video_source
      ):
          raise RuntimeError(
              "Video file does not exist: " + video_source
          )
      with SuppressStderr():
          cap = cv2.VideoCapture(video_source)
      if not cap.isOpened():
          raise RuntimeError(f"Failed to open video: {video_source}")
      return cap
  
imports: from __future__ import annotations
  import os
  import sys
  import tempfile
  from collections.abc import Callable
  from typing import TYPE_CHECKING, Any
  import numpy
  from torch.utils.data import Dataset, IterableDataset
  from monai.utils.enums import ColorOrder
  from monai.utils.module import optional_import
label_desc: Use image node_id 2 for calling the VideoDataset obj's underlying member method code with example usage: obj.open_video(video_source) and returns: cap