This Bash script creates a virtual display on an Android device and streams it using scrcpy
. It's designed to work with Android Debug Bridge (ADB) and scrcpy
, providing a seamless way to create and interact with a secondary display on your Android device.
- Android Debug Bridge (ADB) installed and accessible from the command line
scrcpy
installed and accessible from the command line- You can find scrcpy at: https://github.com/Genymobile/scrcpy
- An Android device connected via USB with USB debugging enabled
- Creates a virtual 4K (3840x2160) display on the connected Android device
- Automatically detects the new display ID
- Streams the virtual display using
scrcpy
with optimized settings - Cleans up the virtual display on script termination
-
Ensure your Android device is connected and USB debugging is enabled.
-
Save the script below this file.
-
Add the executable permission to the script:
chmod +x virtual_display.sh
-
Run the script:
./virtual_display.sh
-
The script will create a virtual display and launch
scrcpy
to stream it. -
To stop the script and clean up, simply close the
scrcpy
window or use Ctrl+C in the terminal.
- Checks for the presence of
adb
and a connected Android device. - Creates a virtual 4K display on the Android device.
- Detects the ID of the newly created display.
- Launches
scrcpy
to stream the virtual display with the following settings:- 8 Mbps bitrate
- Window title set to 'Pixel'
- Maximum 55 FPS
- Audio disabled
- Automatically removes the virtual display when the script is terminated.
The script includes error checking for:
- Missing
adb
orscrcpy
installations - No connected Android device
- Failure to detect the new display ID
The script uses a trap to ensure the virtual display is removed when the script exits, even if terminated unexpectedly.
You can modify the following parameters in the script:
- Virtual display resolution (default: 3840x2160)
- scrcpy settings (bitrate, FPS, window title, etc.)
If you encounter issues:
- Ensure ADB and scrcpy are correctly installed and in your PATH.
- Check that your Android device is properly connected and USB debugging is enabled.
- If the virtual display isn't detected, try increasing the sleep duration after creating the display.
Feel free to fork this project and submit pull requests with improvements or additional features.
This script interacts with your Android device settings. Use at your own risk. Always ensure you have a backup of important data before modifying device settings.