Click the blue “Linux” in the upper left corner, and select “Set as Favorite”
Do you know how to mirror an Android phone to a Linux system? This article will explain how to mirror an Android phone to Ubuntu using the Scrcpy software.
First, let’s get to know Scrcpy.
▲ Control Android Phone from Linux Desktop
-
Free and open-source
-
No root permissions required -
Can run on Linux, Windows, and Mac systems -
Clipboard sharing -
Lightweight (native, only displays the device screen) -
Performance (30~60fps) -
Quality (resolution up to 1920×1080 or higher) -
Low latency (35-70ms) -
Fast startup (can start displaying within seconds) -
Non-intrusive (no need to install any programs on the Android device)
-
The Android device system version must be Android 5.0 (API 21) or higher.
-
Make sure you have enabled adb debugging on the device. -
On some devices, you may also need to enable additional options to control with mouse and keyboard.
sudo apt-get install scrcpy
Of course, you can also download the source code and compile it yourself with the following commands:
# runtime dependencies
sudo apt install ffmpeg libsdl2-2.0-0 adb
# client build dependencies
sudo apt install gcc git pkg-config meson ninja-build \
libavcodec-dev libavformat-dev libavutil-dev \
libsdl2-dev
# server build dependencies
sudo apt install openjdk-8-jdk
scrcpy
It supports execution with command-line parameters, to view the parameter list:
scrcpy --help
We can limit both height and width to a certain size (e.g., 1024):
scrcpy --max-size 1024
scrcpy -m 1024 # short version
(2). Modify Bitrate
scrcpy --bit-rate 2M
scrcpy -b 2M # short version
(3). Limit Frame Rate
scrcpy --max-fps 15
(4). Crop Screen
This feature can be used, for example, to display only one eye of the Oculus Go.
scrcpy --crop 1224:1440:0:0 # 1224x1440 at offset (0,0)
(5). Lock Screen Orientation
scrcpy --lock-video-orientation 0 # natural orientation
scrcpy --lock-video-orientation 1 # 90° counterclockwise
scrcpy --lock-video-orientation 2 # 180°
scrcpy --lock-video-orientation 3 # 90° clockwise
This setting affects recording.
2. Screen Recording
scrcpy --record file.mp4
scrcpy -r file.mkv
scrcpy --no-display --record file.mp4
scrcpy -Nr file.mkv
# Press Ctrl+C to stop recording
3. Connection Methods
Scrcpy uses adb to connect to Android devices. Meanwhile, adb can connect to Android devices via TCP/IP:
-
Connect your Android device and computer to the same Wi-Fi. -
Get the IP address of the Android device (in settings – about phone – status). -
Enable the network adb feature on the Android device: adb tcpip 5555. -
Disconnect your device from the computer. -
Connect to your device: adb connect DEVICE_IP:5555 (replace DEVICE_IP with the device’s IP). -
Run scrcpy.
Lowering the bitrate and resolution may help performance:
scrcpy --bit-rate 2M --max-size 800
scrcpy -b2M -m800 # short version
(2). Multiple Devices
scrcpy --serial 0123456789abcdef
scrcpy -s 0123456789abcdef # short version
scrcpy --serial 192.168.0.1:5555
scrcpy -s 192.168.0.1:5555 # short version
(3). Auto-start when Device Connects
You can use AutoAdb:
autoadb scrcpy -s '{}'
(4). SSH Connection
Local adb can remotely connect to another adb server (assuming both adb versions are the same) to connect to the device:
adb kill-server # close the local adb server on port 5037
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
# Keep this window open
scrcpy
adb kill-server # kill the local adb server on 5037
ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 your_remote_computer
# Keep this window open
scrcpy --force-adb-forward
scrcpy -b2M -m800 --max-fps 15
4. Window Settings
scrcpy --window-title 'My device'
(2). Position and Size
scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
(3). No Border
scrcpy --window-borderless
(4). Keep Window on Top
scrcpy --always-on-top
(5). Fullscreen
scrcpy --fullscreen
scrcpy -f # short version
(6). Rotate
scrcpy --rotation 1
Optional values are:
-
0: No rotation -
1: Rotate 90° counterclockwise -
2: Rotate 180° -
3: Rotate 90° clockwise
Note that scrcpy controls three different orientations:
-
MOD+r requests the device to switch between portrait and landscape (if the foreground application does not support the requested orientation, it may reject the request). -
–lock-video-orientation changes the orientation of the mirrored screen (the device mirror to the computer’s screen orientation). This affects recording. -
–rotation (or MOD+← (left) and MOD+→ (right)) only rotates the screen display. This only affects display, not recording.
5. Other Mirroring Settings
scrcpy --no-control
scrcpy -n
(2). Display Screen
scrcpy --display 1
adb shell dumpsys display # search "mDisplayId=" in the output
(3). Keep Awake
Prevent the device from sleeping while connected:
scrcpy --stay-awake
scrcpy -w
(4). Turn Off Device Screen
scrcpy --turn-screen-off
scrcpy -S
To turn the screen back on, you need to press MOD+Shift+o.
On Android, the power button will always turn the screen on.
For convenience, if the event of pressing the power button is sent via scrcpy (by clicking the right mouse button or MOD+p), it will turn the screen off after a brief delay.
The physical power button can still turn the device screen on.
This feature can also be used to prevent the device from sleeping:
scrcpy --turn-screen-off --stay-awake
scrcpy -Sw
(5). Render Expired Frames
Force rendering of all frames (may increase latency):
scrcpy --render-expired-frames
(6). Show Touches
Android provides this feature in Developer Options.
Scrcpy offers an option to enable this feature at startup and restore initial settings upon exit:
scrcpy --show-touches
scrcpy -t
(7). Disable Screensaver
Disable screensaver:
scrcpy --disable-screensaver
6. Input Control
Note that the switch will only occur if the foreground application supports the requested mode.
(2). Copy and Paste
-
Ctrl+c Copy -
Ctrl+x Cut -
Ctrl+v Paste (after synchronization from computer to device clipboard)
This typically works as you expect.
But the actual behavior depends on the foreground program on the device. For example, Termux sends SIGINT when Ctrl+c is pressed, and K-9 Mail creates a new email.
-
MOD+c inject COPY (copy) -
MOD+x inject CUT (cut) -
MOD+v inject PASTE (paste) (after synchronization from computer to device clipboard)
Additionally, MOD+Shift+v can convert the computer’s clipboard content into a series of key events input to the device. This feature can be useful when applications do not accept paste (like Termux). Note that this feature may cause non-ASCII encoded content to appear incorrectly.
Warning: Pasting the contents of the computer clipboard to the device (whether via Ctrl+v or MOD+v) requires the content to be saved to the device clipboard. Thus, any application can read it. You should avoid transmitting sensitive content this way (such as passwords).
(3). Pinch to Zoom
More specifically, you need to hold Ctrl while holding and moving the mouse. After releasing the left mouse button, any cursor operations will be relative to the center of the screen.
Specifically, scrcpy uses a “virtual finger” to create touch events at the opposite position relative to the center of the screen.
(4). Text Injection Preference
When typing, the system generates two types of events:
-
Key events, representing a key being pressed/released. -
Text events, representing a text being input.
The program defaults to using key events to input letters. Only in this way can the keyboard work normally in games (especially the WASD keys).
But this may cause issues. If you encounter such a problem, you can avoid it with the following operation:
scrcpy --prefer-text
(This may cause the keyboard to not work properly in games)
(5). Key Repeat
To avoid forwarding repeated key events:
scrcpy --no-key-repeat
7. File Transfer
This operation will not show any changes on the screen but will output a log in the console.
(2). Push Files to Device
This operation has no visible response and will only output logs in the console.
You can modify the target directory at startup:
scrcpy --push-target /sdcard/foo/bar/
(3). Hotkeys
You can use the –shortcut-mod suffix to modify it. Optional keys include lctrl, rctrl, lalt, ralt, lsuper, and rsuper. For example:
# Use the right Ctrl key
scrcpy --shortcut-mod=rctrl
# Use the left Ctrl, Alt, or Super key
scrcpy --shortcut-mod=lctrl+lalt,lsuper
Generally, Super refers to Windows or Cmd.
-
Double-click the black border to close the black border
-
Right-click will light up the screen when the screen is off; otherwise, it is treated as pressing the back key. -
Requires Android version >= 7.
All Ctrl + key hotkeys are forwarded to the device for processing, so they will actually be responded to by the current application.
(4). Custom Path
ADB=/path/to/adb scrcpy
end
Linux
Follow, reply with 【1024】 to receive a wealth of Linux materials
Collection of Wonderful Articles
Article Recommendations