seeu100 / blog

我的博客
https://blog.00002000.xyz/
0 stars 0 forks source link

scrcpy #77

Open seeu100 opened 1 month ago

seeu100 commented 1 month ago

scrcpy 是一个用于控制和显示 Android 设备的桌面应用程序。它通过 USB(或 Wi-Fi)连接到设备,并在电脑上以高帧率显示设备屏幕,同时支持键盘和鼠标输入控制。

前提:确保设备已开启 adb 调试

scrcpy wifi 无线连接设备

在手机上查看ip地址,,如192.168.59.249

然后在电脑中运行:

$ adb tcpip 5555
restarting in TCP mode port: 5555
$ adb connect 192.168.59.249
connected to 192.168.59.249:5555
$ scrcpy
作用 参数
禁用音频转发 --no-audio
窗口置顶 --always-on-top
音频比特率 --audio-bit-rate=值
音频缓冲 --audio-buffer=ms
音频编解码器 --audio-codec=名称
音频编码器选项 --audio-codec-options=key[:类型]=值[,...]
特定音频编码器 --audio-encoder=名称
音频源 --audio-source=来源
音频输出缓冲 --audio-output-buffer=ms
视频比特率 -b, --video-bit-rate=值
相机尺寸比 --camera-ar=ar
指定相机ID --camera-id=id
相机朝向 --camera-facing=facing
高速相机模式 --camera-high-speed
相机尺寸 --camera-size=<宽>x<高>
相机帧率 --camera-fps=值
裁剪屏幕 --crop=宽:高:x:y
使用USB设备 -d, --select-usb
禁用屏保 --disable-screensaver
显示缓冲 --display-buffer=ms
指定显示ID --display-id=id
显示方向 --display-orientation=值
使用TCP/IP设备 -e, --select-tcpip
全屏启动 -f, --fullscreen
强制ADB转发 --force-adb-forward
转发所有点击 --forward-all-clicks
帮助 -h, --help
键盘模式 --keyboard=mode
关闭ADB --kill-adb-on-close
传统粘贴 --legacy-paste
列出摄像头 --list-cameras
列出相机尺寸 --list-camera-sizes
列出显示器 --list-displays
列出编码器 --list-encoders
锁定视频方向 --lock-video-orientation[=值]
视频最大尺寸 -m, --max-size=值
鼠标模式 --mouse=mode
最大帧率 --max-fps=值
无控制 -n, --no-control
无播放 -N, --no-playback
禁用音频播放 --no-audio-playback
无清理 --no-cleanup
取消剪贴板自动同步 --no-clipboard-autosync
错误时不降低分辨率 --no-downsize-on-error
不转发重复按键 --no-key-repeat
禁用mipmap --no-mipmaps
不启动设备 --no-power-on
禁用视频转发 --no-video
禁用视频播放 --no-video-playback
方向设置 --orientation=值
OTG模式 --otg
端口设置 -p, --port=port[:port]
退出暂停配置 --pause-on-exit[=mode]
关闭时熄屏 --power-off-on-close
优先文本注入 --prefer-text
FPS计数器 --print-fps
拖放文件目标路径 --push-target=path
录制屏幕 -r, --record=file.mp4
原始键事件注入 --raw-key-events
录制格式强制 --record-format=format
录像方向 --record-orientation=value
渲染驱动选择 --render-driver=name
音频需求 --require-audio
设备序列号 -s, --serial=serial
立即熄屏 -S, --turn-screen-off
快捷键组合 --shortcut-mod=key[+...][,...]
显示触摸反馈 -t, --show-touches
TCP/IP重连配置 --tcpip[=ip[:port]]
镜像时间限制 --time-limit=seconds
隧道主机IP --tunnel-host=ip
隧道端口 --tunnel-port=port
版本信息 -v, --version
日志等级 -V, --verbosity=value
v4l2输出 --v4l2-sink=/dev/videoN
v4l2缓冲 --v4l2-buffer=ms
视频编解码器选择 --video-codec=name
视频编码器选项 --video-codec-options=key[:type]=value[,...]
特定视频编码器 --video-encoder=name
视频源选择 --video-source=source
保持唤醒 -w, --stay-awake
无边框窗口 --window-borderless
自定义窗口标题 --window-title=text
窗口初始位置 (X轴) --window-x=value
窗口初始位置 (Y轴) --window-y=value
窗口初始宽度 --window-width=value
窗口初始高度 --window-height=value
seeu100 commented 1 month ago

scrcpy 2.4 Usage: scrcpy [options] https://d.android.com/reference/android/media/MediaFormat Options:

--always-on-top Make scrcpy window always on top (above other windows).

--audio-bit-rate=value Encode the audio at the given bit rate, expressed in bits/s. Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000). Default is 128K (128000).

--audio-buffer=ms Configure the audio buffering delay (in milliseconds). Lower values decrease the latency, but increase the likelyhood of buffer underrun (causing audio glitches). Default is 50.

--audio-codec=name Select an audio codec (opus, aac, flac or raw). Default is opus.

