Featured

How to cast video from Android to Linux

How to cast video from Android to Linux

There are many apps and tools out there that will help you cast your Android screen to your Linux PC. However, the main problem is that it only mirrors what's on the screen and not the audio. This can be an issue if you are trying to cast video from Android, which requires you to forward both video and audio.

Also, the tools that do let you effectively cast video (including its audio) from your Android device to your Linux PC either require a rooted Android phone or suffers from latency issues. And if not that, then it's a premium tool and requires you to pay money.

But it's Linux we are talking about! Ain't there a free and open-source tool that will help us cast video and forward audio from Android to Linux?

Well, yeah, sure there is! But it can be a bit complicated to set up if you are new to Linux. It basically involves using two tools - scrcpy (screen copy) and sndcpy (sound copy). Neither of the tools requires Android root privileges, but you need to enable “developer mode” and “USB debugging” on your Android phone to get things working.

Now, if all of these seem a bit complicated, then we got you covered. Here is a complete step-by-step guide on using scrcpy and sndcpy to cast video from Android to Linux.

Casting Video from Android to Linux

But first, let's get a quick idea of the tools we will be using.

What are scrcpy and sndcpy?

The scrcpy tool - short for screen copy - is an application that will mirror your Android device to a connected Linux PC via USB or TCP/IP. Not just that, but it will also let you control your Android device from your PC using a mouse and keyboard.

Here is a quick look at some of the main features offered by scrcpy:

So as you can see, scrcpy is a powerful and feature-rich tool for casting video. However, it lacks one crucial functionality - audio forwarding. And this is where the sndcpy tool comes into the picture.

Short for sound copy, sndcpy has one function and one function only to forward audio from your Android phone to your PC. It is designed to be used while mirroring with scrcpy, but both tools can be used independently.

Prerequisites for scrcpy and sndcpy

To make scrcpy and sndcpy work, we need to configure our Android device and Linux PC by turning on some settings and installing some additional tools. Here is a quick look at the requirements and what you'll need:

Having a device with Android 10 is pretty self-explanatory. The sndcpy tool, which we will use for audio forwarding, uses the Playback Capture API to work, and it was introduced in Android 10. However, the scrcpy tool used for screencasting is compatible with Android 5 and higher.

If you are not interested in audio forwarding, you can get away with a bit outdated (>Android 5) Android smartphone.

Moving on, you need to enable “Developer Options” & “USB debugging” on your Android phone and also install “ABD” and “VLC” on Linux. If you don't know how that's done, here is a quick guide to help you out.

Step 1: Enable “Developer Options” and “USB Debugging”

The “USB Debugging” option is inside the “Developer Options,” a hidden settings area on Android devices.

To enable it, open “Settings” and scroll down to “About Phone.” Now open it, and again scroll down till you see the phone “Build Number.” Tap on it 7 times, and you will get a message stating, “you are now a developer!”.

Find Android Build Number

The “Developer Options” setting is now enabled on your device, and you can find it under Settings > System.

Developer Options Unlocked

Disclaimer: We are using a Nokia 6.1 Plus phone running stock Android 10. If you are using an Android device with a custom skin, then the manufacturers might have juggled around these settings. We have included some guides on how to enable “Developer Options” on all the popular devices.

With “Developer Options” enabled, all the settings you have inside it are pretty much the same on all devices. Just scroll down, and you should see an option called “USB debugging.” Just turn it on, and you are good to go.

Turn On USB Debugging

Note: In some devices, you might see an additional option called “USB debugging (security settings).” If that's available, you need to turn that on as well for scrcpy to function properly.

And that's it. You have successfully configured your Android phone. Now it's time to set up your Linux PC.

Step 2: Install ADB Tools and VLC on your Linux PC

You most likely have VLC already installed on your Linux PC. If not, then you can easily install it using your distro's package manager.

Now, to install ADB tools, type in the following commands based on the distro you are using:

For Ubuntu and Debian-based distros:

sudo apt-get install android-tools-adb

For Arch-based distros:

sudo pacman -S android-tools

For Fedora and RHEL-based distros:

sudo yum install android-tools

We also have a detailed read on how to install and set up ADB tools on Linux that you might want to check out.

By now, both your Android phone and Linux PC are ready. So it's finally time that we install and configure scrcpy and sndcpy.

How to install and set up “scrcpy” and “sndcpy” to Cast Video from Android to Linux

Step 1: Install scrcpy and sndcpy

First things first, we need to install scrcpy on our Linux PC. To do this, depending on which distro you are running, enter the following command in your terminal:

Debian and Ubuntu-based distros:

sudo apt install scrcpy

Fedora and RHEL based distros:

sudo dnf install scrcpy

Arch and Arch-based distros:

sudo pacman -S scrcpy

The tool is also available as a snap package. If you have snap enabled on your system, type in the following command to install the tool:

sudo snap install scrcpy

With scrcpy installed, we have to install sndcpy next. However, it is not yet available in any of the repos.

So to download it, we need to head over to the official sndcpy GitHub page. Once there, you have two options - you can either download the latest sndcpy release as a zip file or build the app.

For the sake of this tutorial, we will be downloading the .zip file as it's far simpler.

Download sndcpy

Once downloaded, extract the content of that .zip file into a folder. We have created a dedicated folder for the app and named it “sndcpy.” We will be coming back to this later.

Step 2: Connect your Android Device to your Linux PC

With “USB debugging” enabled on your Android device, connect it to your Linux PC using a USB cable. This is going to bring up a pop-up window on your Android device, asking whether you want to “Allow USB debugging?”

Authorize USB Debugging

Hit the “Allow” button, and that's it!

