跳转至

client.fast_screenshot

fast_screenshot

类:

名称 描述
AdbFastScreenshots

AdbFastScreenshots

方法:

名称 描述
__init__

Capture Android device screen using ADB's screenrecord with high frame rate.

__init__

__init__(adb_path, device_serial, time_interval=179, width=1600, height=900, bitrate='20M', use_busybox=False, connect_to_device=True, screenshotbuffer=10, go_idle=0)

Capture Android device screen using ADB's screenrecord with high frame rate.

This class allows capturing the screen of an Android device using ADB's screenrecord command with an improved frame rate. It continuously captures frames from the device and provides them as NumPy arrays to the caller.

Args: adb_path (str): The path to the ADB executable. device_serial (str): The serial number of the target Android device. time_interval (int): The maximum duration, in seconds, for each screen recording session (up to a maximum of 180 seconds). After reaching this time limit, a new recording session automatically starts without causing interruptions to the user experience. width (int): The width of the captured screen. height (int): The height of the captured screen. bitrate (str): The bitrate for screen recording (e.g., "20M" for 20Mbps). use_busybox (bool): Whether to use BusyBox for base64 encoding. connect_to_device (bool): Whether to connect to the device using ADB. screenshotbuffer (int): The size of the frame buffer to store the last captured frames. go_idle (float): The idle time (in seconds) when no new frames are available. # higher value -> less fps, but also less CPU usage.

Attributes: stop_recording (bool): Control attribute to stop the screen capture.

Methods: stop_capture(): Stops the screen capture.

Usage: import cv2 from adbnativeblitz import AdbFastScreenshots

with AdbFastScreenshots(
    adb_path=r"C:\Android\android-sdk\platform-tools\adb.exe",
    device_serial="127.0.0.1:5555",
    time_interval=179,
    width=1600,
    height=900,
    bitrate="20M",
    use_busybox=False,
    connect_to_device=True,
    screenshotbuffer=10,
    go_idle=0,
) as adbscreen:
    for image in adbscreen:
        cv2.imshow("CV2 WINDOW", image)
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
cv2.destroyAllWindows()

Note: - The AdbFastScreenshots class should be used in a context manager (with statement). - The stop_capture() method can be called to stop the screen capture. - The frames are continuously captured and provided in the form of NumPy arrays. - The class aims to achieve a higher frame rate by avoiding slow subprocess creation for each screen capture session.