--audio-codec-options=key[:type]=value[,...] Set a list of comma-separated key:type=value options for the device audio encoder. The possible values for 'type' are 'int' (default), 'long', 'float' and 'string'. The list of possible codec options is available in the Android documentation:

--audio-encoder=name Use a specific MediaCodec audio encoder (depending on the codec provided by --audio-codec). The available encoders can be listed by --list-encoders.

--audio-source=source Select the audio source (output or mic). Default is output.

--audio-output-buffer=ms Configure the size of the SDL audio output buffer (in milliseconds). If you get "robotic" audio playback, you should test with a higher value (10). Do not change this setting otherwise. Default is 5.

-b, --video-bit-rate=value Encode the video at the given bit rate, expressed in bits/s. Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000). Default is 8M (8000000).

--camera-ar=ar Select the camera size by its aspect ratio (+/- 10%). Possible values are "sensor" (use the camera sensor aspect ratio), ":" (e.g. "4:3") or "" (e.g. "1.6").

--camera-id=id Specify the device camera id to mirror. The available camera ids can be listed by: scrcpy --list-cameras

--camera-facing=facing Select the device camera by its facing direction. Possible values are "front", "back" and "external".

--camera-high-speed Enable high-speed camera capture mode. This mode is restricted to specific resolutions and frame rates, listed by --list-camera-sizes.

--camera-size=x Specify an explicit camera capture size.

--camera-fps=value Specify the camera capture frame rate. If not specified, Android's default frame rate (30 fps) is used.

--crop=width:height:x:y Crop the device screen on the server. The values are expressed in the device natural orientation (typically, portrait for a phone, landscape for a tablet). Any --max-size value is computed on the cropped size.

-d, --select-usb Use USB device (if there is exactly one, like adb -d). Also see -e (--select-tcpip).

--disable-screensaver Disable screensaver while scrcpy is running.

--display-buffer=ms Add a buffering delay (in milliseconds) before displaying. This increases latency to compensate for jitter. Default is 0 (no buffering).

--display-id=id Specify the device display id to mirror. The available display ids can be listed by: scrcpy --list-displays Default is 0.

--display-orientation=value Set the initial display orientation. Possible values are 0, 90, 180, 270, flip0, flip90, flip180 and flip270. The number represents the clockwise rotation in degrees; the "flip" keyword applies a horizontal flip before the rotation. Default is 0.

-e, --select-tcpip Use TCP/IP device (if there is exactly one, like adb -e). Also see -d (--select-usb).

-f, --fullscreen Start in fullscreen.

--force-adb-forward Do not attempt to use "adb reverse" to connect to the device.

--forward-all-clicks By default, right-click triggers BACK (or POWER on) and middle-click triggers HOME. This option disables these shortcuts and forwards the clicks to the device instead.

-h, --help Print this help.

-K Same as --keyboard=uhid.

--keyboard=mode Select how to send keyboard inputs to the device. Possible values are "disabled", "sdk", "uhid" and "aoa". "disabled" does not send keyboard inputs to the device. "sdk" uses the Android system API to deliver keyboard events to applications. "uhid" simulates a physical HID keyboard using the Linux UHID kernel module on the device. "aoa" simulates a physical keyboard using the AOAv2 protocol. It may only work over USB. For "uhid" and "aoa", the keyboard layout must be configured (once and for all) on the device, via Settings -> System -> Languages and input -> Physical keyboard. This settings page can be started directly using the shortcut MOD+k (except in OTG mode) or by executing: adb shell am start -a android.settings.HARD_KEYBOARD_SETTINGS. This option is only available when a HID keyboard is enabled (or a physical keyboard is connected). Also see --mouse.

--kill-adb-on-close Kill adb when scrcpy terminates.

--legacy-paste Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+Shift+v). This is a workaround for some devices not behaving as expected when setting the device clipboard programmatically.

--list-cameras List device cameras.

--list-camera-sizes List the valid camera capture sizes.

--list-displays List device displays.

--list-encoders List video and audio encoders available on the device.

--lock-video-orientation[=value] Lock capture video orientation to value. Possible values are "unlocked", "initial" (locked to the initial orientation), 0, 90, 180 and 270. The values represent the clockwise rotation from the natural device orientation, in degrees. Default is "unlocked". Passing the option without argument is equivalent to passing "initial".

-m, --max-size=value Limit both the width and height of the video to value. The other dimension is computed so that the device aspect-ratio is preserved. Default is 0 (unlimited).

-M Same as --mouse=uhid.

--max-fps=value Limit the frame rate of screen capture (officially supported since Android 10, but may work on earlier versions).

--mouse=mode Select how to send mouse inputs to the device. Possible values are "disabled", "sdk", "uhid" and "aoa". "disabled" does not send mouse inputs to the device. "sdk" uses the Android system API to deliver mouse eventsto applications. "uhid" simulates a physical HID mouse using the Linux UHID kernel module on the device. "aoa" simulates a physical mouse using the AOAv2 protocol. It may only work over USB. In "uhid" and "aoa" modes, the computer mouse is captured to control the device directly (relative mouse mode). LAlt, LSuper or RSuper toggle the capture mode, to give control of the mouse back to the computer. Also see --keyboard.

