From 37e69893c8ea51467381533e16b277562f278697 Mon Sep 17 00:00:00 2001 From: NiiightmareXD Date: Sat, 14 Sep 2024 10:46:52 +0330 Subject: [PATCH] =?UTF-8?q?Added=20Frame.timespan=20=E2=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- windows-capture-python/src/lib.rs | 2 ++ windows-capture-python/windows_capture/__init__.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/windows-capture-python/src/lib.rs b/windows-capture-python/src/lib.rs index 6e40ebe..8c7ebeb 100644 --- a/windows-capture-python/src/lib.rs +++ b/windows-capture-python/src/lib.rs @@ -383,6 +383,7 @@ impl GraphicsCaptureApiHandler for InnerNativeWindowsCapture { ) -> Result<(), Self::Error> { let width = frame.width(); let height = frame.height(); + let timespan = frame.timespan().Duration; let mut buffer = frame .buffer() .map_err(InnerNativeWindowsCaptureError::FrameProcessError)?; @@ -402,6 +403,7 @@ impl GraphicsCaptureApiHandler for InnerNativeWindowsCapture { width, height, stop_list.clone(), + timespan, ), ) .map_err(InnerNativeWindowsCaptureError::PythonError)?; diff --git a/windows-capture-python/windows_capture/__init__.py b/windows-capture-python/windows_capture/__init__.py index d602306..63797be 100644 --- a/windows-capture-python/windows_capture/__init__.py +++ b/windows-capture-python/windows_capture/__init__.py @@ -22,6 +22,8 @@ class Frame: Width Of The Frame height : int Height Of The Frame + timespan : int + Timespan Of The Frame Methods ------- @@ -35,11 +37,12 @@ class Frame: Converts The self.frame_buffer Pixel Type To Bgr Instead Of Bgra """ - def __init__(self, frame_buffer: numpy.ndarray, width: int, height: int) -> None: + def __init__(self, frame_buffer: numpy.ndarray, width: int, height: int, timespan: int) -> None: """Constructs All The Necessary Attributes For The Frame Object""" self.frame_buffer = frame_buffer self.width = width self.height = height + self.timespan = timespan def save_as_image(self, path: str) -> None: """Save The Frame As An Image To The Specified Path""" @@ -49,7 +52,7 @@ def convert_to_bgr(self) -> "Frame": """Converts The self.frame_buffer Pixel Type To Bgr Instead Of Bgra""" bgr_frame_buffer = self.frame_buffer[:, :, :3] - return Frame(bgr_frame_buffer, self.width, self.height) + return Frame(bgr_frame_buffer, self.width, self.height, self.timespan) def crop( self, start_width: int, start_height: int, end_width: int, end_height: int @@ -60,7 +63,7 @@ def crop( ] return Frame( - cropped_frame_buffer, end_width - start_width, end_height - start_height + cropped_frame_buffer, end_width - start_width, end_height - start_height, self.timespan ) @@ -223,6 +226,7 @@ def on_frame_arrived( width: int, height: int, stop_list: list, + timespan: int, ) -> None: """This Method Is Called Before The on_frame_arrived Callback Function To Prepare Data""" @@ -236,7 +240,7 @@ def on_frame_arrived( shape=(height, width, 4), ) - frame = Frame(ndarray, width, height) + frame = Frame(ndarray, width, height, timespan) self.frame_handler(frame, internal_capture_control) else: ndarray = numpy.ctypeslib.as_array( @@ -244,7 +248,7 @@ def on_frame_arrived( shape=(height, row_pitch), )[:, : width * 4].reshape(height, width, 4) - frame = Frame(ndarray, width, height) + frame = Frame(ndarray, width, height, timespan) self.frame_handler(frame, internal_capture_control) self.frame_handler(