Skip to main content

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

Metadata

Release files for adbblitz 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adbblitz 0.10
File Size Uploaded Provenance Actions
adbblitz-0.10.tar.gz 83.5 kB Without provenance Details for adbblitz-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for adbblitz 0.10
File Interpreter ABI Platform Actions
adbblitz-0.10-py3-none-any.whl Python 3 none any Details for adbblitz-0.10-py3-none-any.whl

Total release size: 164.5 kB

Release files / adbblitz-0.10.tar.gz

Download URL adbblitz-0.10.tar.gz
Size 83.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b3dbdf5f4ff40c3e5375a451d8d6ad70bbd96d717eb517871627b3be5bc32b04
BLAKE2b-256 checksum
How to use checksums
5a3e92e0399fba5c6c75d5af6e8f4d103ac893918138acc4ce66ab89e5c38c8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / adbblitz-0.10-py3-none-any.whl

Download URL adbblitz-0.10-py3-none-any.whl
Size 81.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58135a0780cee4255ccd30efd65bab35bd2202b271a9be15d4ad50d90dbf9f85
BLAKE2b-256 checksum
How to use checksums
95d5d7fcbfcd6e485fe848f303942fc82af9991ab84d7b3fef1574f0523c4f8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for adbblitz 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page