Exploring scrcpy - Android Screen Mirroring on Linux!

Background

While taking photos from the blog, I realized that I needed a better solution to monitoring and controlling my phone. I recall that during the pandemic, there were new methods to connect a phone camera to a computer.

Finding a Solution

A quick search of “view phone screen linux” found the following article

The suggested software was

I decided to give it a shot as if I could get it working, it would save me a lot of time from resetting the framing.

Setting up scrcpy

the instructions for fedora were very straight forward.

instructions

  1. Add the copr repo sudo dnf copr enable zeno/scrcpy
  2. run sudo dnf install scrcpy
  3. scrcpy should be installed

issues I ran into

However I ran into issues with the second step.

sudo dnf install scrcpy
Copr repo for scrcpy owned by zeno               10 kB/s | 2.4 kB     00:00    
Error: 
 Problem: conflicting requests
  - nothing provides libavcodec.so.58()(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavcodec.so.58(LIBAVCODEC_58)(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavdevice.so.58()(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavdevice.so.58(LIBAVDEVICE_58)(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavformat.so.58()(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavformat.so.58(LIBAVFORMAT_58)(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavutil.so.56()(64bit) needed by scrcpy-1.18-2.fc33.x86_64
  - nothing provides libavutil.so.56(LIBAVUTIL_56)(64bit) needed by scrcpy-1.18-2.fc33.x86_64
(try to add '--skip-broken' to skip uninstallable packages)
$ sudo dnf install scrcpy --skip-broken

I had a feeling I was missing some video codec dependencies. The first error nothing provides libavcodec.so.58()(64bit) caught my attention
a quick search of nothing provides libavcodec.so.58()(64bit)
yielded the fedora subreddit question that was related to installing ffmpeg.

I decided to install ffmpeg, since on my desktop, it is used for other applications
The following guide was helpful, since it had been a while since I last installed ffmpeg.

After installing the libavcodecs, I was able to install scrcpy.

Running scrcpy

Once scrcpy is installed, you can run scrcpy in the terminal. Make sure your android device has remote usb debugging.
Here’s a good guide for how to enable it

You might need developer mode enabled, so here’s a good guide if you aren’t familiar with developer mode

When you connect your android phone, the following message should appear.


Once you allow it, scrcpy will show up.

By default, scrcpy will launch with a screen in the vertical position to rotate it, refer to the following instructions

I used the 90° rotations

scrcpy --lock-video-orientation=1   # 90° counterclockwise
scrcpy --lock-video-orientation=3   # 90° clockwise

The other nice thing about scrcpy is that your keyboard and mouse inputs are transferred to android. I found this useful in engaging the shutter without changing the position of my phone.

6 Likes

I posted a issue to the project’s github. Hopefully they will respond!

That dependency report is not really a bug though… from your log it’s visible that the package wants to install the dependency, but nothing provides it.
As ffmpeg cannot be shipped in the default Fedora repos, you’ll have to enable rpmfusion repos and then installing scrcpy will also pull the av* packages with it.
The COPR repo does mention that rpmfusion repos are required.

--skip-broken seems like a not-good idea of handling dependencies and filing an upstream bugreport for it seems a bit off…

edit:

DNF Output
[tarulia@localhost]~% dnf provides libavcodec.so.58 libavdevice.so.58 libavformat.so.58 libavutil.so.56
Last metadata expiration check: 0:19:28 ago on Sat 24 Jul 2021 06:22:32 CEST.
ffmpeg-libs-4.3.1-11.fc33.i686 : Libraries for ffmpeg
Repo        : rpmfusion-free
Matched from:
Provide    : libavformat.so.58
Provide    : libavutil.so.56
Provide    : libavcodec.so.58

ffmpeg-libs-4.3.1-11.fc33.i686 : Libraries for ffmpeg
Repo        : rpmfusion-free
Matched from:
Provide    : libavformat.so.58
Provide    : libavutil.so.56
Provide    : libavcodec.so.58

ffmpeg-libs-4.3.1-11.fc33.i686 : Libraries for ffmpeg
Repo        : rpmfusion-free
Matched from:
Provide    : libavformat.so.58
Provide    : libavutil.so.56
Provide    : libavcodec.so.58

ffmpeg-libs-4.3.2-2.fc33.i686 : Libraries for ffmpeg
Repo        : rpmfusion-free-updates
Matched from:
Provide    : libavformat.so.58
Provide    : libavutil.so.56
Provide    : libavcodec.so.58

ffmpeg-libs-4.3.2-2.fc33.i686 : Libraries for ffmpeg
Repo        : rpmfusion-free-updates
Matched from:
Provide    : libavformat.so.58
Provide    : libavutil.so.56
Provide    : libavcodec.so.58

ffmpeg-libs-4.3.2-2.fc33.i686 : Libraries for ffmpeg
Repo        : rpmfusion-free-updates
Matched from:
Provide    : libavformat.so.58
Provide    : libavutil.so.56
Provide    : libavcodec.so.58

libavdevice-4.3.1-11.fc33.i686 : Special devices muxing/demuxing library
Repo        : rpmfusion-free
Matched from:
Provide    : libavdevice.so.58

libavdevice-4.3.2-2.fc33.i686 : Special devices muxing/demuxing library
Repo        : rpmfusion-free-updates
Matched from:
Provide    : libavdevice.so.58

i.e. all dependencies are in the package and found when rpmfusion is enabled as per the notes on the repository.


That aside, I’ve been using scrcpy for a while and it’s always worked great, with 2 different phones. It’s nice because it’s an android native way of doing it via debug.
One thing to note: scrcpy does not currently forward audio (see issue #14), so if you need that you will need additional tools, scrcpy recommends sndcpy for this.

2 Likes

I would be inclined to go for a VNC server on Android instead of all that setup, such as droidVNC-NG or similar.

1 Like

“All that setup” is literally installing one package and hitting OK on the device, how much simpler can it get?
Also I imagine android might not allow capturing certain applications and so they wouldn’t show up on VNC, which is a limitation that does not apply to ADB.

2 Likes

To each their own. Different people have varying comfort levels with installing packages and setup.

What’s the setup process for those? Since I haven’t used those before.

Oh interesting, I guess it wasn’t necessary. I guess they could include a section for dependencies/additional libraries if they wanted to make it more user friendly.

From what I can tell from the Play Store entry you install the app on the Android side and then connect via any VNC-supporting remote software. Which actually makes this step “more complicated” by having to install not one, but two packages (oh no), if you don’t already have a VNC software on the PC side.
Thing is when you’re connecting via VNC you’re dependant on your (WiFi) network and its configuration (WiFi on a different subnet could get annoying or when you completely split off the WiFi from the “regular” network). The Androids IP address could also change which is annoying when you want to make a shortcut (sure you can give the Android a static IP via the router, but that’s yet another step).

Point is, I feel like installing one package on the PC side and plugging in USB is a lot easier ¯\_(ツ)_/¯

2 Likes

this is great…

but
i guess if adb tcpip 5555 is left on… then that poses a security risk when connecting to lan/wan/4g?

1 Like

I don’t think that’s on by default? And when I google adb tcp/ip all I can find are tutorials how to explicitely turn it on. So I guess… don’t do that?

1 Like

OMG, how did you time that so perfectly.
I just learned about scrcpy as well - My phone screen broke, but I still needed to get some data of my old Phone.
I booted into my recovery, flashed a new kernel with a new build.prop to enable unauthenticated ADB access(lost my old ADB keys), and the used this to get the data of the devices.
The first part took way longer than it should, mostly due to me not owning a fully functional micro USB cable.
Pro tip: ADB supports network access, scrcpy supports ADB over network as well!

1 Like

i was using scrcpy and saw that it says it works over tcp/ip

2 Likes

Didn’t even know that, but that article also says it’s optional and gives instructions how to enable it, since it’s off by default.

But I guess yes, if you leave it on, it could be a security risk (should be noted though that debug will not work unless you allow it on the phone).

That being said, default usage is over USB as any ADB debug.

2 Likes

my old android machine has cracked screen… so using it thru my desktop is a perfect use for it.

2 Likes

i had a few apps I used thru avd /android studio…
but now I can just move them to the real phone and get better performance

1 Like

Kind OT, but have you thought about using Android-x86?
It even supports 3D acceleration in VMs, using virt-gpu.
Performance is quite nice, used to run this on a x86 tablet with an i5, smoothest android I’ve ever experienced.

1 Like

Might be worth taking to dms or starting a new thread if you want discussion open to the internet. Otherwise the lounge is good as a chat room.

I’ve used scrcpy / guiscrcpy + sndcpy or BT-connection for audio altogether for a while now. It’s my preferred way of mirroring Android, period, at this point.

It’s a shame I can’t use my phone-only Netflix this way, but it’s pretty much the best way I have to play my Japanese gacha-games. And it’s just much more convenient to download YT videos at night, and then use scrcpy+sndcpy to my PC, then connect a BT earphone to my PC to watch content. And it’s easier to just open up a window on PC than lifting my phone all the time while working.

The only problems I have are 1.) that cable connection can be arse sometimes, 2.) audio is always scuffed (especially when I have a call), 3.) latency is always a thing. Most of these is a problem with my quality of hardware - better router would help with wireless mirroring, my PC’s bluetooth dongle is bad, and better phone would always make it smoother. But it’s good enough for me for now.

2 Likes

I’d definitely recommend newpipe if you don’t already use it already

1 Like

I’m using NewPipe in a pinch when I’m on the go with nothing else to do and nobody around me to chat with. But my preferred software are youtube-dl + mpv. I still do manual downloads, because I got so many things in my sub box, I can’t possibly watch everything that shows up, so I have to filter stuff (and I don’t want to waste bandwidth on things I won’t watch - and I got unlimited bandwidth, no caps or speed caps, but it’s just that I like efficiency - speaking of which, seems like vnstat / traffic total got borked after a pfSense update, yet another reason not to use things you don’t understand, like pfSense and go with the simpler, easier to understand route, a la FreeBSD / OpenBSD).

1 Like