original_docstring: Use `pyscenedetect <https://pyscenedetect.readthedocs.io/en/latest/>`_
      to split scenes in a video.
  
      Parameters
      ----------
      videos: str, VideoStream, or list<str>
          The video to split. If a list is given, assume they are segments of a
          longer video
      threshold: float, default 30.0
          Detection threshold (i.e., ContentDetector(threshold=threshold))
      raise_on_error: bool, default True
          Set to False to suppress exceptions during the detection run (note that
          import errors will still be raised)
      
docstring: Use `pyscenedetect `_
  to split scenes in a video.
  
  Parameters
  
  str, VideoStream, or list
  The video to split. If a list is given, assume they are segments of a
  longer video
  threshold: float, default 30.0
  Detection threshold )
  raise_on_error: bool, default True
  Set to False to suppress exceptions during the detection run (note that
  import errors will still be raised)
docstring_tokens: Use ` pyscenedetect ` _ to split scenes in a video . Parameters str VideoStream or list The video to split . If a list is given assume they are segments of a longer video threshold : float default 30 . 0 Detection threshold ) raise_on_error : bool default True Set to False to suppress exceptions during the detection run ( note that import errors will still be raised )
code: def scene_detect(
      videos: Union[str, VideoStream, list], threshold=30.0, raise_on_error=True
  ):
      """Use `pyscenedetect <https://pyscenedetect.readthedocs.io/en/latest/>`_
      to split scenes in a video.
  
      Parameters
      ----------
      videos: str, VideoStream, or list<str>
          The video to split. If a list is given, assume they are segments of a
          longer video
      threshold: float, default 30.0
          Detection threshold (i.e., ContentDetector(threshold=threshold))
      raise_on_error: bool, default True
          Set to False to suppress exceptions during the detection run (note that
          import errors will still be raised)
      """
      try:
          from scenedetect.detectors import ContentDetector
          from scenedetect.scene_manager import SceneManager
          from scenedetect.video_manager import VideoManager
      except ImportError as e:
          raise ImportError(
              (
                  "Please make sure you have pyscenedetect installed "
                  "via `pip install rikai[video]`"
              )
          )
      video_manager = None
      try:
          if isinstance(videos, VideoStream):
              video_path = [videos.uri]
          elif isinstance(videos, list):
              video_path = videos
          else:
              video_path = [videos]
  
          video_manager = VideoManager(normalize_uri(video_path))
          scene_manager = SceneManager()  # TODO add StatsManager later
          scene_manager.add_detector(ContentDetector(threshold=threshold))
          video_manager.set_downscale_factor()
          video_manager.start()
          scene_manager.detect_scenes(frame_source=video_manager)
          scene_list = scene_manager.get_scene_list()
          return [
              {
                  "start": {
                      "frame_num": s[0].frame_num,
                      "frame_pos_sec": s[0].get_seconds(),
                  },
                  "end": {
                      "frame_num": s[1].frame_num,
                      "frame_pos_sec": s[1].get_seconds(),
                  },
              }
              for s in scene_list
          ]
      except Exception as e:
          if raise_on_error:
              raise e
          else:
              return None
      finally:
          if video_manager is not None:
              video_manager.release()
code_tokens: def scene_detect ( videos : Union [ str , VideoStream , list ] , threshold = 30.0 , raise_on_error = True ) : try : from scenedetect . detectors import ContentDetector from scenedetect . scene_manager import SceneManager from scenedetect . video_manager import VideoManager except ImportError as e : raise ImportError ( ( "Please make sure you have pyscenedetect installed " "via `pip install rikai[video]`" ) ) video_manager = None try : if isinstance ( videos , VideoStream ) : video_path = [ videos . uri ] elif isinstance ( videos , list ) : video_path = videos else : video_path = [ videos ] video_manager = VideoManager ( normalize_uri ( video_path ) ) scene_manager = SceneManager ( ) scene_manager . add_detector ( ContentDetector ( threshold = threshold ) ) video_manager . set_downscale_factor ( ) video_manager . start ( ) scene_manager . detect_scenes ( frame_source = video_manager ) scene_list = scene_manager . get_scene_list ( ) return [ { "start" : { "frame_num" : s [ 0 ] . frame_num , "frame_pos_sec" : s [ 0 ] . get_seconds ( ) , } , "end" : { "frame_num" : s [ 1 ] . frame_num , "frame_pos_sec" : s [ 1 ] . get_seconds ( ) , } , } for s in scene_list ] except Exception as e : if raise_on_error : raise e else : return None finally : if video_manager is not None : video_manager . release ( )
short_docstring: Use `pyscenedetect <https://pyscenedetect.readthedocs.io/en/latest/>`_
  to split scenes in a video.
short_docstring_tokens: Use ` pyscenedetect <https : // pyscenedetect . readthedocs . io / en / latest / > ` _ to split scenes in a video .
comment: """Use `pyscenedetect <https://pyscenedetect.readthedocs.io/en/latest/>`_
      to split scenes in a video.
  
      Parameters
      ----------
      videos: str, VideoStream, or list<str>
          The video to split. If a list is given, assume they are segments of a
          longer video
      threshold: float, default 30.0
          Detection threshold (i.e., ContentDetector(threshold=threshold))
      raise_on_error: bool, default True
          Set to False to suppress exceptions during the detection run (note that
          import errors will still be raised)
      """$SEP$# TODO add StatsManager later