Note: Yes, scrcpy does allow you to connect your Android device to your Linux PC via WiFi and then cast your screen on your PC monitor. A guide on how to do that is provided in a later step. The first time you connect your Android device to your Linux PC, it is best to do so via a wired USB connection.

Step 3: Start scrcpy & sndcpy

To start scrcpy, type in the following command in your terminal:

scrcpy

And that's it!

Start scrcpy

You have successfully mirrored your Android screen to your Linux PC. You should now also control your Android device using the mouse and keyboard on your Linux PC.

Note: Make sure that the screen is unlocked on your Android device. Otherwise, screencasting will not work.

Now it's time to start sndcpy.

We need to open the folder where we stored the downloaded sndcpy file. To do this, enter the cd command followed by the path to your folder as shown below:

cd path_of_folder

Since we created the “sndcpy” folder in the home directory, we just entered the following command in our terminal:

cd /sndcpy

Once inside, type in the following command to start the sndcpy tool:

./sndcpy

This is going to bring up the following pop-up window on your Android device.

Authorize sndcpy

Authorize it, and then press enter on your terminal.

Note: You may notice this error message “main stream error: connection error: connection refused.” According to the developer, it is “expected” and won't affect your usage.

And that's it! The sndcpy tool is now running.

Start sndcpy

Try playing some music on your phone, and you will find that both your phone and Linux PC are sending out the audio. To get the audio solely from your Linux PC, turn the volume down on your Android phone.

Notice that the Volume levels of your Android device and your Linux PC function independently.

Important: If you want to turn off the mirror and audio forwarding, close their respected terminal windows. You can also disconnect the USB cable from your Android phone.

Step 4: Get Full Control Over scrcpy Mirroring.

The whole configuration is working perfectly. You can now cast video from your Android device to your Linux PC. However, by default, the scrcpy mirrors the screen in portrait mode, and we don't want to watch videos in portrait mode.

So how do we fix that?

Well, by default, the window will auto-rotate from portrait to landscape mode, depending on the app you are using.

For example, you might be aware that while watching YouTube on your phone, if you open a video and then go full-screen, it will automatically go into landscape mode!

Same here! As YouTube goes into landscape mode, the scrcpy window will also rotate from portrait mode to landscape mode.

But that being said, you can manually control the rotation by using the following hotkeys:

You can also toggle on and off fullscreen mode by pressing mod + f.

If you don't know which key is the mod key - it's typically the left alt button or the left super button on most systems unless you have manually changed it.

For a complete list of all the shortcuts, you can turn on a terminal window and type in the following command:

scrcpy --help

These shortcuts and other options are also well documented inside the Github page.

(Optional) Step 5: Use scrcpy and sndcpy Wirelessly

The scrcpy and sndcpy tools can mirror your android screen and also forward audio wirelessly over WiFi. However, you need to understand that this is going to affect the overall performance.

By default, scrcpy functions at 8Mbps bitrate. But for the most part, this is too much for the standard WiFi to handle. As such, to get a smoother experience, you might need to lower the bitrate as well as the resolution by launching scrcpy using this command:

scrcpy --bit-rate 2M --max-size 800

So with that out of the way, let's set up your Android device to cast video wirelessly to your Linux PC.

Important: Make sure that the 5555 port is not blocked by a switch or by a firewall. If it's blocked by a firewall, then set up a firewall rule to allow connection through that port. Alternatively, you can also try using different ports like 3389 (rdp) or 443 (https).

In practice, this command should look something like this:

adb connect 199.64.70.96:443

Here 199.64.70.96 is the IP address of the device, and it's connecting through 443 port.

or

adb connect 199.64.70.96:5555

Here 199.64.70.96 is the IP address, and it's connecting through 5555 port.

Now, open a terminal and start scrcpy using the above-discussed command: scrcpy -bit-rate 2M -max-size 800. You can start sndcpy without any additional options or parameters.

How to disable ADB over WiFi?

If you want to disable ADB over WiFi, open a terminal window and type the following command:

adb usb

This will disable ADB over WiFi. You will now need to connect your phone via USB to execute ADB commands.

How to Remove scrcpy and sndcpy From Your System?

It would be an injustice to show our readers how to install a software/package and yet skip out on the part of how to uninstall/remove it.

Now with that being said, removing scrcpy is fairly simple.

If you installed it using your distro's package manager, use its uninstall command to remove it.

Alternatively, if you installed the scrcpy package, then use the following command to uninstall it:

sudo snap remove scrcpy

To remove sndcpy, open the path where you extracted it from the .zip file and remove/delete all the sndcpy files. As simple as that!

Wrapping Up

So this was our in-depth, comprehensive guide on how to cast video from your Android device to your Linux PC. We hope you found this useful and that it helped you enjoy your phone's content on the bigger screen with the louder speakers of your Linux PC.

Now, as you can see, scrcpy isn't merely an app for casting video. In fact, it's an extremely powerful tool that can help you work with your mobile applications using your PC peripherals. We are sure that hearing about scrcpy, and sndcpy has got your imagination running on potential use cases. So let us know how you plan to use these in the comments below.

Also, in case you ran into an issue setting up the tools, don't hesitate to write to us in the comments. You can also check out the official FAQ page for a possible solution to your problem.

Remap your mouse buttons differently for different software with X-Mouse Button Control
Maybe you need a tool that could make your mouse's control change with every application that you use. If this is the case, you can try out an applica...
Microsoft Sculpt Touch Wireless Mouse Review
I recently read about the Microsoft Sculpt Touch wireless mouse and decided to buy it. After using it for a while, I decided to share my experience wi...
AppyMouse On-screen Trackpad and Mouse Pointer for Windows Tablets
Tablet users often miss the mouse pointer, especially when they are habitual to using the laptops. The touchscreen Smartphones and tablets come with m...