-n, --no-control Disable device control (mirror the device in read-only).

-N, --no-playback Disable video and audio playback on the computer (equivalent to --no-video-playback --no-audio-playback).

--no-audio Disable audio forwarding.

--no-audio-playback Disable audio playback on the computer.

--no-cleanup By default, scrcpy removes the server binary from the device and restores the device state (show touches, stay awake and power mode) on exit. This option disables this cleanup.

--no-clipboard-autosync By default, scrcpy automatically synchronizes the computer clipboard to the device clipboard before injecting Ctrl+v, and the device clipboard to the computer clipboard whenever it changes. This option disables this automatic synchronization.

--no-downsize-on-error By default, on MediaCodec error, scrcpy automatically tries again with a lower definition. This option disables this behavior.

--no-key-repeat Do not forward repeated key events when a key is held down.

--no-mipmaps If the renderer is OpenGL 3.0+ or OpenGL ES 2.0+, then mipmaps are automatically generated to improve downscaling quality. This option disables the generation of mipmaps.

--no-power-on Do not power on the device on start.

--no-video Disable video forwarding.

--no-video-playback Disable video playback on the computer.

--orientation=value Same as --display-orientation=value --record-orientation=value.

--otg Run in OTG mode: simulate physical keyboard and mouse, as if the computer keyboard and mouse were plugged directly to the device via an OTG cable. In this mode, adb (USB debugging) is not necessary, and mirroring is disabled. LAlt, LSuper or RSuper toggle the mouse capture mode, to give control of the mouse back to the computer. Keyboard and mouse may be disabled separately using--keyboard=disabled and --mouse=disabled. It may only work over USB. See --keyboard and --mouse.

将参数的文档修改为中文的助记卡片表格,参数不要翻译: -p, --port=port[:port] Set the TCP port (range) used by the client to listen. Default is 27183:27199.

--pause-on-exit[=mode] Configure pause on exit. Possible values are "true" (always pause on exit), "false" (never pause on exit) and "if-error" (pause only if an error occured). This is useful to prevent the terminal window from automatically closing, so that error messages can be read. Default is "false". Passing the option without argument is equivalent to passing "true".

--power-off-on-close Turn the device screen off when closing scrcpy.

--prefer-text Inject alpha characters and space as text events instead of key events. This avoids issues when combining multiple keys to enter a special character, but breaks the expected behavior of alpha keys in games (typically WASD).

--print-fps Start FPS counter, to print framerate logs to the console. It can be started or stopped at any time with MOD+i.

--push-target=path Set the target directory for pushing files to the device by drag & drop. It is passed as is to "adb push". Default is "/sdcard/Download/".

-r, --record=file.mp4 Record screen to file. The format is determined by the --record-format option if set, or by the file extension.

--raw-key-events Inject key events for all input keys, and ignore text events.

--record-format=format Force recording format (mp4, mkv, m4a, mka, opus, aac, flac or wav).

--record-orientation=value Set the record orientation. Possible values are 0, 90, 180 and 270. The number represents the clockwise rotation in degrees. Default is 0.

--render-driver=name Request SDL to use the given render driver (this is just a hint). Supported names are currently "direct3d", "opengl", "opengles2", "opengles", "metal" and "software". https://wiki.libsdl.org/SDL_HINT_RENDER_DRIVER

--require-audio By default, scrcpy mirrors only the video when audio capture fails on the device. This option makes scrcpy fail if audio is enabled but does not work.

-s, --serial=serial The device serial number. Mandatory only if several devices are connected to adb.

-S, --turn-screen-off Turn the device screen off immediately.

--shortcut-mod=key[+...][,...] Specify the modifiers to use for scrcpy shortcuts. Possible keys are "lctrl", "rctrl", "lalt", "ralt", "lsuper" and "rsuper". A shortcut can consist in several keys, separated by '+'. Several shortcuts can be specified, separated by ','. For example, to use either LCtrl+LAlt or LSuper for scrcpy shortcuts, pass "lctrl+lalt,lsuper". Default is "lalt,lsuper" (left-Alt or left-Super).

-t, --show-touches Enable "show touches" on start, restore the initial value on exit. It only shows physical touches (not clicks from scrcpy).

--tcpip[=ip[:port]] Configure and reconnect the device over TCP/IP. If a destination address is provided, then scrcpy connects to this address before starting. The device must listen on the given TCP port (default is 5555). If no destination address is provided, then scrcpy attempts to find the IP address of the current device (typically connected over USB), enables TCP/IP mode, then connects to this address before starting.

--time-limit=seconds Set the maximum mirroring time, in seconds.

--tunnel-host=ip Set the IP address of the adb tunnel to reach the scrcpy server. This option automatically enables --force-adb-forward. Default is localhost.

--tunnel-port=port Set the TCP port of the adb tunnel to reach the scrcpy server. This option automatically enables --force-adb-forward. Default is 0 (not forced): the local port used for establishing the tunnel will be used.

-v, --version Print the version of scrcpy.

