1 Star 0 Fork 0

Robertzi / scrcpy

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

Only the original README is guaranteed to be up-to-date.

只有原版的README会保持最新。

本文根据ed130e05进行翻译。

scrcpy (v1.17)

本应用程序可以显示并控制通过 USB (或 TCP/IP) 连接的安卓设备,且不需要任何 root 权限。本程序支持 GNU/Linux, WindowsmacOS

screenshot

它专注于:

  • 轻量 (原生,仅显示设备屏幕)
  • 性能 (30~60fps)
  • 质量 (分辨率可达 1920×1080 或更高)
  • 低延迟 (35~70ms)
  • 快速启动 (最快 1 秒内即可显示第一帧)
  • 无侵入性 (不会在设备上遗留任何程序)

系统要求

安卓设备最低需要支持 API 21 (Android 5.0)。

确保设备已开启 adb 调试

在某些设备上,还需要开启额外的选项以使用鼠标和键盘进行控制。

获取本程序

Packaging status

Linux

在 Debian (目前仅支持 testingsid 分支) 和Ubuntu (20.04) 上:

apt install scrcpy

我们也提供 Snap 包: scrcpy

对 Fedora 我们提供 COPR 包: scrcpy

对 Arch Linux 我们提供 AUR 包: scrcpy

对 Gentoo 我们提供 Ebuild 包:scrcpy/

您也可以自行构建 (不必担心,这并不困难)。

Windows

在 Windows 上,简便起见,我们提供包含了所有依赖 (包括 adb) 的预编译包。

也可以使用 Chocolatey

choco install scrcpy
choco install adb    # 如果还没有 adb

或者 Scoop:

scoop install scrcpy
scoop install adb    # 如果还没有 adb

您也可以自行构建

macOS

本程序已发布到 Homebrew。直接安装即可:

brew install scrcpy

你还需要在 PATH 内有 adb。如果还没有:

# Homebrew >= 2.6.0
brew install --cask android-platform-tools

# Homebrew < 2.6.0
brew cask install android-platform-tools

您也可以自行构建

运行

连接安卓设备,然后执行:

scrcpy

本程序支持命令行参数,查看参数列表:

scrcpy --help

功能介绍

捕获设置

降低分辨率

有时候,可以通过降低镜像的分辨率来提高性能。

要同时限制宽度和高度到某个值 (例如 1024):

scrcpy --max-size 1024
scrcpy -m 1024  # 简写

另一边会被按比例缩小以保持设备的显示比例。这样,1920×1080 分辨率的设备会以 1024×576 的分辨率进行镜像。

修改码率

默认码率是 8Mbps。要改变视频的码率 (例如改为 2Mbps):

scrcpy --bit-rate 2M
scrcpy -b 2M  # 简写

限制帧率

要限制捕获的帧率:

scrcpy --max-fps 15

本功能从 Android 10 开始才被官方支持,但在一些旧版本中也能生效。

画面裁剪

可以对设备屏幕进行裁剪,只镜像屏幕的一部分。

例如可以只镜像 Oculus Go 的一只眼睛。

scrcpy --crop 1224:1440:0:0   # 以 (0,0) 为原点的 1224x1440 像素

如果同时指定了 --max-size,会先进行裁剪,再进行缩放。

锁定屏幕方向

要锁定镜像画面的方向:

scrcpy --lock-video-orientation 0   # 自然方向
scrcpy --lock-video-orientation 1   # 逆时针旋转 90°
scrcpy --lock-video-orientation 2   # 180°
scrcpy --lock-video-orientation 3   # 顺时针旋转 90°

只影响录制的方向。

窗口可以独立旋转

编码器

一些设备内置了多种编码器,但是有的编码器会导致问题或崩溃。可以手动选择其它编码器:

scrcpy --encoder OMX.qcom.video.encoder.avc

要列出可用的编码器,可以指定一个不存在的编码器名称,错误信息中会包含所有的编码器:

scrcpy --encoder _

屏幕录制

可以在镜像的同时录制视频:

scrcpy --record file.mp4
scrcpy -r file.mkv

仅录制,不显示镜像:

