Hosting Scrypted on Android
The Scrypted home video platform is typically installed on a Linux, MacOS, or Windows server, with optional viewer apps available for Android and iOS as part of the paid NVR plugin. Historically, Scrypted was available as an Android app. Although this Android app is no longer offered, in this blog we’ll take a look at what it takes to go back to Scrypted’s roots and get Scrypted server running on Android. While these steps should work for most Android devices, the test device I used is a $20 Walmart onn Android TV - just for fun. (Some caveats are listed at the very end.)
Screenshots taken for this article were done through Vysor.
Installing Termux
We will be using the Termux app and proot-distro to install a full Ubuntu 22.04 distribution to run Scrypted.
To install Termux, get the app from F-Droid. The Google Play Store version is not recommended.
Launching the app should give you a shell:
The Termux landing screen
Now, install proot-distro with the command:
pkg install proot-distro
Then install Ubuntu 22.04:
proot-distro install ubuntu-oldlts
NOTE: As of this writing, Ubuntu 22.04 is identified in proot-distro as
ubuntu-oldlts
. To show all available distributions, run proot-distro list
.
To launch a shell inside proot-distro:
proot-distro login ubuntu-oldlts
Installing and logging into Ubuntu 22.04
Extra steps for 32-bit Android
If your device runs 32-bit Android, the following extra steps may be required.
Fixing processor identification
On some Android devices, the kernel and userspace applications run in 32-bit
mode on a 64-bit processor. Processor identification within proot-distro may
show armv8l
:
Default uname
output
We want this to show armv7l
instead, to match what would be shown on
other 32-bit Arm machines like the Raspberry Pi. This is important for some
dependencies (especially Python packages) to be installed correctly. To do
this, exit proot-distro and download and install a patched version of proot:
pkg install wget openssl
wget https://github.com/bjia56/proot/releases/download/5.1.107.1-64/proot_5.1.107.1-64_arm.deb
dpkg -i proot_5.1.107.1-64_arm.deb
Now, processor identification shows armv7l
:
Patched uname
output
Configuring an alternative Python package index
Scrypted’s Python plugins will typically pull pre-built packages from pypi.org. However, armv7l packages are rarely published there, so we will need to use an alternate package index. A couple of options include:
- piwheels: This index provides automated builds of nearly every package hosted on pypi.org.
- armv7l-wheels: My own index hosting a manually-curated list of packages built with external dependencies bundled together.
Inside proot-distro, add the file /etc/pip.conf
with the following contents
for piwheels:
[global]
extra-index-url=https://www.piwheels.org/simple/
or the following for armv7l-wheels:
[global]
extra-index-url=https://bjia56.github.io/armv7l-wheels/
Installing Scrypted server
If you haven’t already, enter into proot-distro with
proot-distro login ubuntu-oldlts
. Update the system and install some initial
dependencies:
apt update && apt -y upgrade
apt -y install curl sudo nscd
mkdir -p /var/run/nscd
Docker is not supported within Termux, so we will need to use a modified version of the Linux local installation instructions. Download and run the install script:
unset ANDROID_DATA
unset ANDROID_ROOT
curl -s https://raw.githubusercontent.com/koush/scrypted/main/install/local/install-scrypted-dependencies-linux.sh | SERVICE_USER=$USER SERVICE_USER_ROOT=1 bash
NOTE: If curl reports the error CANNOT LINK EXECUTABLE "curl": library "libssl.so.1.1" not found
,
you may be referencing curl libraries from Termux instead of Ubuntu. Exit out
of proot-distro and log back in, then retry.
NOTE: You may get an npm error saying the module node-addon-api
cannot
be found while building the @scrypted/node-pty
package. Run
npm --prefix /root/.scrypted install node-addon-api
to install the
missing module, then rerun the Scrypted install command above.
On 32-bit Android, install a custom build of ffmpeg:
curl -L --output "/root/.scrypted/node_modules/@scrypted/ffmpeg-static/artifacts/ffmpeg-linux-arm" https://github.com/eugeneware/ffmpeg-static/releases/download/b6.0/ffmpeg-linux-arm
There is no systemd within proot-distro, so we can use a script to do the same thing that the Scrypted systemd service will do:
#!/bin/bash
unset ANDROID_DATA
unset ANDROID_ROOT
export NODE_OPTIONS=--dns-result-order=ipv4first
export SCRYPTED_INSTALL_ENVIRONMENT=local
# nscd is required for ffmpeg-static to do
# hostname resolution on Ubuntu 22.04
nscd -d &
npx -y scrypted serve
Save this file as /usr/local/bin/scrypted-serve.sh
and make it executable with chmod +x /usr/local/bin/scrypted-serve.sh
. We will use this in the next
section to start Scrypted automatically.
Test that everything installed correctly by running scrypted-serve.sh
.
Scrypted running on Android
Starting Scrypted on boot
Up to date instructions for how to set up Termux to start on boot can be found on the Termux wiki, however the general steps are reproduced here for completeness.
Install the Termux:Boot app from F-Droid. Then, go to Android settings and turn off battery or power saving optimizations for both Termux and Termux:Boot. Launch the Termux:Boot app to allow it to run on boot.
Launch Termux, and create the file ~/.termux/boot/start-scrypted
:
#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
proot-distro login ubuntu-oldlts -- scrypted-serve.sh
Mark it executable with chmod +x ~/.termux/boot/start-scrypted
.
Caveats
While an Android TV may be a good starting point to run Scrypted, due to being plugged into the wall, it’s worth noting that most Android TVs run in 32-bit mode, even if the processor supports 64 bits. Only a select few devices on the market (such as NVIDIA’s Shield TV Pro - the tower model, not the stick) run applications in 64-bit mode. Scrypted has long phased out official support for 32-bit platforms, so some functionality may fail.
Conclusion
We’ve covered the basic steps to install Scrypted server on Android. While the server runs, functionality of popular plugins have not been fully tested exhaustively - perhaps plugin-specific setup will be covered in a future blog post.