-V, --verbosity=value Set the log level (verbose, debug, info, warn or error). Default is info.

--v4l2-sink=/dev/videoN Output to v4l2loopback device. It requires to lock the video orientation (see --lock-video-orientation). This feature is only available on Linux.

--v4l2-buffer=ms Add a buffering delay (in milliseconds) before pushing frames. This increases latency to compensate for jitter. This option is similar to --display-buffer, but specific to V4L2 sink. Default is 0 (no buffering). This option is only available on Linux.

--video-codec=name Select a video codec (h264, h265 or av1). Default is h264.

--video-codec-options=key[:type]=value[,...] Set a list of comma-separated key:type=value options for the device video encoder. The possible values for 'type' are 'int' (default), 'long', 'float' and 'string'. The list of possible codec options is available in the Android documentation: https://d.android.com/reference/android/media/MediaFormat

--video-encoder=name Use a specific MediaCodec video encoder (depending on the codec provided by --video-codec). The available encoders can be listed by --list-encoders.

--video-source=source Select the video source (display or camera). Camera mirroring requires Android 12+. Default is display.

-w, --stay-awake Keep the device on while scrcpy is running, when the device is plugged in.

--window-borderless Disable window decorations (display borderless window).

--window-title=text Set a custom window title.

--window-x=value Set the initial window horizontal position. Default is "auto".

--window-y=value Set the initial window vertical position. Default is "auto".

--window-width=value Set the initial window width. Default is 0 (automatic).

--window-height=value Set the initial window height. Default is 0 (automatic).

Shortcuts:

In the following list, MOD is the shortcut modifier. By default, it's (left) Alt or (left) Super, but it can be configured by --shortcut-mod (see above).

MOD+f Switch fullscreen mode

MOD+Left
    Rotate display left

MOD+Right
    Rotate display right

MOD+Shift+Left
MOD+Shift+Right
    Flip display horizontally

MOD+Shift+Up
MOD+Shift+Down
    Flip display vertically

MOD+g
    Resize window to 1:1 (pixel-perfect)

MOD+w
Double-click on black borders
    Resize window to remove black borders

MOD+h
Middle-click
    Click on HOME

MOD+b
MOD+Backspace
Right-click (when screen is on)
    Click on BACK

MOD+s
4th-click
    Click on APP_SWITCH

MOD+m
    Click on MENU

MOD+Up
    Click on VOLUME_UP

MOD+Down
    Click on VOLUME_DOWN

MOD+p
    Click on POWER (turn screen on/off)

Right-click (when screen is off)
    Power on

MOD+o
    Turn device screen off (keep mirroring)

MOD+Shift+o
    Turn device screen on

MOD+r
    Rotate device screen

MOD+n
5th-click
    Expand notification panel

MOD+Shift+n
    Collapse notification panel

MOD+c
    Copy to clipboard (inject COPY keycode, Android >= 7 only)

MOD+x
    Cut to clipboard (inject CUT keycode, Android >= 7 only)

MOD+v
    Copy computer clipboard to device, then paste (inject PASTE keycode, Android >= 7 only)

MOD+Shift+v
    Inject computer clipboard text as a sequence of key events

MOD+k
    Open keyboard settings on the device (for HID keyboard only)

MOD+i
    Enable/disable FPS counter (print frames/second in logs)

Ctrl+click-and-move
    Pinch-to-zoom and rotate from the center of the screen

Shift+click-and-move
    Tilt (slide vertically with two fingers)

Drag & drop APK file
    Install APK from computer

Drag & drop non-APK file
    Push file to device (see --push-target)

Environment variables:

ADB
    Path to adb executable

ANDROID_SERIAL
    Device serial to use if no selector (-s, -d, -e or --tcpip=<addr>) is specified

SCRCPY_ICON_PATH
    Path to the program icon

SCRCPY_SERVER_PATH
    Path to the server binary

Exit status:

  0  Normal program termination
  1  Start failure
  2  Device disconnected while running

