How to Mirror Your Android Phone on Ubuntu

Click the blue “Linux” in the upper left corner, and select “Set as Favorite”

Get the latest articles first
How to Mirror Your Android Phone on Ubuntu
1

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.

1
Introduction to Scrcpy

First, let’s get to know Scrcpy.

Scrcpy is an open-source command-line tool designed to allow computer users to control their Android devices through android adb or a USB cable, supporting operations on Android devices via mouse and keyboard, and importantly, it does not require root permissions.

How to Mirror Your Android Phone on Ubuntu

▲ Control Android Phone from Linux Desktop

2
Main Features of Scrcpy
  • 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)

3
Usage Requirements
  • 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.

4
Install Scrcpy on Ubuntu
Install via the default software repository with the following command:
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

5
Run Scrcpy on Ubuntu
Connect the computer and Android device via USB and execute:
scrcpy

It supports execution with command-line parameters, to view the parameter list:

scrcpy --help

6
Introduction to Scrcpy Functions
1. Screen Settings
(1). Reduce Resolution
Sometimes, lowering the resolution of the device screen can effectively improve performance.

We can limit both height and width to a certain size (e.g., 1024):

scrcpy --max-size 1024
scrcpy -m 1024  # short version
The shorter side will be scaled proportionally to maintain the display ratio of the device. Thus, a device with a resolution of 1920×1080 will display at a resolution of 1024×576.

(2). Modify Bitrate

The default bitrate is 8Mbps. If you want to change the bitrate of the screen (for example, to 2Mbps):
scrcpy --bit-rate 2M
scrcpy -b 2M  # short version

(3). Limit Frame Rate

The frame rate of the screen can be limited with the following command:
scrcpy --max-fps 15
This feature is only supported by Android 10 and later versions, but may also be available on earlier versions.

(4). Crop Screen

The device screen can be mirrored after cropping to display part of the 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)
If –max-size is specified at the same time, the resolution change will occur after the screen is cropped.

(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

You can record video while mirroring the screen:
scrcpy --record file.mp4
scrcpy -r file.mkv
To record without starting screen mirroring:
scrcpy --no-display --record file.mp4
scrcpy -Nr file.mkv
# Press Ctrl+C to stop recording
In the display, “skipped frames” will be recorded even though they are not displayed in real-time due to performance reasons. Each frame has a timestamp during transmission, so changes in packet delay do not affect the recorded file.

3. Connection Methods

(1). Wireless

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

If multiple devices are listed after executing adb devices, you must specify the serial number of the device:
scrcpy --serial 0123456789abcdef
scrcpy -s 0123456789abcdef  # short version
If the device is connected to the computer via TCP/IP:
scrcpy --serial 192.168.0.1:5555
scrcpy -s 192.168.0.1:5555  # short version
You can start multiple scrcpy instances simultaneously to display multiple devices’ screens.

(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
From another terminal:
scrcpy
To avoid starting remote port forwarding, you can force a forwarding connection:
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
From another terminal:
scrcpy --force-adb-forward
Similar to wireless network connections, the following settings may help improve performance:
scrcpy -b2M -m800 --max-fps 15

4. Window Settings

(1). Title
The window title defaults to the device model. You can modify it with the following command:
scrcpy --window-title 'My device'

(2). Position and Size

You can specify the initial window position and size:
scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600

(3). No Border

Disable the border:
scrcpy --window-borderless

(4). Keep Window on Top

You can keep the window on top with the following command:
scrcpy --always-on-top

(5). Fullscreen

You can start scrcpy in fullscreen mode with the following command:
scrcpy --fullscreen
scrcpy -f  # short version
Fullscreen mode can be toggled in real-time with MOD+f.

(6). Rotate

The window can be rotated with the following command:
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

(1). Read-only
Disable computer control of the device (e.g., keyboard input, mouse movement, and file transfer):
scrcpy --no-control
scrcpy -n

(2). Display Screen

If multiple displays are available, you can choose a specific display for mirroring:
scrcpy --display 1
You can find the display ID with the following command:
adb shell dumpsys display   # search "mDisplayId=" in the output
The second display may only be controllable when the device is running Android 10 or higher (it may display on the computer but cannot be operated from the computer).

(3). Keep Awake

Prevent the device from sleeping while connected:

scrcpy --stay-awake
scrcpy -w
The device settings will revert after the program is closed.

(4). Turn Off Device Screen

When starting screen mirroring, you can turn off the device’s screen with the following command:
scrcpy --turn-screen-off
scrcpy -S
Or press MOD+o when needed.

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

To reduce latency, scrcpy defaults to rendering the most recent successfully decoded frame and skipping any previous frames.

Force rendering of all frames (may increase latency):

scrcpy --render-expired-frames

(6). Show Touches

During presentations, you may sometimes need to display touch points on the device:

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
Note that this feature can only display physical touches (touching the screen with your hand).

(7). Disable Screensaver

Scrcpy does not disable screensavers by default.

Disable screensaver:

scrcpy --disable-screensaver

6. Input Control

(1). Rotate Device Screen
Use MOD+r to switch between portrait and landscape modes.

Note that the switch will only occur if the foreground application supports the requested mode.

(2). Copy and Paste

Every time the Android clipboard changes, it is automatically synchronized to the computer’s clipboard.
All Ctrl shortcuts are forwarded to the device. Among them:
  • 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.

In this case, cut, copy, and paste (available only on Android >= 7):
  • 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

Simulate “pinch to zoom”: Ctrl + hold and move the mouse.

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

When you hold down a key, the program defaults to generating multiple key events. This may cause performance issues in some games.

To avoid forwarding repeated key events:

scrcpy --no-key-repeat

7. File Transfer

(1). Install APK
If you want to install an APK, drag and drop the APK file (with the .apk extension) into the scrcpy window.

This operation will not show any changes on the screen but will output a log in the console.

(2). Push Files to Device

If you want to push files to the device’s /sdcard/, drag and drop the files (not APK files) into the scrcpy window.

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

In the following table, MOD is the modifier key for hotkeys. The default is (left) Alt or (left) Super.

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.

How to Mirror Your Android Phone on Ubuntu

  1. Double-click the black border to close the black border

  2. Right-click will light up the screen when the screen is off; otherwise, it is treated as pressing the back key.
  3. 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

To use the adb you want, you can set its path in the environment variable ADB:
ADB=/path/to/adb scrcpy
If you need to override the path for scrcpy-server, you can set it in SCRCPY_SERVER_PATH.

end

Linux

Follow, reply with 【1024】 to receive a wealth of Linux materials

Collection of Wonderful Articles

Article Recommendations

【Collection】ARM
【Collection】Fan Q&A
【Collection】All Originals
CollectionLinuxIntroduction
CollectionComputer Networks
CollectionLinux Drivers
【Dry Goods】Embedded Driver Engineer Learning Path
【Dry Goods】All Knowledge Points of Linux Embedded – Mind Map

Leave a Comment