1 Star 11 Fork 9

Haskely/py-scrcpy-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Python Scrcpy Client

(本项目客隆自:https://github.com/leng-yue/py-scrcpy-client

这个包允许你使用Python实时查看和控制安卓设备。

众所周知 Scrcpy(https://github.com/Genymobile/scrcpy) 是一个很强大的安卓设备控制开源程序,

无需Root,延迟低,效果强,控制效果好。

但是,原程序控制端是用c语言写的,编译也麻烦,二次开发不容易;

本项目使用python语言重新编写控制端,这样就很方便的使用python对手机进行操控了。

使用方法:

(翻译自 https://leng-yue.github.io/py-scrcpy-client/guide.html)

在本文中,您将在 10 分钟内学会使用该项目。

0. 安装

首先,您需要通过 pip 安装此软件包:

pip install scrcpy-client[ui]

然后,您可以启动 py-scrcpy 来查看演示:

  • 注意:不想看demo ui的可以忽略[ui]

1. 连接手机¶

import scrcpy
# If you already know the device serial
client = scrcpy.Client(device="DEVICE SERIAL")
# You can also pass an ADBClient instance to it
from adbutils import adb
adb.connect("127.0.0.1:5555")
client = scrcpy.Client(device=adb.devices()[0])

由于本项目依赖于 adbutils,所以用户无需在 windows 和 macOS 上手动下载 adb。

不过linux用户还是需要手动安装adb。

  • Debian 用户可以使用 apt install adb 来安装 ADB。 获取更多信息,请访问 adbutils's webpage.

2. 绑定事件

该项目的核心遵循事件发送者和接收者结构。这意味着您可以将多个侦听器添加到同一流中。

import cv2

def on_frame(frame):
    # If you set non-blocking (default) in constructor, the frame event receiver 
    # may receive None to avoid blocking event.
    if frame is not None:
        # frame is an bgr numpy ndarray (cv2' default format)
        cv2.imshow("viz", frame)
    cv2.waitKey(10)

client.add_listener(scrcpy.EVENT_FRAME, on_frame)

[可选] 你也可以添加一个监听器来监听 init 事件。

def on_init():
    # Print device name
    print(client.device_name)
client.add_listener(scrcpy.EVENT_INIT, on_init)

然后就可以启动客户端了

client.start()

【可选】你可以用thread=True来启动客户端,那么frame loop会在一个新的线程中执行,主线程不会被阻塞。

client.start(threaded=True)

3. 发送动作

您可以在 API:scrcpy.control 子模块 中找到所有操作。 核心会自动为自己创建一个控制实例。 例如,您可以通过以下方式发送触摸事件

# Mousedown
client.control.touch(100, 200, scrcpy.ACTION_DOWN)
# Mouseup
client.control.touch(100, 200, scrcpy.ACTION_UP)

4. 获取设备信息

# Resolution
client.resolution
# Screenshot / Last frame
client.last_frame
# Device Name
client.device_name

5. 减少 CPU 使用率

您可以使用 max_width、bitrate 和 max_fps 参数来限制视频流的比特率。 在降低视频码流码率后,H264解码器可以节省大量的CPU资源。 当您不需要 10 毫秒级别的体验时,这非常有用。 (在大多数自动化中,您可能只需要 5 fps)。

原文档:

This package allows you to view and control android device in realtime.

demo gif

Note: This gif is compressed and experience lower quality than actual.

How to use

To begin with, you need to install this package via pip:

pip install scrcpy-client[ui]

Then, you can start py-scrcpy to view the demo:

Note: you can ignore [ui] if you don't want to view the demo ui

Document

Here is the document GitHub page: Documentation Also, you can check scrcpy_ui/main.py for a full functional demo.

Contribution & Development

Already implemented all functions in scrcpy server 1.20. Please check scrcpy server 1.20 source code: Link

Reference & Appreciation

Copyright (c) 2021-2021 Lengyue and others Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

这个包允许你 *使用Python* 实时查看和控制安卓设备。 众所周知 Scrcpy(https://github.com/Genymobile/scrcpy) 是一个很强大的安卓设备控制开源程序,无需Root,延迟低,效果强,控制效果好。 但是,原程序控制端是用c语言写的,编译也麻烦,二次开发不容易; 本项目使用python语言重新编写控制端,这样就很方便的使用python对手机进行操控了 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者 (3)

全部

语言

近期动态

接近2年前评论了任务 #I53109 C:\Users\999999\Desktop\myscrcpy.py:7: UnsupportedWarning: devices is unsupported as of 0.4.0. use device_list() instead client = scrcpy.Client(device=adb.devices()[0])
接近2年前评论了任务 #I53109 C:\Users\999999\Desktop\myscrcpy.py:7: UnsupportedWarning: devices is unsupported as of 0.4.0. use device_list() instead client = scrcpy.Client(device=adb.devices()[0])
接近3年前评论了仓库
3年前评论了任务 #I53109 C:\Users\999999\Desktop\myscrcpy.py:7: UnsupportedWarning: devices is unsupported as of 0.4.0. use device_list() instead client = scrcpy.Client(device=adb.devices()[0])
3年前评论了任务 #I53109 C:\Users\999999\Desktop\myscrcpy.py:7: UnsupportedWarning: devices is unsupported as of 0.4.0. use device_list() instead client = scrcpy.Client(device=adb.devices()[0])
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Haskely/py-scrcpy-client.git
git@gitee.com:Haskely/py-scrcpy-client.git
Haskely
py-scrcpy-client
py-scrcpy-client
main

搜索帮助