--always-on-top -- Make scrcpy window always on top (above other windows) --audio-bit-rate -- Encode the audio at the given bit-rate --audio-buffer -- Configure the audio buffering delay (in milliseconds) --audio-codec-options -- Set a list of comma-separated key:type=value options for the device audio encoder --audio-codec -- Select the audio codec --audio-encoder -- Use a specific MediaCodec audio encoder --audio-output-buffer -- Configure the size of the SDL audio output buffer (in milliseconds) --audio-source -- Select the audio source --camera-ar -- Select the camera size by its aspect ratio --camera-facing -- Select the device camera by its facing direction --camera-fps -- Specify the camera capture frame rate --camera-high-speed -- Enable high-speed camera capture mode --camera-id -- Specify the camera id to mirror --camera-size -- Specify an explicit camera capture size --crop -- [width:height:x:y] Crop the device screen on the server --disable-screensaver -- Disable screensaver while scrcpy is running --display-buffer -- Add a buffering delay (in milliseconds) before displaying --display-id -- Specify the display id to mirror --display-orientation -- Set the initial display orientation --force-adb-forward -- Do not attempt to use "adb reverse" to connect to the device --forward-all-clicks -- Forward clicks to device --fullscreen -- Start in fullscreen --help -- Print the help --keyboard -- Set the keyboard input mode --kill-adb-on-close -- Kill adb when scrcpy terminates --legacy-paste -- Inject computer clipboard text as a sequence of key events on Ctrl+v --list-camera-sizes -- List the valid camera capture sizes --list-cameras -- List cameras available on the device --list-displays -- List displays available on the device --list-encoders -- List video and audio encoders available on the device --lock-video-orientation -- Lock video orientation --max-fps -- Limit the frame rate of screen capture --max-size -- Limit both the width and height of the video to value --mouse -- Set the mouse input mode --no-audio -- Disable audio forwarding --no-audio-playback -- Disable audio playback --no-cleanup -- Disable device cleanup actions on exit --no-clipboard-autosync -- Disable automatic clipboard synchronization --no-control -- Disable device control (mirror the device in read only) --no-downsize-on-error -- Disable lowering definition on MediaCodec error --no-key-repeat -- Do not forward repeated key events when a key is held down --no-mipmaps -- Disable the generation of mipmaps --no-playback -- Disable video and audio playback --no-power-on -- Do not power on the device on start --no-video -- Disable video forwarding --no-video-playback -- Disable video playback --orientation -- Set the video orientation --otg -- Run in OTG mode (simulating physical keyboard and mouse) --pause-on-exit -- Make scrcpy pause before exiting --port -- [port[:port]] Set the TCP port (range) used by the client to listen --power-off-on-close -- Turn the device screen off when closing scrcpy --prefer-text -- Inject alpha characters and space as text events instead of key events --print-fps -- Start FPS counter, to print frame logs to the console --push-target -- Set the target directory for pushing files to the device by drag and drop --raw-key-events -- Inject key events for all input keys, and ignore text events --record-format -- Force recording format --record-orientation -- Set the record orientation --record -- Record screen to file --render-driver -- Request SDL to use the given render driver --require-audio -- Make scrcpy fail if audio is enabled but does not work --select-tcpip -- Use TCP/IP device --select-usb -- Use USB device --serial -- The device serial number (mandatory for multiple devices only) --shortcut-mod -- [key1,key2+key3,...] Specify the modifiers to use for scrcpy shortcuts --show-touches -- Show physical touches --stay-awake -- Keep the device on while scrcpy is running, when the device is plugged in --tcpip -- (optional [ip:port]) Configure and connect the device over TCP/IP --time-limit -- Set the maximum mirroring time, in seconds --tunnel-host -- Set the IP address of the adb tunnel to reach the scrcpy server --tunnel-port -- Set the TCP port of the adb tunnel to reach the scrcpy server --turn-screen-off -- Turn the device screen off immediately --v4l2-buffer -- Add a buffering delay (in milliseconds) before pushing frames --v4l2-sink -- [/dev/videoN] Output to v4l2loopback device --verbosity -- Set the log level --version -- Print the version of scrcpy --video-bit-rate -- Encode the video at the given bit-rate --video-codec-options -- Set a list of comma-separated key:type=value options for the device video encoder --video-codec -- Select the video codec --video-encoder -- Use a specific MediaCodec video encoder --video-source -- Select the video source --window-borderless -- Disable window decorations (display borderless window) --window-height -- Set the initial window height --window-title -- Set a custom window title --window-width -- Set the initial window width --window-x -- Set the initial window horizontal position --window-y -- Set the initial window vertical position

