def __init__( self, path: typing.Union[str, os.PathLike], pre_load: bool = None, fps: int = None, *_, **__, ): assert os.path.isfile(path), f"video [{path}] not existed" self.path: str = str(path) self.data: typing.Optional[typing.Tuple[VideoFrame]] = tuple() self._hook_list: typing.List["BaseHook"] = [] self.fps: int = fps if fps: video_path = os.path.join(tempfile.mkdtemp(), f"tmp_{fps}.mp4") logger.debug(f"convert video, and bind path to {video_path}") toolbox.fps_convert(fps, self.path, video_path, constants.FFMPEG) self.path = video_path with toolbox.video_capture(self.path) as cap: self.frame_count = toolbox.get_frame_count(cap) self.frame_size = toolbox.get_frame_size(cap) if pre_load: self.load_frames() logger.info( f"video object generated, length: {self.frame_count}, size: {self.frame_size}" )
def test_convert_video(): target_fps: int = 30 ret = toolbox.fps_convert(target_fps, VIDEO_PATH, os.path.join(PROJECT_PATH, f"{target_fps}.mp4")) assert not ret