Do you know how to project an Android phone to Linux? This article uses Scrcpy software as an example to explain how to screen an Android phone to Ubuntu.

Scrcpy introduction

First, let’s take a look at Scrcpy.

Scrcpy is an open source command line tool designed to enable computer users to control their Android devices via Android ADB or via A USB cable. It supports operation of Android devices via mouse and keyboard, and most importantly, without root permissions.

Key features of Scrcpy:

  • Free and open source
  • No root permission required
  • It runs on Linux, Windows and Mac
  • Clipboards can be shared
  • Lightweight (native, display device screen only)
  • Performance (30-60 FPS)
  • Quality (resolution up to 1920×1080 or higher)
  • Low latency (35-70 ms)
  • Fast start (display starts in seconds)
  • Non-invasive (you don’t need to install any apps on your Android device)

Application requirements:

  • Android device version must be Android 5.0 (API 21) or later.
  • Make sure you have ADB debugging turned on on the device.
  • On some devices, you’ll need to turn on additional options to control with the mouse and keyboard.

Install Scrcpy on Ubuntu

To install the software repository by default, run the following command:

sudo apt-get install scrcpy
Copy the code

Of course, you can also download the source code to compile and install, the command is as follows:

# runtime dependencies sudo apt install libsdl2-2.0-0 adb # client build dependencies sudo apt install git pkg-config meson ninja-build \ libavcodec-dev libavformat-dev libavutil-dev \ libsdl2-dev # server build dependencies sudo apt install openjdk-8-jdkCopy the code

Run Scrcpy on Ubuntu

Connect your PC to your Android device using USB and execute:

scrcpy
Copy the code

Supports execution with command line parameters. View the parameter list:

scrcpy --help
Copy the code

Scrcpy function description

The picture Settings

Reduced resolution

In some cases, reducing the resolution of a device’s screen image 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
Copy the code

The shorter side is scaled down to keep the device proportioned. Thus, a 1920×1080 device will display at a resolution of 1024×576.

Modify the screen bit rate

The default bit rate is 8Mbps. If you want to change the bitrate of the screen (say to 2Mbps) :

scrcpy --bit-rate 2M
scrcpy -b 2M  # short version
Copy the code
Limit the frame rate

The frame rate of the screen can be limited by using the following command:

scrcpy --max-fps 15
Copy the code

This feature is only officially supported in Android 10 and later versions, but may be available in earlier versions as well.

The picture cut

The device picture can be mirrored after cutting to display part of the screen.

This feature could be used, for example, to show only one Oculus Go eye.

Scrcpy --crop 1224:1440:0:0 # 1224x1440 at offset (0,0)Copy the code

If –max-size is specified at the same time, the resolution will be changed after the image is cropped.

Lock screen orientation

Screen orientation can be locked using the following command:

Scrcpy --lock-video-orientation 0 # Natural orientation --lock-video-orientation 1 # 90° Orientation: orientation 3 # 90° clockwiseCopy the code

This setting affects recording.

Screen recording

Video can be recorded while the screen is mirrored:

scrcpy --record file.mp4
scrcpy -r file.mkv
Copy the code

Recording without screen mirroring enabled:

Scrcpy --no-display -- Record file.mp4 SCRcpy-nr file.mkv # Press Ctrl+C to stop recordingCopy the code

“Skipped frames” are recorded in the display, although they are not displayed in real time for performance reasons. Each frame in transit is time-stamped, so packet delay changes do not affect the recorded file.

The connection method

wireless

Scrcpy uses ADB to connect to Android devices. Also, ADB can connect to Android devices via TCP/IP:

  1. Connect your Android device and computer to the same Wi-Fi.
  2. Get the IP address of the Android device (in Settings – About phone – status information).
  3. Turn on the network ADB feature on your Android deviceadb tcpip 5555.
  4. Disconnect your device from your computer.
  5. Connect to your device:adb connect DEVICE_IP:5555 (Replace it with the device IP addressDEVICE_IP).
  6. runscrcpy.

Reducing bitrate and resolution may help performance:

scrcpy --bit-rate 2M --max-size 800
scrcpy -b2M -m800  # short version
Copy the code
More equipment

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
Copy the code

If the device is connected to the computer through TCP/IP:

Scrcpy -- Serial 192.168.0.1:5555 SCRcpy -s 192.168.0.1:5555 # short versionCopy the code

You can launch multiple SCRCPY instances at the same time to display multiple devices at the same time.

Automatically starts when the device is connected