scrcpy --no-display --record file.mp4
scrcpy -Nr file.mkv
# 按 Ctrl+C 停止录制

录制时会包含“被跳过的帧”,即使它们由于性能原因没有实时显示。设备会为每一帧打上 时间戳 ,所以 包时延抖动 不会影响录制的文件。

连接

无线

Scrcpy 使用 adb 与设备通信,并且 adb 支持通过 TCP/IP 连接到设备:

  1. 将设备和电脑连接至同一 Wi-Fi。

  2. 打开 设置 → 关于手机 → 状态信息,获取设备的 IP 地址,也可以执行以下的命令:

    adb shell ip route | awk '{print $9}'
  3. 启用设备的网络 adb 功能 adb tcpip 5555

  4. 断开设备的 USB 连接。

  5. 连接到您的设备:adb connect DEVICE_IP:5555 (将 DEVICE_IP 替换为设备 IP).

  6. 正常运行 scrcpy

可能需要降低码率和分辨率:

scrcpy --bit-rate 2M --max-size 800
scrcpy -b2M -m800  # 简写

多设备

如果 adb devices 列出了多个设备,您必须指定设备的 序列号

scrcpy --serial 0123456789abcdef
scrcpy -s 0123456789abcdef  # 简写

如果设备通过 TCP/IP 连接:

scrcpy --serial 192.168.0.1:5555
scrcpy -s 192.168.0.1:5555  # 简写

您可以同时启动多个 scrcpy 实例以同时显示多个设备的画面。

在设备连接时自动启动

您可以使用 AutoAdb:

autoadb scrcpy -s '{}'

SSH 隧道

要远程连接到设备,可以将本地的 adb 客户端连接到远程的 adb 服务端 (需要两端的 adb 协议版本相同):

adb kill-server    # 关闭本地 5037 端口上的 adb 服务端
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
# 保持该窗口开启

在另一个终端:

scrcpy

若要不使用远程端口转发,可以强制使用正向连接 (注意 -L-R 的区别):

adb kill-server    # 关闭本地 5037 端口上的 adb 服务端
ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 your_remote_computer
# 保持该窗口开启

在另一个终端:

scrcpy --force-adb-forward

类似无线网络连接,可能需要降低画面质量:

scrcpy -b2M -m800 --max-fps 15

窗口设置

标题

窗口的标题默认为设备型号。可以通过如下命令修改:

scrcpy --window-title 'My device'

位置和大小

您可以指定初始的窗口位置和大小:

scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600

无边框

关闭边框:

scrcpy --window-borderless

保持窗口在最前

您可以通过如下命令保持窗口在最前面:

scrcpy --always-on-top

全屏

您可以通过如下命令直接全屏启动scrcpy:

scrcpy --fullscreen
scrcpy -f  # 简写

全屏状态可以通过 MOD+f 随时切换。

旋转

可以通过以下命令旋转窗口:

scrcpy --rotation 1

可选的值有:

  • 0: 无旋转
  • 1: 逆时针旋转 90°
  • 2: 旋转 180°
  • 3: 顺时针旋转 90°

也可以使用 MOD+ (左箭头)MOD+ (右箭头) 随时更改。

需要注意的是, scrcpy 有三个不同的方向:

  • MOD+r 请求设备在竖屏和横屏之间切换 (如果前台应用程序不支持请求的朝向,可能会拒绝该请求)。
  • --lock-video-orientation 改变镜像的朝向 (设备传输到电脑的画面的朝向)。这会影响录制。
  • --rotation (或 MOD+/MOD+) 只旋转窗口的内容。这只影响显示,不影响录制。

其他镜像设置

只读

禁用电脑对设备的控制 (如键盘输入、鼠标事件和文件拖放):

scrcpy --no-control
scrcpy -n

显示屏

如果设备有多个显示屏,可以选择要镜像的显示屏:

scrcpy --display 1

可以通过如下命令列出所有显示屏的 id:

adb shell dumpsys display   # 在输出中搜索 “mDisplayId=”

控制第二显示屏需要设备运行 Android 10 或更高版本 (否则将在只读状态下镜像)。

保持常亮

