PyAV `av.InputContainer` backend.
| 35 | |
| 36 | |
| 37 | class VideoStreamAv(VideoStream): |
| 38 | """PyAV `av.InputContainer` backend.""" |
| 39 | |
| 40 | # TODO: Investigate adding an accurate_duration option to backends to calculate the duration |
| 41 | # with higher precision. Sometimes it doesn't exactly match what the codec or VLC reports, |
| 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 |
no outgoing calls