1 Star 0 Fork 84

babbi / scrcpy

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

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

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

本文根据479d10d进行翻译。

scrcpy (v1.16)

本应用程序可以通过USB(或 TCP/IP )连接用于显示或控制安卓设备。这不需要获取 root 权限。

该应用程序可以在 GNU/Linux, WindowsmacOS 环境下运行。

screenshot

它专注于:

  • 轻量 (原生,仅显示设备屏幕)
  • 性能 (30~60fps)
  • 质量 (分辨率可达1920x1080或更高)
  • 低延迟 (35-70ms)
  • 快速启动 (数秒内即能开始显示)
  • 无侵入性 (不需要在安卓设备上安装任何程序)

使用要求

安卓设备系统版本需要在Android 5.0(API 21)或以上。

确保您在设备上开启了adb调试

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

获取scrcpy

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下载scrcpy。直接安装就可以了:

brew install scrcpy

您需要 adb以使用scrcpy,并且它需要可以通过 PATH被访问。如果您没有:

brew cask install android-platform-tools

您也可以自行编译

运行scrcpy

用USB链接电脑和安卓设备,并执行:

scrcpy

支持带命令行参数执行,查看参数列表:

scrcpy --help

功能介绍

画面设置

缩小分辨率

有时候,将设备屏幕镜像分辨率降低可以有效地提升性能。

我们可以将高度和宽度都限制在一定大小内(如 1024):

scrcpy --max-size 1024
scrcpy -m 1024  # short version

较短的一边会被按比例缩小以保持设备的显示比例。 这样,1920x1080 的设备会以 1024x576 的分辨率显示。

修改画面比特率

默认的比特率是8Mbps。如果要改变画面的比特率 (比如说改成2Mbps):

scrcpy --bit-rate 2M
scrcpy -b 2M  # short version

限制画面帧率

画面的帧率可以通过下面的命令被限制:

scrcpy --max-fps 15

这个功能仅在Android 10和以后的版本被Android官方支持,但也有可能在更早的版本可用。

画面裁剪

设备画面可在裁切后进行镜像,以显示部分屏幕。

这项功能可以用于,例如,只显示Oculus Go的一只眼睛。

scrcpy --crop 1224:1440:0:0   # 1224x1440 at offset (0,0)

如果--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 --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地址(在设置-关于手机-状态信息)。
  3. 打开安卓设备的网络adb功能adb tcpip 5555
  4. 将您的设备与电脑断开连接。
  5. 连接到您的设备:adb connect DEVICE_IP:5555 (用设备IP替换 DEVICE_IP).
  6. 运行scrcpy

降低比特率和分辨率可能有助于性能:

scrcpy --bit-rate 2M --max-size 800
scrcpy -b2M -m800  # short version

多设备

如果多个设备在执行adb devices后被列出,您必须指定设备的 序列号

scrcpy --serial 0123456789abcdef
scrcpy -s 0123456789abcdef  # short version

如果设备是通过TCP/IP方式连接到电脑的:

scrcpy --serial 192.168.0.1:5555
scrcpy -s 192.168.0.1:5555  # short version

您可以同时启动多个 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    # kill the local adb server on 5037
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  # short version

全屏状态可以通过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以在竖屏和横屏模式之间切换。

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

复制黏贴

每次Android的剪贴板变化的时候,它都会被自动同步到电脑的剪贴板上。

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

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

这通常如您所期望的那样运作。

但实际的行为取决于设备上的前台程序。 例如 TermuxCtrl+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) 都需要将内容保存至设备的剪贴板。如此,任何一个应用程序都可以读取它。 您应当避免将敏感内容通过这种方式传输(如密码)。

捏拉缩放

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

更准确的说,您需要在按住Ctrl的同时按住并移动鼠标。 在鼠标左键松开之后,光标的任何操作都会相对于屏幕的中央进行。

具体来说, scrcpy 使用“虚拟手指”以在相对于屏幕中央相反的位置产生触摸事件。

文字注入偏好

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

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

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

但这也有可能造成问题。如果您遇到了这样的问题,您可以通过下列操作避免它:

scrcpy --prefer-text

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

按键重复

当你一直按着一个按键不放时,程序默认产生多个按键事件。 在某些游戏中这可能会导致性能问题。

避免转发重复按键事件:

scrcpy --no-key-repeat

文件传输

安装APK

如果您要要安装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就是Windows或者Cmd

操作 快捷键
全屏 MOD+f
向左旋转屏幕 MOD+ (左)
向右旋转屏幕 MOD+ (右)
将窗口大小重置为1:1 (像素优先) MOD+g
将窗口大小重置为消除黑边 MOD+w | 双击¹
点按 主屏幕 MOD+h | 点击鼠标中键
点按 返回 MOD+b | 点击鼠标右键²
点按 切换应用 MOD+s
点按 菜单 (解锁屏幕) MOD+m
点按 音量+ MOD+ (up)
点按 音量- MOD+ (down)
点按 电源 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。

如何编译?

请查看编译

常见问题

请查看FAQ.

开发者

请查看开发者页面

许可协议

Copyright (C) 2018 Genymobile
Copyright (C) 2018-2020 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-2020 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.

简介

scrcpy 是一个在电脑上显示和控制 Android 设备的命令行工具,适用于 GNU/Linux、Windows 和 Mac OS,且无需 root 展开 收起
C/C++
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助

14c37bed 8189591 565d56ea 8189591