MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / __init__

Method __init__

scenedetect/backends/pyav.py:44–150  ·  view source on GitHub ↗

Open a video by path. .. warning:: Using `threading_mode` with `suppress_output = True` can cause lockups in your application. See the PyAV documentation for details: https://pyav.org/docs/stable/overview/caveats.html#sub-interpeters Arguments:

(
        self,
        path_or_io: StrPath | ty.BinaryIO,
        frame_rate: FrameRate | None = None,
        name: str | None = None,
        threading_mode: str | None = None,
        suppress_output: bool = False,
        framerate: FrameRate | None = None,
    )

Source from the content-addressed store, hash-verified

42 # but we can try to seek to the end of the video first to determine it. Investigate how VLC
43 # calculates the end time.
44 def __init__(
45 self,
46 path_or_io: StrPath | ty.BinaryIO,
47 frame_rate: FrameRate | None = None,
48 name: str | None = None,
49 threading_mode: str | None = None,
50 suppress_output: bool = False,
51 framerate: FrameRate | None = None,
52 ):
53 """Open a video by path.
54
55 .. warning::
56
57 Using `threading_mode` with `suppress_output = True` can cause lockups in your
58 application. See the PyAV documentation for details:
59 https://pyav.org/docs/stable/overview/caveats.html#sub-interpeters
60
61 Arguments:
62 path_or_io: Path to the video, or a file-like object.
63 frame_rate: If set, overrides the detected frame rate. Takes precedence over
64 `framerate`.
65 name: Overrides the `name` property derived from the video path. Should be set if
66 `path_or_io` is a file-like object.
67 threading_mode: The PyAV video stream `thread_type`. See av.codec.context.ThreadType
68 for valid threading modes ('AUTO', 'FRAME', 'NONE', and 'SLICE'). If this mode is
69 'AUTO' or 'FRAME' and not all frames have been decoded, the video will be reopened
70 if seekable, and the remaining frames decoded in single-threaded mode.
71 suppress_output: If False, ffmpeg output will be sent to stdout/stderr by calling
72 `av.logging.restore_default_callback()` before any other library calls. If True
73 the application may deadlock if threading_mode is set. See the PyAV documentation
74 for details: https://pyav.org/docs/stable/overview/caveats.html#sub-interpeters
75 framerate: [DEPRECATED] Use `frame_rate` instead. Retained as a deprecated
76 alias for backwards compatibility; ignored when `frame_rate` is provided.
77
78 Raises:
79 OSError: file could not be found or access was denied
80 VideoOpenFailure: video could not be opened (may be corrupted)
81 ValueError: specified frame rate is invalid
82 """
83 # TODO(https://scenedetect.com/issues/258): See what
84 # `self._container.discard_corrupt = True` does with corrupt videos.
85 super().__init__()
86
87 # TODO(https://scenedetect.com/issue/548): emit DeprecationWarning when `framerate=` is
88 # used, once internal callers and downstream users have had a release to migrate.
89 if frame_rate is None:
90 frame_rate = framerate
91 # Ensure specified frame rate is valid if set.
92 if frame_rate is not None and frame_rate < MAX_FPS_DELTA:
93 raise ValueError(f"Specified frame rate ({float(frame_rate):f}) is invalid!")
94
95 self._name = "" if name is None else name
96 self._path = ""
97 self._frame: av.VideoFrame | None = None
98 self._decoder: ty.Generator | None = None
99 self._reopened = True
100
101 if threading_mode:

Callers

nothing calls this directly

Calls 5

_get_durationMethod · 0.95
get_file_nameFunction · 0.90
VideoOpenFailureClass · 0.90
framerate_to_fractionFunction · 0.90

Tested by

no test coverage detected