You can use AutoAdb:

autoadb scrcpy -s '{}'
Copy the code
SSH connection

Local ADB can connect remotely to another ADB server (assuming the same ADB version) to connect remotely to the device:

Adb kill-server # Disable adb server ssh-cn-l5037 :localhost: 5037-r27183 :localhost:27183 your_remote_computer # Keep the window openCopy the code

From another terminal:

scrcpy
Copy the code

To avoid starting remote port forwarding, you can force a forwarding connection to start (note the difference between -l and -r:

adb kill-server # kill the local adb server on 5037 ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 Your_remote_computer # Keep this window openCopy the code

From another terminal:

scrcpy --force-adb-forward
Copy the code

Similar to a wireless network connection, the following Settings may help improve performance:

scrcpy -b2M -m800 --max-fps 15
Copy the code

Window Settings

The title

The default title of the window is device model. You can modify it with the following command:

scrcpy --window-title 'My device'
Copy the code
Location and size

You can specify the initial window position and size:

scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
Copy the code
No border

Close borders:

scrcpy --window-borderless
Copy the code
Keep the window first

You can keep the window at the front with the following command:

scrcpy --always-on-top
Copy the code
Full screen

You can directly start scrCPy in full screen by running the following command:

scrcpy --fullscreen
scrcpy -f  # short version
Copy the code

Full screen status can be changed in real time by MOD+ F.

rotating

The window can be rotated by using the following command:

scrcpy --rotation 1
Copy the code

The possible values are:

  • 0: no rotation
  • 1: Counterclockwise rotation 90°
  • 2: rotate 180 °
  • 3: Rotate 90° clockwise

This can also be changed in real time using the MOD+← (left) and MOD+→ (right) shortcuts.

Note that SCRCPY controls three different orientations:

  • The MOD+ R requesting device toggles between portrait and landscape (the request may be rejected if the foreground application does not support the requested orientation).
  • --lock-video-orientationChange the orientation of the image (the orientation of the image from the device to the computer). This will affect the recording.
  • --rotation(or MOD+←/MOD+→) only rotate the window screen. This only affects display, not recording.

Other Mirror Settings

read-only

Turn off computer control of the device (such as keyboard input, mouse movement, and file transfer) :

scrcpy --no-control
scrcpy -n
Copy the code
display

If multiple screens are available, you can select a specific screen for mirroring:

scrcpy --display 1
Copy the code

You can run the following command to find the ID of the display:

Adb shell dumpsys display # Search for "mDisplayId="Copy the code

The second display may only be controlled if the device is running Android 10 or above (it may be displayed on the computer, but not operated through it).

Keep normally on

Prevent device sleep while connected:

scrcpy --stay-awake
scrcpy -w
Copy the code

After the program is closed, the device Settings are restored.

Turn off device screen

To enable screen mirroring, run the following command to close the screen:

scrcpy --turn-screen-off
scrcpy -S
Copy the code

Or press MOD+ O when needed.

To reopen the screen, press MOD+Shift+ O.

On Android, the power button always turns the screen on.

For convenience, if the event to press the power button is issued via SCRCPY (via right mouse click or MOD+ P), it will turn the screen off after a short delay.

The physical power button still opens the device screen.

This feature can also be used to prevent device sleep:

scrcpy --turn-screen-off --stay-awake
scrcpy -Sw
Copy the code
Render Goaway frame

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

Force all frames to render (may result in high latency) :

scrcpy --render-expired-frames
Copy the code
According to touch

In the presentation process, there may be times when the function of showing touch points (displayed on the device) will be used.

Android provides this functionality in the developer Settings.

Scrcpy provides an option to turn this feature on at startup and restore the initial Settings on exit:

scrcpy --show-touches
scrcpy -t
Copy the code

Note that this feature can only show physical touches (touching with your hand on the screen).

Close the screen saver

Scrcpy does not turn off screen savers by default.

Turn off the screen saver:

scrcpy --disable-screensaver
Copy the code

The input control

Rotating device screen

Use MOD+ R to switch between portrait and landscape modes.

It is important to note that the switch will only happen if the foreground application supports the required mode.

Copy paste

Every time the Android clipboard changes, it is automatically synchronized to the computer clipboard.

All Ctrl shortcuts are forwarded to the device. Among them:

  • Ctrl + c to copy
  • Ctrl + x shear
  • Ctrl+ V paste (after PC to device clipboard synchronization is complete)

This usually works as you would expect.

But the actual behavior depends on the foreground program on the device. For example, Termux sends SIGINT when Ctrl+ C is pressed, or K-9 Mail creates a new message.

Cut copy paste in this case (available only on Android >= 7) :

  • The MOD + c injectionCOPY(copy)
  • The MOD + x injectionCUT(shear)
  • The MOD + v injectionPASTE(Paste) (after clipboard synchronization from computer to device is complete)

In addition, MOD+Shift+ V converts the computer’s clipboard contents into a string of keystroke events for input to the device. This can come in handy when the application doesn’t accept stickiness, such as Termux. Note that this feature can cause errors in non-ASCII encoded content.

Warning: Pasting the contents of the computer’s clipboard to the device (either by Ctrl+ V or MOD+ V) requires saving the contents to the device’s clipboard. This way, any application can read it. You should avoid transmitting sensitive content (such as passwords) this way.

Knead pull zoom

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

More specifically, you need to hold down and move the mouse while holding down Ctrl. After the left mouse button is released, any movement of the cursor takes place relative to the center of the screen.

Specifically, SCRCPy uses a “virtual finger” to generate touch events in a position opposite to the center of the screen.

Text injection preference

When typing, the system generates two kinds of events:

  • The key eventsRepresents a button being pressed/released.
  • The text eventRepresents that a text has been entered.

By default, the program uses keystroke events to enter letters. Only then will the keyboard work properly in the game (especially the WASD key).

But it can also cause problems. If you encounter this problem, you can avoid it by doing the following:

scrcpy --prefer-text
Copy the code

(This causes the keyboard to not work properly in the game)

The key repeat

By default, multiple keystroke events are generated when you hold down a key. This can cause performance problems in some games.

Avoid forwarding duplicate key events:

scrcpy --no-key-repeat
Copy the code

The file transfer

Install the APK

If you want to install APK, drag and drop APK files (names ending in.apk) into the SCRCPY window.

This action does not change on the screen, but prints a log on the console.

Push files to devices

If you want to push a file to device /sdcard/, please drag and drop the file to (not APK file) scrCPy window.

There is no visible response for this operation and only logs are printed on the console.

You can modify the destination directory at startup:

scrcpy --push-target /sdcard/foo/bar/
Copy the code

Audio forward

Scrcpy does not support audio. Please use sndcpy.

Also read Issue #14.

hotkey

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

You can modify it with the –shortcut-mod suffix. The optional keys are LCTRL, RCTRL, LALT, Ralt, lsuper and Rsuper. The following cases:

Scrcpy --shortcut-mod= LCTRL +lalt,lsuper use Ctrl, Alt or Super on the leftCopy the code

In general,SuperWindows or Cmd.

operation shortcuts
Full screen MOD+f
Rotate screen to the left The MOD + please(left)
Rotate the screen to the right The MOD + –(right).
Resize the window to 1:1 (pixels preferred) MOD+g
Resize the window to eliminate black edges MOD+w | Double-click the creates
Click on theThe main screen MOD+h | Click the middle mouse button
Click on thereturn MOD+b | Click the right mouse button ²
Click on theSwitching applications MOD+s
Click on theThe menu(Unlock the screen) MOD+m
Click on theThe volume + The MOD + write(up)
Click on theThe volume - The MOD + left(down)
Click on theThe power supply MOD+p
Open the screen Click the right mouse button ²
Turn off the device screen (but continue to display on the computer) MOD+o
Open the device screen MOD+Shift+o
Rotating device screen MOD+r
Expand notification Panel MOD+n
Expand shortcut MOD+Shift+n
Copy to clipboard ³ MOD+c
Cut to clipboard ³ MOD+x
Synchronize clipboard and paste ³ MOD+v
Import computer clipboard text MOD+Shift+v
Turn on/off FPS display (in STdout) MOD+i
Knead pull zoom Ctrl+Click and move the mouse

(1) Double click black edge to close black edge ² Clicking the right mouse button will light up the screen when the screen is off, otherwise it will be regarded as pressing the back button. ³ requires Android version Android >= 7.

All Ctrl+ key hotkeys are forwarded to the device for processing, so the current application actually responds to them.

Custom path

To use the ADB you want to use, you can set its path in the environment variable ADB:

ADB=/path/to/adb scrcpy
Copy the code

If you need to override the path of scrcpy-server, you can set it in SCRCPY_SERVER_PATH.

Write in the last

In this article you should learn how to screen your Android phone into your Own Ubuntu/Linux Mint/Debian system. Try it out and don’t leave a comment if you have any questions.