阻止设备在连接时休眠:

scrcpy --stay-awake
scrcpy -w

程序关闭时会恢复设备原来的设置。

关闭设备屏幕

可以通过以下的命令行参数在关闭设备屏幕的状态下进行镜像:

scrcpy --turn-screen-off
scrcpy -S

或者在任何时候按 MOD+o

要重新打开屏幕,按下 MOD+Shift+o.

在Android上,电源 按钮始终能把屏幕打开。为了方便,对于在 scrcpy 中发出的 电源 事件 (通过鼠标右键或 MOD+p),会 (尽最大的努力) 在短暂的延迟后将屏幕关闭。设备上的 电源 按钮仍然能打开设备屏幕。

还可以同时阻止设备休眠:

scrcpy --turn-screen-off --stay-awake
scrcpy -Sw

渲染过期帧

默认状态下,为了降低延迟, scrcpy 永远渲染解码成功的最近一帧,并跳过前面任意帧。

强制渲染所有帧 (可能导致延迟变高):

scrcpy --render-expired-frames

显示触摸

在演示时,可能会需要显示物理触摸点 (在物理设备上的触摸点)。

Android 在 开发者选项 中提供了这项功能。

Scrcpy 提供一个选项可以在启动时开启这项功能并在退出时恢复初始设置:

scrcpy --show-touches
scrcpy -t

请注意这项功能只能显示 物理 触摸 (用手指在屏幕上的触摸)。

关闭屏保

Scrcpy 默认不会阻止电脑上开启的屏幕保护。

关闭屏幕保护:

scrcpy --disable-screensaver

输入控制

旋转设备屏幕

使用 MOD+r 在竖屏和横屏模式之间切换。

需要注意的是,只有在前台应用程序支持所要求的模式时,才会进行切换。

复制粘贴

每次安卓的剪贴板变化时,其内容都会被自动同步到电脑的剪贴板上。

所有的 Ctrl 快捷键都会被转发至设备。其中:

  • Ctrl+c 通常执行复制
  • Ctrl+x 通常执行剪切
  • Ctrl+v 通常执行粘贴 (在电脑到设备的剪贴板同步完成之后)

大多数时候这些按键都会执行以上的功能。

但实际的行为取决于设备上的前台程序。例如,Termux 会在按下 Ctrl+c 时发送 SIGINT,又如 K-9 Mail 会新建一封邮件。

要在这种情况下进行剪切,复制和粘贴 (仅支持 Android >= 7):

  • MOD+c 注入 COPY (复制)
  • MOD+x 注入 CUT (剪切)
  • MOD+v 注入 PASTE (粘贴) (在电脑到设备的剪贴板同步完成之后)

另外,MOD+Shift+v 会将电脑的剪贴板内容转换为一串按键事件输入到设备。在应用程序不接受粘贴时 (比如 Termux),这项功能可以派上一定的用场。不过这项功能可能会导致非 ASCII 编码的内容出现错误。

警告: 将电脑剪贴板的内容粘贴至设备 (无论是通过 Ctrl+v 还是 MOD+v) 都会将内容复制到设备的剪贴板。如此,任何安卓应用程序都能读取到。您应避免将敏感内容 (如密码) 通过这种方式粘贴。

一些设备不支持通过程序设置剪贴板。通过 --legacy-paste 选项可以修改 Ctrl+vMOD+v 的工作方式,使它们通过按键事件 (同 MOD+Shift+v) 来注入电脑剪贴板内容。

双指缩放

模拟“双指缩放”:Ctrl+按住并移动鼠标

更准确的说,在按住鼠标左键时按住 Ctrl。直到松开鼠标左键,所有鼠标移动将以屏幕中心为原点,缩放或旋转内容 (如果应用支持)。

实际上,scrcpy 会在以屏幕中心对称的位置上生成由“虚拟手指”发出的额外触摸事件。

文字注入偏好

打字的时候,系统会产生两种事件

  • 按键事件 ,代表一个按键被按下或松开。
  • 文本事件 ,代表一个字符被输入。

程序默认使用按键事件来输入字母。只有这样,键盘才会在游戏中正常运作 (例如 WASD 键)。

