Skip to content

Commit

Permalink
Added Frame.timespan ⭐
Browse files Browse the repository at this point in the history
  • Loading branch information
NiiightmareXD committed Sep 14, 2024
1 parent 694f8ae commit 37e6989
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions windows-capture-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -402,6 +403,7 @@ impl GraphicsCaptureApiHandler for InnerNativeWindowsCapture {
width,
height,
stop_list.clone(),
timespan,
),
)
.map_err(InnerNativeWindowsCaptureError::PythonError)?;
Expand Down
14 changes: 9 additions & 5 deletions windows-capture-python/windows_capture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Frame:
Width Of The Frame
height : int
Height Of The Frame
timespan : int
Timespan Of The Frame
Methods
-------
Expand All @@ -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"""
Expand All @@ -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
Expand All @@ -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
)


Expand Down Expand Up @@ -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"""
Expand All @@ -236,15 +240,15 @@ 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(
ctypes.cast(buf, ctypes.POINTER(ctypes.c_uint8)),
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(
Expand Down

0 comments on commit 37e6989

Please sign in to comment.