Skip to main content

ADB - The fastest screenshots - scrcpy stream directly to NumPy (without scrcpy.exe) - no root required!

Project description

ADB - Fastest screenshots - scrcpy raw stream directly to NumPy (without scrcpy.exe) - no root required!

Tested against Windows 10 / Python 3.10 / Anaconda

pip install adbblitz

with Google Pixel 6 - not rooted

with Bluestacks 5 - not rooted

TCP - Taking multiple screenshots

If you want to take multiple screenshots using a TCP connection, you can use AdbShotTCP

Import the modules

from adbblitz import AdbShotUSB, AdbShotTCP

Use the with statement to create an instance of the AdbShotTCP class and specify the required parameters

Within the with block, you can iterate over the shosho object to capture screenshots After everything is done, the socket connection will be closed, you don't have to take care about anything.

from adbblitz import AdbShotUSB, AdbShotTCP
import numpy as np
from time import time
import cv2


with AdbShotTCP(
    device_serial="localhost:5555",
    adb_path=r"C:\ProgramData\chocolatey\lib\scrcpy\tools\scrcpy-win64-v2.0\adb.exe",
    ip="127.0.0.1",
    port=5555,
    max_frame_rate=60,
    max_video_width=960,
    scrcpy_server_version="2.0",
    forward_port=None,
    frame_buffer=24,
    byte_package_size=131072,
    sleep_after_exception=0.01,
    log_level="info",
    lock_video_orientation=0,
) as shosho:
framecounter = 0
stop_at_frame = None
fps = 0
start_time = time()
show_screenshot = True
# print(shosho)
for bi in shosho:
    if bi.dtype == np.uint16:
        continue
    cv2.imshow("title", bi)
    if cv2.waitKey(25) & 0xFF == ord("q"):
        # cv2.destroyAllWindows()
        # shosho.quit()
        break
    fps += 1
print(f"fast_ctypes_screenshots: {fps / (time() - start_time)}")

TCP - Taking one screenshot at the time

If you take only one screenshot, the connection will stay open until you call AdbShotTCP.quit()

a = AdbShotTCP(
	device_serial="localhost:5555",
	adb_path=r"C:\ProgramData\chocolatey\lib\scrcpy\tools\scrcpy-win64-v2.0\adb.exe",
	ip="127.0.0.1",
	port=5037,
	sleep_after_exception=0.05,
	frame_buffer=4,
	lock_video_orientation=0,
	max_frame_rate=0,
	byte_package_size=131072,
	scrcpy_server_version="2.0",
	log_level="info",
	max_video_width=0,
	start_server=True,
	connect_to_device=True,
)

scr = a.get_one_screenshot()
scr.quit() # closes the connection
	

USB - Taking multiple screenshots

Same thing for USB

with AdbShotUSB(
    device_serial="xxxxx",
    adb_path=r"C:\ProgramData\chocolatey\lib\scrcpy\tools\scrcpy-win64-v2.0\adb.exe",
    adb_host_address="127.0.0.1",
    adb_host_port=5037,
    sleep_after_exception=0.05,
    frame_buffer=4,
    lock_video_orientation=0,
    max_frame_rate=0,
    byte_package_size=131072,
    scrcpy_server_version="2.0",
    log_level="info",
    max_video_width=0,
    start_server=True,
    connect_to_device=True,
) as self:
    start_time, fps = time(), 0
    for bi in self:
        if bi.dtype == np.uint16:
            continue
        cv2.imshow("test", bi)
        fps += 1
        if cv2.waitKey(25) & 0xFF == ord("q"):
            cv2.destroyAllWindows()
            break
    print(f"FPS: {fps / (time() - start_time)}")
    cv2.destroyAllWindows()

USB - Taking one screenshot at the time

su=AdbShotUSB(
            device_serial="xxxxxx",
            adb_path=r"C:\ProgramData\chocolatey\lib\scrcpy\tools\scrcpy-win64-v2.0\adb.exe",
            adb_host_address="127.0.0.1",
            adb_host_port=5037,
            sleep_after_exception=0.05,
            frame_buffer=4,
            lock_video_orientation=0,
            max_frame_rate=0,
            byte_package_size=131072,
            scrcpy_server_version="2.0",
            log_level="info",
            max_video_width=0,
            start_server=True,
            connect_to_device=True,
        )
scr=su.get_one_screenshot()
scr.quit() # closes the connection

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adbblitz-0.10.tar.gz (83.5 kB view details)

Uploaded Source

Built Distribution

adbblitz-0.10-py3-none-any.whl (81.1 kB view details)

Uploaded Python 3

File details

Details for the file adbblitz-0.10.tar.gz.

File metadata

  • Download URL: adbblitz-0.10.tar.gz
  • Upload date:
  • Size: 83.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for adbblitz-0.10.tar.gz
Algorithm Hash digest
SHA256 b3dbdf5f4ff40c3e5375a451d8d6ad70bbd96d717eb517871627b3be5bc32b04
MD5 b8b6939f66299d38199f2b2c8f0c0141
BLAKE2b-256 5a3e92e0399fba5c6c75d5af6e8f4d103ac893918138acc4ce66ab89e5c38c8e

See more details on using hashes here.

File details

Details for the file adbblitz-0.10-py3-none-any.whl.

File metadata

  • Download URL: adbblitz-0.10-py3-none-any.whl
  • Upload date:
  • Size: 81.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for adbblitz-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 58135a0780cee4255ccd30efd65bab35bd2202b271a9be15d4ad50d90dbf9f85
MD5 fff7c06004f5386783ecc6073bd08efb
BLAKE2b-256 95d5d7fcbfcd6e485fe848f303942fc82af9991ab84d7b3fef1574f0523c4f8f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page