但这也有可能造成一些问题。如果您遇到了问题,可以通过以下方式避免:

scrcpy --prefer-text

(这会导致键盘在游戏中工作不正常)

按键重复

默认状态下,按住一个按键不放会生成多个重复按键事件。在某些游戏中这可能会导致性能问题。

避免转发重复按键事件:

scrcpy --no-key-repeat

右键和中键

默认状态下,右键会触发返回键 (或电源键),中键会触发 HOME 键。要禁用这些快捷键并把所有点击转发到设备:

scrcpy --forward-all-clicks

文件拖放

安装APK

将 APK 文件 (文件名以 .apk 结尾) 拖放到 scrcpy 窗口来安装。

该操作在屏幕上不会出现任何变化,而会在控制台输出一条日志。

将文件推送至设备

要推送文件到设备的 /sdcard/,将 (非 APK) 文件拖放至 scrcpy 窗口。

该操作没有可见的响应,只会在控制台输出日志。

在启动时可以修改目标目录:

scrcpy --push-target /sdcard/foo/bar/

音频转发

Scrcpy 不支持音频。请使用 sndcpy.

另外请阅读 issue #14

快捷键

在以下列表中, MOD 是快捷键的修饰键。 默认是 (左) Alt 或 (左) Super

您可以使用 --shortcut-mod 来修改。可选的按键有 lctrlrctrllaltraltlsuperrsuper。例如:

# 使用右 Ctrl 键
scrcpy --shortcut-mod=rctrl

# 使用左 Ctrl 键 + 左 Alt 键,或 Super 键
scrcpy --shortcut-mod=lctrl+lalt,lsuper

Super 键通常是指 WindowsCmd 键。

操作 快捷键
全屏 MOD+f
向左旋转屏幕 MOD+ (左箭头)
向右旋转屏幕 MOD+ (右箭头)
将窗口大小重置为1:1 (匹配像素) MOD+g
将窗口大小重置为消除黑边 MOD+w | 双击¹
点按 主屏幕 MOD+h | 鼠标中键
点按 返回 MOD+b | 鼠标右键²
点按 切换应用 MOD+s
点按 菜单 (解锁屏幕) MOD+m
点按 音量+ MOD+ (上箭头)
点按 音量- MOD+ (下箭头)
点按 电源 MOD+p
打开屏幕 鼠标右键²
关闭设备屏幕 (但继续在电脑上显示) MOD+o
打开设备屏幕 MOD+Shift+o
旋转设备屏幕 MOD+r
展开通知面板 MOD+n
收起通知面板 MOD+Shift+n
复制到剪贴板³ MOD+c
剪切到剪贴板³ MOD+x
同步剪贴板并粘贴³ MOD+v
注入电脑剪贴板文本 MOD+Shift+v
打开/关闭FPS显示 (在 stdout) MOD+i
捏拉缩放 Ctrl+按住并移动鼠标

¹双击黑边可以去除黑边 ²点击鼠标右键将在屏幕熄灭时点亮屏幕,其余情况则视为按下返回键 。 ³需要安卓版本 Android >= 7。

所有的 Ctrl+按键 的快捷键都会被转发到设备,所以会由当前应用程序进行处理。

自定义路径

要使用指定的 adb 二进制文件,可以设置环境变量 ADB

ADB=/path/to/adb scrcpy

要覆盖 scrcpy-server 的路径,可以设置 SCRCPY_SERVER_PATH

为什么叫 scrcpy

一个同事让我找出一个和 gnirehtet 一样难以发音的名字。

strcpy 复制一个 string; scrcpy 复制一个 screen。

如何构建?

请查看BUILD

常见问题

请查看FAQ

开发者

请查看开发者页面

许可协议

Copyright (C) 2018 Genymobile
Copyright (C) 2018-2021 Romain Vimont

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

相关文章

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright (C) 2018 Genymobile Copyright (C) 2018-2021 Romain Vimont Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Display and control your Android device 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/robertzi/scrcpy.git
git@gitee.com:robertzi/scrcpy.git
robertzi
scrcpy
scrcpy
master

搜索帮助