seeu100 commented 1 month ago
参数 描述
-S--turn-screen-off 连接时关闭设备屏幕。
-w--stay-awake 保持设备唤醒状态。
-s--serial 指定要连接的设备的序列号或IP:端口(如通过Wi-Fi连接)。
-d--display 指定要镜像的显示编号(如果有多个显示)。默认为0。
-m--max-size 设置最大显示尺寸(宽度x高度),例如 -m1080x1920
-b--bit-rate 设置视频比特率(默认自动)。例如 -b10M 设置为10Mbps。
-r--refresh-rate 设置屏幕刷新率(Hz),默认为设备的原生刷新率。
-w--window 以窗口模式启动(默认全屏)。
-f--fullscreen 以全屏模式启动。
-o--orientation 锁定屏幕方向:0=自动,1=竖直,2=水平。
-c--control 启用触控板模式,鼠标左键单击为点击,右键为右键点击,滚轮滚动。
-n--no-display 不显示画面,仅转发输入事件。
-V--version 显示版本信息并退出。
-h--help 显示帮助信息。
参数 中文说明
--always-on-top 让 scrcpy 窗口始终保持在其他窗口之上
--audio-bit-rate 以指定比特率对音频进行编码
--audio-buffer 配置音频缓冲延迟(以毫秒为单位)
--audio-codec-options 为设备音频编码器设置一系列逗号分隔的键:类型=值选项
--audio-codec 选择音频编码器
--audio-encoder 使用特定的 MediaCodec 音频编码器
--audio-output-buffer 配置 SDL 音频输出缓冲区的大小(以毫秒为单位)
--audio-source 选择音频源
--camera-ar 按照长宽比选择摄像头尺寸
--camera-facing 按照朝向选择设备摄像头
--camera-fps 指定摄像头捕获的帧率
--camera-high-speed 启用高速摄像头捕获模式
--camera-id 指定要镜像的摄像头ID
--camera-size 明确指定摄像头捕获的尺寸
--crop 在服务器上对设备屏幕进行裁剪 [宽度:高度:x坐标:y坐标]
--disable-screensaver 在 scrcpy 运行时禁用屏幕保护程序
--display-buffer 在显示前添加缓冲延迟(以毫秒为单位)
--display-id 指定要镜像的显示屏ID
--display-orientation 设置初始显示屏方向
--force-adb-forward 不尝试使用 "adb reverse" 来连接设备
--forward-all-clicks 转发所有点击至设备
--fullscreen 全屏启动
--help 打印帮助信息
--keyboard 设置键盘输入模式
--kill-adb-on-close scrcpy 终止时终止 adb
--legacy-paste 在 Ctrl+v 时将计算机剪贴板文本作为一系列按键事件注入
--list-camera-sizes 列出有效的摄像头捕获尺寸
--list-cameras 列出设备上的摄像头
--list-displays 列出设备上的显示屏
--list-encoders 列出设备上可用的视频和音频编码器
--lock-video-orientation 锁定视频方向
--max-fps 限制屏幕捕获的帧率
--max-size 将视频的宽度和高度限制为指定值
--mouse 设置鼠标输入模式
--no-audio 禁止音频转发
--no-audio-playback 禁止音频播放
--no-cleanup 退出时禁用设备清理动作
--no-clipboard-autosync 禁止自动剪贴板同步
--no-control 禁用设备控制(只读镜像设备)
--no-downsize-on-error 禁用在 MediaCodec 错误时降低分辨率的操作
--no-key-repeat 当按键按下不释放时,不转发重复的按键事件
--no-mipmaps 禁止生成 mipmaps
--no-playback 禁止视频和音频播放
--no-power-on 启动时不唤醒设备
--no-video 禁止视频转发
--no-video-playback 禁止视频播放
--orientation 设置视频方向
--otg 以OTG模式运行(模拟物理键盘和鼠标)
--pause-on-exit 使 scrcpy 在退出前暂停
--port [端口[:端口]]设置客户端监听使用的TCP端口范围
--power-off-on-close 关闭 scrcpy 时关闭设备屏幕
--prefer-text 将alpha字符和空格作为文本事件而非按键事件注入
--print-fps 启动FPS计数器,打印帧日志至控制台
--push-target 通过拖放文件到设备设置目标目录
--raw-key-events 对所有输入键注入按键事件,并忽略文本事件
--record-format 强制录像格式
--record-orientation 设置录像方向
--record 录制屏幕到文件
--render-driver 请求SDL使用给定的渲染驱动
--require-audio 如果启用音频但无法工作,则使 scrcpy 失败
--select-tcpip 使用TCP/IP设备
--select-usb 使用USB设备
--serial 设备序列号(仅多设备时必需)
--shortcut-mod [键1,键2+键3,...]指定用于 scrcpy 快捷键的修饰符
--show-touches 显示物理触摸
--stay-awake 当设备插电且 scrcpy 运行时保持设备开启
--tcpip (可选[ip:port])配置并连接设备通过TCP/IP
--time-limit 设置最大镜像时间(以秒为单位)
--tunnel-host 设置adb隧道的IP地址以到达scrcpy服务器
--tunnel-port 设置adb隧道的TCP端口以到达scrcpy服务器
--turn-screen-off 立即关闭设备屏幕
--v4l2-buffer 在推帧前添加缓冲延迟(以毫秒为单位)
--v4l2-sink [/dev/videoN] 输出到v4l2loopback设备
--verbosity 设置日志级别
--version 打印 scrcpy 版本信息
--video-bit-rate 以指定比特率对视频进行编码
--video-codec-options 为设备视频编码器设置一系列逗号分隔的键:类型=值选项
--video-codec 选择视频编码器
--video-encoder 使用特定的 MediaCodec 视频编码器
--video-source 选择视频源
--window-borderless 禁用窗口装饰(显示无边框窗口)
--window-height 设置初始窗口高度
--window-title 设置自定义窗口标题
--window-width 设置初始窗口宽度
--window-x 设置初始窗口水平位置
--window-y 设置初始窗口垂直位置
seeu100 commented 1 month ago

运行

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

scrcpy

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

scrcpy --help

功能介绍

采集设置

降低分辨率

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

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

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

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

修改码率

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

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     # 初始(目前)方向
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 停止录制

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

v4l2loopback

在 Linux 上,可以将视频流发送至 v4l2 回环 (loopback) 设备,因此可以使用任何 v4l2 工具像摄像头一样打开安卓设备。

需安装 v4l2loopback 模块:

sudo apt install v4l2loopback-dkms

创建一个 v4l2 设备:

sudo modprobe v4l2loopback

这样会在 /dev/videoN 创建一个新的视频设备,其中 N 是整数。 (更多选项 可以用来创建多个设备或者特定 ID 的设备)。

列出已启用的设备:

# 需要 v4l-utils 包
v4l2-ctl --list-devices

# 简单但或许足够
ls /dev/video*

使用一个 v4l2 漏开启 scrcpy:

scrcpy --v4l2-sink=/dev/videoN
scrcpy --v4l2-sink=/dev/videoN --no-display  # 禁用窗口镜像
scrcpy --v4l2-sink=/dev/videoN -N            # 简写

(将 N 替换为设备 ID,使用 ls /dev/video* 命令查看)

启用之后,可以使用 v4l2 工具打开视频流:

ffplay -i /dev/videoN
vlc v4l2:///dev/videoN   # VLC 可能存在一些缓冲延迟

例如,可以在 OBS 中采集视频。

缓冲

可以加入缓冲,会增加延迟,但可以减少抖动 (见 #2464)。

对于显示缓冲:

scrcpy --display-buffer=50  # 为显示增加 50 毫秒的缓冲

对于 V4L2 漏:

scrcpy --v4l2-buffer=500    # 为 v4l2 漏增加 500 毫秒的缓冲

连接

TCP/IP (无线)

Scrcpy 使用 adb 与设备通信,并且 adb 支持通过 TCP/IP 连接到设备(设备必须连接与电脑相同的网络)。

自动配置

参数 --tcpip 允许自动配置连接。这里有两种方式。

对于传入的 adb 连接,如果设备(在这个例子中以192.168.1.1为可用地址)已经监听了一个端口(通常是5555),运行:

scrcpy --tcpip=192.168.1.206       # 默认端口是5555
scrcpy --tcpip=192.168.1.1:5555

如果adb TCP/IP(无线) 模式在某些设备上不被启用(或者你不知道IP地址),用USB连接设备,然后运行:

scrcpy --tcpip    # 无需其他参数

这将会自动寻找设备IP地址,启用TCP/IP模式,然后在启动之前连接到设备。

手动配置

或者,可以通过 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 '{}'

隧道

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

远程ADB服务器

要连接到一个远程ADB服务器,让服务器在所有接口上监听:

adb kill-server
adb -a nodaemon server start
# 保持该窗口开启

警告:所有客户端与ADB服务器的交流都是未加密的。

假设此服务器可在 192.168.1.2 访问。 然后,从另一个终端,运行 scrcpy:

export ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
scrcpy --tunnel-host=192.168.1.2

默认情况下,scrcpy使用用于 adb forward 隧道建立的本地端口(通常是 27183,见 --port )。它也可以强制使用一个不同的隧道端口(当涉及更多的重定向时,这在更复杂的情况下可能很有用):

scrcpy --tunnel-port=1234
SSH 隧道

为了安全地与远程ADB服务器通信,最好使用SSH隧道。

首先,确保ADB服务器正在远程计算机上运行:

adb start-server

然后,建立一个SSH隧道:

# 本地  5038 --> 远程  5037
# 本地 27183 <-- 远程 27183
ssh -CN -L5038:localhost:5037 -R27183:localhost:27183 your_remote_computer
# 保持该窗口开启

在另一个终端上,运行scrcpy:

export ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy

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

# 本地  5038 --> 远程  5037
# 本地 27183 <-- 远程 27183
ssh -CN -L5038:localhost:5037 -L27183:localhost:27183 your_remote_computer
# 保持该窗口开启

在另一个终端上,运行scrcpy:

export ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy --force-adb-forward

类似地,对于无线连接,可能需要降低画面质量:

scrcpy -b2M -m800 --max-fps 15

窗口设置

标题

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

scrcpy --window-title "我的设备"

位置和大小

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

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

可选的值有:

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

需要注意的是, scrcpy 中有三类旋转方向:

其他镜像设置

只读

禁用电脑对设备的控制 (任何可与设备交互的方式:如键盘输入、鼠标事件和文件拖放):

scrcpy --no-control
scrcpy -n

显示屏

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

scrcpy --display 1

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

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

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

保持常亮

阻止设备在连接时一段时间后休眠:

scrcpy --stay-awake
scrcpy -w

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

关闭设备屏幕

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

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 --power-off-on-close

显示触摸

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

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

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

scrcpy --show-touches
scrcpy -t

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

关闭屏保

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

关闭屏幕保护:

scrcpy --disable-screensaver

输入控制

旋转设备屏幕

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

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

复制粘贴

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

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

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

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

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

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

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

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

要禁用自动剪贴板同步功能,使用--no-clipboard-autosync

双指缩放

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

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

实际上,scrcpy 会在关于屏幕中心对称的位置上用“虚拟手指”发出触摸事件。

物理键盘模拟 (HID)

默认情况下,scrcpy 使用安卓按键或文本注入,这在任何情况都可以使用,但仅限于ASCII字符。

在 Linux 上,scrcpy 可以模拟为 Android 上的物理 USB 键盘,以提供更好地输入体验 (使用 USB HID over AOAv2):禁用虚拟键盘,并适用于任何字符和输入法。

不过,这种方法仅支持 USB 连接以及 Linux平台。

启用 HID 模式:

scrcpy --hid-keyboard
scrcpy -K  # 简写

如果失败了 (如设备未通过 USB 连接),则自动回退至默认模式 (终端中会输出日志)。这即允许通过 USB 和 TCP/IP 连接时使用相同的命令行参数。

在这种模式下,原始按键事件 (扫描码) 被发送给设备,而与宿主机按键映射无关。因此,若键盘布局不匹配,需要在 Android 设备上进行配置,具体为 设置 → 系统 → 语言和输入法 → 实体键盘

物理鼠标模拟 (HID)

与物理键盘模拟类似,可以模拟一个物理鼠标。 同样,它仅在设备通过 USB 连接时才有效,并且目前仅在 Linux 上受支持。

默认情况下,scrcpy 使用 Android 鼠标事件注入,使用绝对坐标。 通过模拟物理鼠标,在Android设备上出现鼠标指针,并注入鼠标相对运动、点击和滚动。

启用此模式:

scrcpy --hid-mouse
scrcpy -M  # 简写

您还可以将 --forward-all-clicks 添加到 转发所有点击.

启用此模式后,计算机鼠标将被“捕获”(鼠标指针从计算机上消失并出现在 Android 设备上)。

特殊的捕获键,AltSuper,切换(禁用或启用)鼠标捕获。 使用其中之一将鼠标的控制权交还给计算机。

OTG

可以仅使用物理键盘和鼠标模拟 (HID) 运行 scrcpy,就好像计算机键盘和鼠标通过 OTG 线直接插入设备一样。

在这个模式下,adb (USB 调试)是不必要的,且镜像被禁用。

启用 OTG 模式:

scrcpy --otg
# 如果有多个 USB 设备可用,则通过序列号选择
scrcpy --otg -s 0123456789abcdef

只开启 HID 键盘 或 HID 鼠标 是可行的:

scrcpy --otg --hid-keyboard              # 只开启 HID 键盘
scrcpy --otg --hid-mouse                 # 只开启 HID 鼠标
scrcpy --otg --hid-keyboard --hid-mouse  # 开启 HID 键盘 和 HID 鼠标
# 为了方便,默认两者都开启
scrcpy --otg                             # 开启 HID 键盘 和 HID 鼠标

--hid-keyboard--hid-mouse 一样,它只在设备通过 USB 连接时才有效,且目前仅在 Linux 上支持。

文本注入偏好

输入文字的时候,系统会产生两种事件

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

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

scrcpy --prefer-text

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

相反,您可以强制始终注入原始按键事件:

scrcpy --raw-key-events

该选项不影响 HID 键盘 (该模式下,所有按键都发送为扫描码)。

按键重复

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

避免转发重复按键事件:

scrcpy --no-key-repeat

该选项不影响 HID 键盘 (该模式下,按键重复由 Android 直接管理)。

右键和中键

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

scrcpy --forward-all-clicks

文件拖放

安装APK

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

不会有视觉反馈,终端会输出一条日志。

将文件推送至设备

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

不会有视觉反馈,终端会输出一条日志。

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

scrcpy --push-target=/sdcard/Movies/

音频转发

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 | 第4键³
点按 菜单 (解锁屏幕)⁴ MOD+m
点按 音量+ MOD+ (上箭头)
点按 音量- MOD+ (下箭头)
点按 电源 MOD+p
打开屏幕 鼠标右键²
关闭设备屏幕 (但继续在电脑上显示) MOD+o
打开设备屏幕 MOD+Shift+o
旋转设备屏幕 MOD+r
展开通知面板 MOD+n | 第5键³
展开设置面板 MOD+n+n | 双击第5键³
收起通知面板 MOD+Shift+n
复制到剪贴板⁵ MOD+c
剪切到剪贴板⁵ MOD+x
同步剪贴板并粘贴⁵ MOD+v
注入电脑剪贴板文本 MOD+Shift+v
打开/关闭FPS显示 (至标准输出) MOD+i
捏拉缩放 Ctrl+按住并移动鼠标
拖放 APK 文件 从电脑安装 APK 文件
拖放非 APK 文件 将文件推送至设备

¹双击黑边可以去除黑边。
²点击鼠标右键将在屏幕熄灭时点亮屏幕,其余情况则视为按下返回键 。
³鼠标的第4键和第5键。
⁴对于开发中的 react-native 应用程序,MENU 触发开发菜单。
⁵需要安卓版本 Android >= 7。

有重复按键的快捷键通过松开再按下一个按键来进行,如“展开设置面板”:

  1. 按下 MOD 不放。
  2. 双击 n
  3. 松开 MOD

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

自定义路径

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

ADB=/path/to/adb scrcpy

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

要覆盖图标,可以设置其路径至 SCRCPY_ICON_PATH

为什么叫 scrcpy

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

strcpy 源于 string (字符串); scrcpy 源于 screen (屏幕)。

如何构建?

请查看 [BUILD]。

常见问题

请查看 FAQ

开发者

请查看开发者页面

许可协议

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

相关文章